dynamic

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: MIT Imports: 11 Imported by: 0

README

XGo/Dynamic

this package provides some dynamic features using reflect and go/ast.

Features

Function Headers

Examples: https://gowalker.org/github.com/Kretech/xgo/dynamic#_ex_btn_GetFuncHeader

Variable Names

https://gowalker.org/github.com/Kretech/xgo/p#VarName

Compact function from Php

https://gowalker.org/github.com/Kretech/xgo/p#Compact

Variable scopes in goroutine

https://gowalker.org/github.com/Kretech/xgo/p#G

Documentation

Index

Examples

Constants

View Source
const PtrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const

sys.PtrSize

Variables

This section is empty.

Functions

This section is empty.

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 in runtime

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
}

func GetFuncHeaderNoCache

func GetFuncHeaderNoCache(originFunc interface{}) (fh FuncHeader, err error)

GetFuncHeaderNoCache is optional way when the cache is incorrect

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 Parameter

type Parameter struct {
	Name  string
	RType reflect.Type
}

Parameter contains input and output info of function

Jump to

Keyboard shortcuts

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