Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultAnalyzer() *analysis.Analyzer
- func DefaultFuncMap() template.FuncMap
- func IsBasic(kind string) bool
- func IsComplex(kind string) bool
- func IsFloat(kind string) bool
- func IsInt(kind string) bool
- func IsUint(kind string) bool
- func LoadPackage(path string) (*packages.Package, error)
- func Print(analyzer *analysis.Analyzer, withRunningFolder bool) string
- func StartPlayground(command *Command)
- type Action
- type Code
- func (c *Code) AddToImports(imp string) string
- func (c *Code) DebugPrint() bool
- func (c *Code) Declare(name string) error
- func (c *Code) HasInStore(key string) bool
- func (c *Code) HasNotGenerated(pkg, kind string) (bool, error)
- func (c *Code) Header(flagValues string) string
- func (c *Code) Implements(fieldInfo TypeInfo) (bool, error)
- func (c *Code) Keeper() map[string]interface{}
- func (c *Code) ListStored() []string
- func (c *Code) OutputFile() string
- func (c *Code) PackageName() string
- func (c *Code) RecurseGenerate(pkg, kind string) error
- func (c *Code) ResetKeeper()
- func (c *Code) Retrieve(key string) (interface{}, error)
- func (c *Code) SelectedPeerType() string
- func (c *Code) SelectedType() string
- func (c *Code) Serve() bool
- func (c *Code) Store(key string, value interface{}) error
- func (c *Code) StructByKey(key string) (*TypeInfo, error)
- func (c *Code) TemplateFile() string
- func (c *Code) TestMode() bool
- func (c *Code) Tmpl() *template.Template
- type CodeConfig
- type Command
- type ErrorType
- type FunctionInfo
- type Imports
- type MalformedRequest
- type Methods
- type PackageInfo
- type Tag
- type Tags
- type TemporaryPackage
- type TemporaryProject
- type TypeInfo
- func (t *TypeInfo) Clone(newName string) TypeInfo
- func (t *TypeInfo) FuncData() (*FunctionInfo, error)
- func (t *TypeInfo) IsBasic() bool
- func (t *TypeInfo) IsBool() bool
- func (t *TypeInfo) IsComplex() bool
- func (t *TypeInfo) IsFloat() bool
- func (t *TypeInfo) IsInt() bool
- func (t *TypeInfo) IsRune() bool
- func (t *TypeInfo) IsString() bool
- func (t *TypeInfo) IsUint() bool
- func (t *TypeInfo) IsUnsafe() bool
- func (t *TypeInfo) PackageAndKind() string
- func (t *TypeInfo) RealKind() string
- func (t *TypeInfo) SetPrefix(prefix string) error
- func (t *TypeInfo) StructOrArrayString() string
- func (t *TypeInfo) TagsByKey(name string) []string
- type TypesSlice
- type VarInfo
- type Vars
Constants ¶
const (
ToolName = "stroo"
)
Variables ¶
var InvalidAnalysis = MalformedRequest{Type: Packalyse, Status: http.StatusBadRequest}
var InvalidFormat = MalformedRequest{Type: BadFormat, Status: http.StatusBadRequest}
var InvalidGoSource = MalformedRequest{Type: BadTempProject, Status: http.StatusBadRequest}
var InvalidPackage = MalformedRequest{Type: PackaLoad, Status: http.StatusBadRequest}
var InvalidTemplate = MalformedRequest{Type: TemplExe, Status: http.StatusBadRequest}
var InvalidTemplate2 = MalformedRequest{Type: TemplaParse, Status: http.StatusBadRequest}
var InvalidTypes = MalformedRequest{Type: NoTypes, Status: http.StatusBadRequest}
Functions ¶
func DefaultAnalyzer ¶
func DefaultFuncMap ¶
func StartPlayground ¶
func StartPlayground(command *Command)
Types ¶
type Action ¶
type Action struct {
// contains filtered or unexported fields
}
below is copy paste (with some modifications) from golang.org/x/tools/go/analysis/internal/checker, because we cannot use that internal package
func (*Action) ResultType ¶
type Code ¶
type Code struct { CodeConfig Imports []string PackageInfo *PackageInfo // contains filtered or unexported fields }
var Root *Code
func New ¶
func New( info *PackageInfo, config CodeConfig, tmpl *template.Template, ) (*Code, error)
func (*Code) AddToImports ¶
func (*Code) DebugPrint ¶
func (*Code) Declare ¶
this should be called to allow the generator to know which kind of methods we're generating
func (*Code) HasInStore ¶
func (*Code) HasNotGenerated ¶
checker for recurse generated
func (*Code) Implements ¶
check if a kind has a method called the same as the template being declared
func (*Code) ListStored ¶
func (*Code) OutputFile ¶
func (*Code) PackageName ¶
func (*Code) RecurseGenerate ¶
uses the template name to apply the template recursively it's useful for replacing the code in existing generated files
func (*Code) ResetKeeper ¶
func (c *Code) ResetKeeper()
func (*Code) SelectedPeerType ¶
func (*Code) SelectedType ¶
getters for config - to be accessible from template
func (*Code) StructByKey ¶
gets a struct declaration by it's name
func (*Code) TemplateFile ¶
type CodeConfig ¶
type Command ¶
type Command struct { CodeConfig Inspector *analysis.Analyzer WorkingDir string Result *PackageInfo Out bytes.Buffer }
func NewCommand ¶
builds a new command from the analyzer (which holds the inspector) and sets the Run function
type FunctionInfo ¶
type MalformedRequest ¶
type MalformedRequest struct { Status int `json:"status"` ErrorMessage string `json:"errorMessage"` PartialSource string `json:"partialSource"` Type ErrorType `json:"type"` }
func (MalformedRequest) Error ¶
func (m MalformedRequest) Error() string
type Methods ¶
type Methods []FunctionInfo
type PackageInfo ¶
type PackageInfo struct { Name string Path string Types TypesSlice Interfaces TypesSlice Functions Methods Vars Vars TypesInfo *types.Info Imports []*Imports PrintDebug bool }
func (*PackageInfo) LoadImports ¶
func (pkg *PackageInfo) LoadImports(fromImports []*types.Package)
type Tag ¶
type TemporaryPackage ¶
type TemporaryProject ¶
type TemporaryProject struct { Config *packages.Config Modules []TemporaryPackage TempDirName string // contains filtered or unexported fields }
func CreateTempProj ¶
func CreateTempProj(tmpPacks []TemporaryPackage) (*TemporaryProject, error)
func (*TemporaryProject) Cleanup ¶
func (e *TemporaryProject) Cleanup()
must be called by the caller, as in `defer tmpProj.Cleanup()`
func (*TemporaryProject) File ¶
func (e *TemporaryProject) File(tmpPackName, tmpPackFileName string) string
func (*TemporaryProject) Filename ¶
func (e *TemporaryProject) Filename(tmpPackName, tmpPackFileName string) string
func (*TemporaryProject) Finalize ¶
func (e *TemporaryProject) Finalize() error
type TypeInfo ¶
type TypeInfo struct { Package string // current or imported package name PackagePath string // current or imported package path Name string // for `type` in case of struct or func type declaration Name == Kind; for `field` the name of the field Kind string // for `type` usually the way we Extract; for `field` the kind of the field (for extracting `type`) Tags Tags // tags, for both Prefix string // `field` info property, for storing embedding names Fields TypesSlice // for `type` fields ; for `field` is always nil MethodList Methods // for `type` methods ; for `field` first element contains `func data` if it's marked as `IsFunc` IsArray bool // for `type` if it's array it's not a struct, it's struct; for `field` if it's an array IsPointer bool // for `type` if array, it's pointer; for `field` if it's a pointer IsImported bool // for `type` if kind it's an imported one; for `field` if it's external to current package IsAlias bool // for `type` if it's alias; for `field` it's always false IsFunc bool // for `type` if it's a function type definition; for `field` IsStruct bool // `field` info property IsMap bool // `field` info property IsChan bool // `field` info property IsExported bool // `field` info property IsEmbedded bool // `field` info property IsInterface bool // `field` info property Comment *ast.CommentGroup // comment found in AST }
func NewAliasFromField ¶
func (*TypeInfo) FuncData ¶ added in v0.0.3
func (t *TypeInfo) FuncData() (*FunctionInfo, error)
func (*TypeInfo) PackageAndKind ¶ added in v0.0.3
func (*TypeInfo) RealKind ¶ added in v0.0.3
in case we need to print `*Something` instead of `Something`
func (*TypeInfo) StructOrArrayString ¶ added in v0.0.3
type TypesSlice ¶
type TypesSlice []TypeInfo
func (TypesSlice) Extract ¶
func (s TypesSlice) Extract(typeName string) *TypeInfo
this should be called only from Code's StructByKey method
func (TypesSlice) HasFieldKind ¶ added in v0.0.3
func (s TypesSlice) HasFieldKind(kind string) bool
func (TypesSlice) Len ¶ added in v0.0.3
func (s TypesSlice) Len() int
implementation of Sorter interface, so we can sort fields
func (TypesSlice) Less ¶ added in v0.0.3
func (s TypesSlice) Less(i, j int) bool
func (TypesSlice) Swap ¶ added in v0.0.3
func (s TypesSlice) Swap(i, j int)