Documentation
¶
Overview ¶
go/template helper functions
Index ¶
- Variables
- func BaseName(name string) string
- func CamelCase(s string) string
- func CamelCaseSlice(elem []string) string
- func Contact(args_ ...interface{}) []interface{}
- func EachLine(s string, f eachLineFunc) string
- func Empty(given interface{}) bool
- func Eq(a interface{}, b interface{}) (ok bool)
- func FileExists(filename string) bool
- func FilterEmpty(v ...interface{}) []interface{}
- func Format(_args ...interface{}) (string, error)
- func GetEnv(key string, def ...string) string
- func GetName(v interface{}) string
- func In(needle interface{}, haystack ...interface{}) (ok bool)
- func InStrings(x string, list ...string) bool
- func Join(seq string, args_ ...interface{}) string
- func JsonMarshal(v interface{}) []byte
- func JsonMarshalIndent(v interface{}) []byte
- func Kind(v interface{}, dereference_ ...bool) reflect.Kind
- func NotIn(needle interface{}, haystack ...interface{}) bool
- func ParseBool(v interface{}) (bool, error)
- func RegisterFuncMap(functions map[string]interface{})
- func ReverseStrings(s []string) []string
- func Set(_args ...interface{}) interface{}
- func ShowJSON(data interface{}, depth_ ...int) string
- func Struct2Map(obj interface{}) map[string]interface{}
- func Throws(err error)
- func ToBool(v interface{}, _def ...bool) bool
- func ToInt(v interface{}, def int) int
- func ToString(v interface{}, def ...string) string
- func TrimLineLeft(cutset string, s string) string
- func TrimLinePrefix(prefix string, s string) string
- func TrimLineRight(cutset string, s string) string
- func TrimLineSuffix(suffix string, s string) string
- func WithLinePrefix(prefix string, s string) string
- func WithLineSlash(s string) string
- func WithLineSuffix(suffix string, s string) string
- type Args
- func (args Args) Bool(index int, def bool) bool
- func (args Args) Def(index int, def interface{}) interface{}
- func (args Args) First() interface{}
- func (args Args) Flatten() Args
- func (args Args) Get(index int) (v interface{}, ok bool)
- func (args Args) Int(index int, def int) int
- func (args Args) Kind(index int, dereference bool) reflect.Kind
- func (args Args) Last() interface{}
- func (args Args) Len() int
- func (args *Args) Pop() interface{}
- func (args *Args) Push(other ...interface{}) Args
- func (args *Args) Shift() interface{}
- func (args Args) String(index int, def string) string
- type FormatPipeline
- type SetPipeline
Constants ¶
This section is empty.
Variables ¶
var Functions = map[string]interface{}{ "env": GetEnv, "filename": filepath.Base, "basename": func(filename string) string { return strings.TrimSuffix( filepath.Base(filename), filepath.Ext(filename), ) }, "eq": Eq, "in": In, "notIn": NotIn, "toString": ToString, "showJSON": ShowJSON, "contact": Contact, "empty": Empty, "filterEmpty": FilterEmpty, "format": Format, "trimLinePrefix": TrimLinePrefix, "trimLineSuffix": TrimLineSuffix, "trimLineLeft": TrimLineLeft, "trimLineRight": TrimLineRight, "withLinePrefix": WithLinePrefix, "withLineSuffix": WithLineSuffix, "withLineSlash": WithLineSlash, }
Functions ¶
func BaseName ¶
BaseName returns the last path element of the name, with the last dotted suffix removed. a/b/c.d => c
func CamelCase ¶
CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2.
func CamelCaseSlice ¶
CamelCaseSlice is like CamelCase, but the argument is a slice of strings to be joined with "_".
func FilterEmpty ¶
func FilterEmpty(v ...interface{}) []interface{}
func Format ¶
格式化为字符串 参数: (args ...interface{}, FormatPipeline )
将 FormatPipeline 放在最后是为了适配 go template 的 pipeline 用法
example: `$FormatPipeline|format $arg1 $arg2` => `$FormatPipeline.Format($arg1,$arg2)`
func JsonMarshal ¶
func JsonMarshal(v interface{}) []byte
func JsonMarshalIndent ¶
func JsonMarshalIndent(v interface{}) []byte
func RegisterFuncMap ¶
func RegisterFuncMap(functions map[string]interface{})
func Struct2Map ¶
func Struct2Map(obj interface{}) map[string]interface{}
func TrimLineLeft ¶
func TrimLinePrefix ¶
func TrimLineRight ¶
func TrimLineSuffix ¶
func WithLinePrefix ¶
func WithLineSlash ¶
func WithLineSuffix ¶
Types ¶
type Args ¶
type Args []interface{}
type FormatPipeline ¶
type SetPipeline ¶
type SetPipeline interface {
SetPipeline(field string, value interface{}) interface{}
}