Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( //go:embed version.txt Version string //go:embed build.txt BuildTime string )
nolint
Functions ¶
func LoadPackages ¶
func LoadPackages( ctx context.Context, pwd string, env []string, tags string, patterns []string, ) ([]*packages.Package, []error)
LoadPackages typechecks the packages that match the given patterns and includes source for all transitive dependencies. The patterns are defined by the underlying build system. For the go tool, this is described at https://golang.ir/cmd/go/#hdr-Package_lists_and_patterns
wd is the working directory and env is the set of environment variables to use when loading the packages specified by patterns. If env is nil or empty, it is interpreted as an empty set of variables. In case of duplicate environment variables, the last one in the list takes precedence.
Types ¶
type Bind ¶
type Bind struct {
// contains filtered or unexported fields
}
type BindArgs ¶
type BindArgs struct { // Name is the name of the injector function. Name string // Tuple represents the arguments. Tuple *types.Tuple // Pos is the source position of the injector function. Pos token.Pos }
BindArgs describes the arguments passed to an injector function.
type Fielder ¶
type Fielder struct { Name string Mod FieldMod Type string Imports map[string]ImportInfo }
func (*Fielder) Val ¶ added in v0.0.3
Example ¶
package main import ( "fmt" "gitee.com/xuender/bindgen/internal" ) func main() { field := internal.Fielder{ Name: "FieldName", Mod: internal.Get, Type: "int", Imports: map[string]internal.ImportInfo{}, } fmt.Println(field.Val("source", "int32")) field.Mod = internal.Exported fmt.Println(field.Val("source", "float64")) field.Type = "bool" fmt.Println(field.Val("source", "int32")) field.Type = "int" fmt.Println(field.Val("source", "string")) field.Type = "float32" fmt.Println(field.Val("source", "string")) field.Type = "string" fmt.Println(field.Val("source", "int")) field.Type = "string" fmt.Println(field.Val("source", "int64")) field.Type = "string" fmt.Println(field.Val("source", "float64")) field.Type = "string" fmt.Println(field.Val("source", "float32")) }
Output: int32(source.GetFieldName()) float64(source.FieldName) conv.IfElse[int32](source.FieldName, 1, 0) strconv.Itoa(source.FieldName) strconv.FormatFloat(float64(source.FieldName), 'f', -1, 32) conv.Must(strconv.Atoi(source.FieldName)) conv.Must(strconv.Atoi(int(source.FieldName))) conv.Must(strconv.ParseFloat(source.FieldName, 64)) float32(conv.Must(strconv.ParseFloat(source.FieldName, 32)))
type Gen ¶
type Gen struct {
// contains filtered or unexported fields
}
Gen is the file-bindgen generator state.
type GenerateOptions ¶
type GenerateOptions struct { // Header will be inserted at the start of each generated file. Header []byte PrefixOutputFile string Tags string }
GenerateOptions holds options for Generate.
type GenerateResult ¶
type GenerateResult struct { // PkgPath is the package's PkgPath. PkgPath string // OutputPath is the path where the generated output should be written. // May be empty if there were errors. OutputPath string // Content is the gofmt'd source code that was generated. May be nil if // there were errors during generation. Content []byte // Errs is a slice of errors identified during generation. Errs []error }
GenerateResult stores the result for a package from a call to Generate.
func Generate ¶
func Generate( ctx context.Context, pwd string, env []string, patterns []string, opts *GenerateOptions, ) ([]GenerateResult, []error)
Generate may return one or more errors if it failed to load the packages.
func (GenerateResult) Commit ¶
func (gen GenerateResult) Commit() error
Commit writes the generated file to disk.
type ImportInfo ¶ added in v0.0.3
type ImportInfo struct {
// contains filtered or unexported fields
}
ImportInfo holds info about an import.