genutil

package
v0.0.0-...-d046166 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package genutil provides utilities to help "go generate" implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateConstants

func GenerateConstants(input, output string, params Params) error

Types

type GroupSpec

type GroupSpec struct {
	Prefix   string // constant prefix used as group identifier, e.g, the prefix for "KEY_*" should be "KEY".
	TypeName string // constant type name, e.g. "EventCode"
	Desc     string // human-readable group description used in comment
}

GroupSpec describes how to make a group of constants.

type LineParser

type LineParser func(line string) (name, sval string, ok bool)

type Params

type Params struct {
	PackageName    string      // Go package name, e.g. "input"
	RepoName       string      // repo name, e.g "Linux kernel"
	PreludeCode    string      // Go code to include at the top of file (typically "//go:generate go run ...")
	CopyrightYear  int         // copyright year used in the license, e.g "2018"
	MainGoFilePath string      // name of the main .go file for generating the constants, e.g "gen/gen_constants.go"
	Types          []TypeSpec  // specification of types to be defined
	Groups         []GroupSpec // specification of groups of constants
	LineParser     LineParser  // parser for each line in the input file
}

Params controls the detailed behavior of GenerateConstants.

type TypeSpec

type TypeSpec struct {
	Name        string // type name, e.g "EventCode"
	BuiltInType string // Go built-in type, e.g "uint16"
	Desc        string // human-readable type description used in comment
}

TypeSpec describes a Go type to be defined in the generated code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL