codes

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:        "codes",
	Aliases:     nil,
	Usage:       "codes {project path}",
	Description: "scan fns project and generate fn codes",
	ArgsUsage:   "",
	Category:    "",
	Action: func(ctx *cli.Context) (err error) {
		projectDir := strings.TrimSpace(ctx.Args().First())
		if projectDir == "" {
			projectDir = "."
		}
		projectDir, err = filepath.Abs(projectDir)
		if err != nil {
			err = fmt.Errorf("fnc: codes failed for project path is invalid, %v", err)
			return
		}
		debug := ctx.Bool("debug")
		p, pErr := NewProject(projectDir, debug)
		if pErr != nil {
			err = pErr
			return
		}
		scanErr := p.Scan()
		if scanErr != nil {
			err = scanErr
			return
		}
		generateErr := p.Generate()
		if generateErr != nil {
			err = generateErr
			return
		}

		return
	},
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:     "debug",
			EnvVars:  []string{"FNC_DEBUG"},
			Usage:    "print debug infos",
			Required: false,
		},
	},
}

Functions

This section is empty.

Types

type Component added in v1.8.0

type Component struct {
	Name   string
	Loader string
	Struct string
}

type Field

type Field struct {
	Name        string
	Tag         map[string]string
	Type        *Type
	Annotations map[string]string
}

func (*Field) Deprecated

func (x *Field) Deprecated() (deprecated bool)

func (*Field) Description

func (x *Field) Description() (description string)

func (*Field) Enum

func (x *Field) Enum() (enum string)

func (*Field) Title

func (x *Field) Title() (title string)

func (*Field) Validation

func (x *Field) Validation() (required bool, validation string)

type FileSet

type FileSet struct {
	Package  string
	Files    []string
	Parent   *FileSet
	Children map[string]*FileSet
}

func NewFileSet

func NewFileSet(dir string) (v *FileSet, err error)

func (*FileSet) MapToPackageFiles

func (v *FileSet) MapToPackageFiles() (x map[string][]string)

func (FileSet) String

func (v FileSet) String() string

type Fn

type Fn struct {
	FuncName    string
	Param       *FnField
	Result      *FnField
	Annotations map[string]string
}

func (*Fn) Description

func (f *Fn) Description() (v string)

func (*Fn) GetPermissions added in v1.10.0

func (f *Fn) GetPermissions() (roles []string, v bool)

func (*Fn) HasAuthorization

func (f *Fn) HasAuthorization() (v bool)

func (*Fn) HasDeprecated

func (f *Fn) HasDeprecated() (v bool)

func (*Fn) HasParam

func (f *Fn) HasParam() (v bool)

func (*Fn) HasResult

func (f *Fn) HasResult() (v bool)

func (*Fn) HasTx

func (f *Fn) HasTx() (kind string, opts []string, has bool)

func (*Fn) HasValidate

func (f *Fn) HasValidate() (v bool)

func (*Fn) IsInternal added in v1.3.0

func (f *Fn) IsInternal() (v bool)

func (*Fn) Name

func (f *Fn) Name() (v string)

func (*Fn) NameToConstName

func (f *Fn) NameToConstName() (v string, err error)

func (*Fn) NameToProxyName

func (f *Fn) NameToProxyName() (v string, err error)

func (*Fn) Title

func (f *Fn) Title() (v string)

type FnField

type FnField struct {
	InFile bool
	Name   string
	Type   *Type
}

func (*FnField) Description

func (x *FnField) Description() (description string)

func (*FnField) String

func (x *FnField) String() (s string)

func (*FnField) Title

func (x *FnField) Title() (title string)

type Import

type Import struct {
	Name  string
	Alias string
	Path  string
}

type Imports

type Imports []*Import

func NewImports

func NewImports(file *ast.File) (imports Imports)

func (Imports) FindByAlias added in v1.8.0

func (s Imports) FindByAlias(alias string) (v *Import, has bool)

func (Imports) FindByName

func (s Imports) FindByName(name string) (v *Import, has bool)

type Module

type Module struct {
	Name      string
	Path      string
	GoVersion string
	Requires  []Require
	Program   *loader.Program
	Deps      map[string]*Module
	Structs   map[string]*Struct
}

func NewModule

func NewModule(modFile string) (mod *Module, err error)

func (*Module) CreatedPackageInfos

func (mod *Module) CreatedPackageInfos() (infos []*loader.PackageInfo)

