utils

package
Version: v0.0.0-...-0d31e50 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GENERATED_BY_GOD = CompileRegex(`^Code generated by god.* DO NOT EDIT\.`)

Functions

func CompileRegex

func CompileRegex(pattern string) *regexp.Regexp

func ExecuteTemplate

func ExecuteTemplate(tmpl *template.Template, data interface{}) string

func GetFunctionsFromPackageForStructs

func GetFunctionsFromPackageForStructs(structs Structs) (map[*Struct]Functions, error)

TODO

func GetShortName

func GetShortName(name string) (string, error)

func GetStringFromPosition

func GetStringFromPosition(start token.Pos, end token.Pos) (string, error)

func GetTemplate

func GetTemplate(name string, text string) *template.Template

func IsASCII

func IsASCII(c byte) bool

func IsLower

func IsLower(c byte) bool

func IsPrivate

func IsPrivate(name string) bool

func IsPublic

func IsPublic(name string) bool

public 的要求

func IsUpper

func IsUpper(c byte) bool

func SaveGoCodeToFile

func SaveGoCodeToFile(filename string, content []byte) error

func SaveToFile

func SaveToFile(filename string, content []byte) error

func ShouldIgnore

func ShouldIgnore(name string) bool

func ToGetterName

func ToGetterName(name string) (string, error)

func ToSetterName

func ToSetterName(name string) (string, error)

func ToString

func ToString(bs []byte) string

Types

type Field

type Field struct {
	Name string // 字段名
	Type string // 字段类型

	GetterName         string // Getter 的名称
	GetterAlreadyExist bool   // Getter 是否在原本的代码中就存在,含同名 field 已经存在的情况
	WillGenerateGetter bool   // 是否要生成 Getter

	SetterName         string
	SetterAlreadyExist bool
	WillGenerateSetter bool

	IsPublic     bool
	ShouldIgnore bool
	HasGetter    bool

	IgnoreReason string
}

type Fields

type Fields map[string]*Field

func GetFieldsFromStruct

func GetFieldsFromStruct(structType *ast.StructType) (fields Fields, err error)

type Function

type Function struct{}

type Functions

type Functions map[string]*Function

func GetFunctionsFromFileForStruct

func GetFunctionsFromFileForStruct(f *ast.File, s *Struct) (Functions, error)

func GetFunctionsFromPackageForStruct

func GetFunctionsFromPackageForStruct(s *Struct) (Functions, error)

type Struct

type Struct struct {
	Name      string // 结构体名称
	ShortName string // 生成的函数中用于引用结构体的名称
	LowerName string
	IsPresent bool   // 结构体在包中存在
	Fields    Fields // 结构体包含的成员

	ImportedStatements string // 这个 struct 定义可能需要依赖的导入语句
}

type Structs

type Structs map[string]*Struct

func GetStructsFromFile

func GetStructsFromFile(astFile *ast.File) (Structs, error)

func GetStructsFromPackage

func GetStructsFromPackage() (Structs, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL