// GenerateClient generates go client for the model func (s *Schema) GenerateClient() ([]byte, error) { // Generate file headers goBytes, err := generators.RunTemplate("clientHdr", s) if err != nil { return nil, err } // Generate all object definitions for _, obj := range s.Objects { objBytes, err := obj.GenerateGoStructs() if err != nil { return nil, err } goBytes = append(goBytes, objBytes...) } // Generate clients for all objects for _, obj := range s.Objects { objBytes, err := obj.GenerateClientObjs() if err != nil { return nil, err } goBytes = append(goBytes, objBytes...) } return goBytes, nil }
// GeneratePythonClientObjs generates the python client for individual objects func (obj *Object) GeneratePythonClientObjs() ([]byte, error) { goBytes, err := generators.RunTemplate("pyclientObj", obj) if err != nil { return nil, err } return goBytes, nil }
func (obj *Object) GenerateJsViews() ([]byte, error) { goBytes, err := generators.RunTemplate("jsView", obj) if err != nil { return nil, err } return goBytes, nil }
func (prop *Property) GenerateGoStructs() (string, error) { // this function has to return a string because it is used in templates. var found bool for _, myType := range validPropertyTypes { if myType == prop.Type { found = true } } if !found { return "", errors.New("Unknown Property") } byt, err := generators.RunTemplate("propstruct", prop) return string(byt), err }
// GenerateGoStructs generates go code from a schema func (s *Schema) GenerateGoStructs() ([]byte, error) { var goBytes []byte // Generate all object definitions for _, obj := range s.Objects { objBytes, err := obj.GenerateGoStructs() if err != nil { return nil, err } goBytes = append(goBytes, objBytes...) } for _, name := range []string{"gostructs", "callbacks", "init", "register"} { byts, err := generators.RunTemplate(name, s) if err != nil { return nil, err } goBytes = append(goBytes, byts...) } return goBytes, nil }
// GenerateGoHdrs generates go file headers func (s *Schema) GenerateGoHdrs() ([]byte, error) { return generators.RunTemplate("hdr", s) }
func (obj *Object) GenerateGoStructs() ([]byte, error) { return generators.RunTemplate("objstruct", obj) }
func (s *Schema) GenerateGoFuncs() ([]byte, error) { // Output the functions and routes return generators.RunTemplate("routeFunc", s) }