Beispiel #1
0
// 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
}
Beispiel #2
0
// 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
}
Beispiel #3
0
func (obj *Object) GenerateJsViews() ([]byte, error) {
	goBytes, err := generators.RunTemplate("jsView", obj)
	if err != nil {
		return nil, err
	}

	return goBytes, nil
}
Beispiel #4
0
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
}
Beispiel #5
0
// 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
}
Beispiel #6
0
// GenerateGoHdrs generates go file headers
func (s *Schema) GenerateGoHdrs() ([]byte, error) {
	return generators.RunTemplate("hdr", s)
}
Beispiel #7
0
func (obj *Object) GenerateGoStructs() ([]byte, error) {
	return generators.RunTemplate("objstruct", obj)
}
Beispiel #8
0
func (s *Schema) GenerateGoFuncs() ([]byte, error) {
	// Output the functions and routes
	return generators.RunTemplate("routeFunc", s)
}