Documentation ¶
Index ¶
- func Encode(v ...any) (any, error)
- func EncodeToJSON(v ...any) ([]byte, error)
- func EncodeToString(v ...any) (string, error)
- func GetFunctionName(i interface{}) string
- func GetReflectElem(r reflect.Value) reflect.Value
- func GetReflectTypeElem(t reflect.Type) reflect.Type
- func HtmlEscape(s string) string
- func RetInvalidType(f *Fielder) error
- func RetMissing(f *Fielder) error
- func SetReflectValue(r reflect.Value, v reflect.Value, escape bool) bool
- type Fielder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Transforms a complex struct into a map or a []map
c3po.Encode(struct{Name:"Jão"}) => map[string]any{"Name":"jão"} c3po.Encode(struct{Name:"Jão", Age:99}) => map[string]any{"Name":"jão", "Age":99} c3po.Encode([]struct{Name:"Jão", Age:99}) => []map[string]any{"Name":"jão", "Age":99}
func EncodeToJSON ¶
EncodeToJSON is similar to Encode, but return a []byte{}
c3po.EncodeToJSON(struct{Name:"Jão", Age:99}) => []byte{"{'Name':'jão', 'Age':99}"}
func EncodeToString ¶
EncodeToString is similar to EncodeToJSON, but return a []byte{}
c3po.EncodeToString(struct{Name:"Jão", Age:99}) => "{'Name':'jão', 'Age':99}"
func GetFunctionName ¶
func GetFunctionName(i interface{}) string
func HtmlEscape ¶
func RetInvalidType ¶
func RetMissing ¶
Types ¶
type Fielder ¶
type Fielder struct { Name string RealName string Default any Schema any Escape bool // default: false Required bool // default: false Nullable bool // default: false Heritage bool // default: false Recursive bool // default: true SkipOnErr bool // default: false IsMAP, IsSlice, IsStruct, IsPointer bool SliceType, MapKeyType, MapValueType *Fielder Type reflect.Kind Tags map[string]string SuperIndex *int // if a field to a struct Children map[string]*Fielder FieldsByIndex map[int]string }
func ParseSchema ¶
usage:
c3po.ParseSchema(struct{}) => struct{} c3po.ParseSchema(&struct{}) => *struct{} c3po.ParseSchema(&struct{Field:Value}) => *struct{Field: value} // with default value type Schema struct{ Field `c3po:"-"` // omit this field Field `c3po:"realName"` // string: real name field Field `c3po:"name"` // string: name of validation (default realName) Field `c3po:"escape"` // bool: escape html value (default false) Field `c3po:"required"` // bool: ... (default false) Field `c3po:"nullable"` // bool: if true, allow nil value (default false) Field `c3po:"recursive"`// bool: deep validation (default true) Field `c3po:"skiponerr"`// bool: omit on valid. error (default false) }
func ParseSchemaWithTag ¶
Click to show internal directories.
Click to hide internal directories.