Referencing other dto, collection and one
Primitive support in Golang is standard as bool and bool? emi types. bool resolves the primitive
counterpart in golang without modification, whearas the nullable data types such as
bool? will be wrapped around Nullable[bool]
similar to all other primitives and structs which are nullable.
Emi doesn't generate pointer elements in Golang, and it's support has been removed many years ago in Fireback.
name: Catalog
fields:
- name: person
type: one
target: PersonDto
- name: personOptional
type: one?
target: PersonDto
- name: people
type: collection
target: PersonDto
- name: peopleOptional
type: collection?
target: PersonDto
Possible result:
package datatypes
import "encoding/json"
func GetCatalogCliFlags(prefix string) []emigo.CliFlag {
return []emigo.CliFlag{
{
Name: prefix + "person",
Type: "one",
},
{
Name: prefix + "person-optional",
Type: "one?",
},
{
Name: prefix + "people",
Type: "collection",
},
{
Name: prefix + "people-optional",
Type: "collection?",
},
}
}
func CastCatalogFromCli(c emigo.CliCastable) Catalog {
data := Catalog{}
if c.IsSet("person-optional") {
emigo.ParseNullable(c.String("person-optional"), &data.PersonOptional)
}
if c.IsSet("people-optional") {
emigo.ParseNullable(c.String("people-optional"), &data.PeopleOptional)
}
return data
}
// The base class definition for catalog
type Catalog struct {
Person PersonDto `json:"person" yaml:"person"`
PersonOptional emigo.Nullable[PersonDto] `json:"personOptional" yaml:"personOptional"`
People []PersonDto `json:"people" yaml:"people"`
PeopleOptional emigo.Nullable[[]PersonDto] `json:"peopleOptional" yaml:"peopleOptional"`
}
func (x *Catalog) Json() string {
if x != nil {
str, _ := json.MarshalIndent(x, "", " ")
return string(str)
}
return ""
}