Documentation ¶
Index ¶
- func CallerName(short bool) string
- func CallerNameSkip(skip int, short bool) string
- func VarName(args ...interface{}) []string
- func VarNameDepth(skip int, args ...interface{}) []string
- type FuncHeader
- type Name
- func (name Name) Compact(args ...interface{}) (paramNames []string, paramAndValues map[string]interface{})
- func (name Name) DepthCompact(depth int, args ...interface{}) (paramNames []string, paramAndValues map[string]interface{})
- func (n Name) VarName(args ...interface{}) []string
- func (n Name) VarNameDepth(skip int, args ...interface{}) (names []string)
- type Parameter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallerName ¶ added in v0.5.8
func CallerNameSkip ¶ added in v0.5.8
func VarNameDepth ¶ added in v0.5.7
Types ¶
type FuncHeader ¶
type FuncHeader struct { Doc string // docs above func Name string In []*Parameter Out []*Parameter }
FuncHeader contains function info
func GetFuncHeader ¶
func GetFuncHeader(originFunc interface{}) (fh FuncHeader, err error)
GetFuncHeader return function header cached in funcPC @fixme according the comment of reflect/Value.Pointer pc is not unique for simple function
Example ¶
// // Person ... // type Person struct{} // // // comment // func (this Person) Name() string { // return `noname` // } // // // Say can say something // func (this Person) Say(c string) string { // return this.Name() + ` : ` + c // } h, _ := GetFuncHeader(Person{}.Say) log.Println(h.Name) //: Say-fm log.Println(h.Doc) //: // Say can say something for _, param := range append(h.In, h.Out...) { log.Println(param.Name, param.RType) //: c string //: string }
Output:
func GetFuncHeaderNoCache ¶
func GetFuncHeaderNoCache(originFunc interface{}) (fh FuncHeader, err error)
GetFuncHeaderNoCache return function header in runtime without cache
func (*FuncHeader) Encode ¶
func (fh *FuncHeader) Encode() string
Encode is convenient for json marshal
func (*FuncHeader) Equals ¶
func (fh *FuncHeader) Equals(other *FuncHeader) bool
Equals return two header is equivalent for testing
type Name ¶ added in v0.5.7
type Name struct { // X.Y means how user call this function // if user called dynamic.VarName(a), X=dynamic Y=VarName // if user called dump.Dump(a) X=dump Y=Dump // set this variant used to avoid to scanner import alias X string Y string }
func (Name) DepthCompact ¶ added in v0.5.7
func (Name) VarName ¶ added in v0.5.7
VarName return the variable names VarName(a, b) => []string{"a", "b"}
func (Name) VarNameDepth ¶ added in v0.5.7
VarNameDepth return the variable names of args... args is a stub for call this method
how can we do this ? first, get function info by runtime.Caller second, get astFile with ast/parser last, match function parameters in ast and get the code
Click to show internal directories.
Click to hide internal directories.