Type Declaration
Overview
The API type declaration is very similar to the Golang type statement, but there are some nuances and we turn to the API type statement.
Type Declaration
In the API description, the type declaration needs to satisfy the following rule:
- Type declaration must start with
type
- No need to declare
structure
keywords - Nested Structural Declarations are not supported
- Alias not supported
Sample
type StructureExample {
// Basic data type example
BaseInt int `json:"base_int"`
BaseBool bool `json:"base_bool"`
BaseString string `json:"base_string"`
BaseByte byte `json:"base_byte"`
BaseFloat32 float32 `json:"base_float32"`
BaseFloat64 float64 `json:"base_float64"`
// slice example
BaseIntSlice []int `json:"base_int_slice"`
BaseBoolSlice []bool `json:"base_bool_slice"`
BaseStringSlice []string `json:"base_string_slice"`
BaseByteSlice []byte `json:"base_byte_slice"`
BaseFloat32Slice []float32 `json:"base_float32_slice"`
BaseFloat64Slice []float64 `json:"base_float64_slice"`
// map example
BaseMapIntString map[int]string `json:"base_map_int_string"`
BaseMapStringInt map[string]int `json:"base_map_string_int"`
BaseMapStringStruct map[string]*StructureExample `json:"base_map_string_struct"`
BaseMapStringIntArray map[string][]int `json:"base_map_string_int_array"`
// anonymous example
*Base
// pointer example
Base4 *Base `json:"base4"`
// new features ( goctl >= 1.5.1 version support )
// tag ignore example
TagOmit string
}
tip
New API features are referenced New API Resolver Us
We don't support generic, weak types, e.g. any
type
You can participate in the discussion discussion to share your views https://github.com/zeroicro/go-zero/discussions/3121 ::