apigen/src/types.go

99 lines
2.3 KiB
Go
Raw Normal View History

package main
type API struct {
2021-03-21 23:08:04 -03:00
BasePath string `yaml:"basepath,omitempty"`
Host string `yaml:"host,omitempty"`
Types map[string]*APIType `yaml:"types,omitempty"`
Methods map[string]*APIMethod `yaml:"methods,omitempty"`
Namespace string `yaml:"namespace"`
Imports map[string]string `yaml:"imports"`
UsedImportsTypes map[string]bool `yaml:"used_imports_types"`
UsedImportsFunctions map[string]bool `yaml:"used_imports_functions"`
}
2021-01-30 06:53:34 -03:00
type APIFieldTag struct {
Key string
Name string
Opts []string
}
type APIField struct {
2021-03-21 23:08:04 -03:00
Type string `yaml:"type,omitempty"`
Array bool `yaml:"array,omitempty"`
Desc string `yaml:"desc,omitempty"`
Map bool `yaml:"map,omitempty"`
Mapkey string `yaml:"mapkey,omitempty"`
Mapval string `yaml:"mapval,omitempty"`
Tags map[string]APIFieldTag `yaml:"tags,omitempty"`
}
2020-12-22 10:08:57 -03:00
func (a *APIField) String() string {
if a.Array {
return "[]" + a.Type
} else {
return a.Type
}
}
type APIType struct {
2021-03-21 23:08:04 -03:00
Name string `yaml:"name,omitempty"`
Desc string `yaml:"desc,omitempty"`
Fields map[string]*APIField `yaml:"fields,omitempty"`
Col string `yaml:"col,omitempty"`
}
type APIParamType struct {
Typename string
Ispointer bool
2020-12-12 09:21:12 -03:00
IsArray bool
}
type APIMethod struct {
Desc string `yaml:"desc"`
Verb string `yaml:"verb"`
Path string `yaml:"path"`
Perm string `yaml:perm`
ReqType *APIParamType
ResType *APIParamType
Raw bool `yaml:"raw"`
}
2020-12-12 09:21:12 -03:00
func APIParamTypeToString(t *APIParamType) string {
ret := ""
if t.IsArray {
ret = "[]"
if t.Ispointer {
ret = ret + "*"
}
ret = ret + t.Typename
return ret
}
if t.Ispointer {
2021-03-21 23:08:04 -03:00
ret = ret + "*"
2020-12-12 09:21:12 -03:00
}
ret = ret + t.Typename
return ret
}
func APIParamTypeDecToString(t *APIParamType) string {
ret := ""
if t.IsArray {
ret = "[]"
if t.Ispointer {
ret = ret + "*"
}
ret = ret + t.Typename
return ret
}
if t.Ispointer {
ret = ret + "*"
}
ret = ret + t.Typename
return ret
}
2020-12-13 09:23:36 -03:00
func APIParamTypeUseRef(t *APIParamType) string {
if t.IsArray || !t.Ispointer {
return "&"
}
return ""
}