func (*Module) FileInfo

func (mod *Module) FileInfo(f *ast.File) (v *token.File)

func (*Module) FindDeps

func (mod *Module) FindDeps(pkgPath string) (deps map[string]*Module, err error)

func (*Module) GetPackageOfFile

func (mod *Module) GetPackageOfFile(f *ast.File) (name string, ident string, has bool)

func (*Module) GetStruct

func (mod *Module) GetStruct(pkg string, name string) (v *Struct, has bool)

func (*Module) SetStruct

func (mod *Module) SetStruct(v *Struct)

func (Module) String

func (mod Module) String() (s string)

type Project

type Project struct {
	// contains filtered or unexported fields
}

func NewProject

func NewProject(projectDirPath string, debug bool) (p *Project, err error)

func (*Project) Generate

func (p *Project) Generate() (err error)

func (*Project) Path

func (p *Project) Path() (v string)

func (*Project) Scan

func (p *Project) Scan() (err error)

func (*Project) Services

func (p *Project) Services() (v []*Service)

func (*Project) String

func (p *Project) String() (s string)

type Require

type Require struct {
	Name           string
	Version        string
	Replace        string
	ReplaceVersion string
	Indirect       bool
}

func (Require) Path

func (r Require) Path() (s string)

type Service

type Service struct {
	DirPath string
	Package string
	Imports Imports

	Annotations map[string]string
	Components  map[string]*Component
	// contains filtered or unexported fields
}

func (*Service) AddComponent added in v1.8.0

func (svc *Service) AddComponent(c *Component) (err error)

func (*Service) AddFn

func (svc *Service) AddFn(fn *Fn) (err error)

func (*Service) Description

func (svc *Service) Description() (v string)

func (*Service) Fns

func (svc *Service) Fns() (v []*Fn)

func (*Service) Internal

func (svc *Service) Internal() (v bool)

func (*Service) Name

func (svc *Service) Name() (v string)

func (*Service) Title

func (svc *Service) Title() (v string)

type Struct

type Struct struct {
	Package     string
	Name        string
	Fields      []*Field
	Annotations map[string]string
}

func NewStruct

func NewStruct(pkg string, name string, mod *Module) (s *Struct, err error)

func (Struct) Description

func (s Struct) Description() (description string)

func (Struct) Key

func (s Struct) Key() (key string)

func (Struct) ObjectKey

func (s Struct) ObjectKey() (v string)

func (Struct) Title

func (s Struct) Title() (title string)

type Type

type Type struct {
	Kind   string
	Indent string // built-in type name
	Import *Import
	Struct *Struct
	X      *Type // if map, x is key
	Y      *Type // if map, y is value
}

func NewType

func NewType(e ast.Expr, pkgPath string, imports Imports, mod *Module) (typ *Type, err error)

func (*Type) Annotations

func (t *Type) Annotations() (v map[string]string)

func (*Type) CodeString

func (t *Type) CodeString() (v string)

func (*Type) GetImport

func (t *Type) GetImport() (v *Import, has bool)

func (*Type) HasStruct

func (t *Type) HasStruct() bool

func (*Type) IsArray

func (t *Type) IsArray() bool

func (*Type) IsBuiltin

func (t *Type) IsBuiltin() bool

func (*Type) IsFnsCodeError

func (t *Type) IsFnsCodeError() bool

func (*Type) IsFnsContext

func (t *Type) IsFnsContext() bool

func (*Type) IsFnsEmpty

func (t *Type) IsFnsEmpty() bool

func (*Type) IsFnsJsonArray

func (t *Type) IsFnsJsonArray() bool

func (*Type) IsFnsJsonDate

func (t *Type) IsFnsJsonDate() bool

func (*Type) IsFnsJsonObject

func (t *Type) IsFnsJsonObject() bool

func (*Type) IsFnsJsonRawMessage

func (t *Type) IsFnsJsonRawMessage() bool

func (*Type) IsFnsJsonTime

func (t *Type) IsFnsJsonTime() bool

func (*Type) IsJsonRawMessage

func (t *Type) IsJsonRawMessage() bool

func (*Type) IsMap

func (t *Type) IsMap() bool

func (*Type) IsStar

func (t *Type) IsStar() bool

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) IsTime

func (t *Type) IsTime() bool

func (*Type) ObjectKey

func (t *Type) ObjectKey() (v string)

Jump to

Keyboard shortcuts

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