gosysl

package module
v0.0.0-...-79c1323 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

Sysl plugin for Golang REST api generation

Build Status Codecov Go Report Card License

sysl-go-rest generates RESTful API in the Go programming language for given Sysl specification.

Usage

go install github.com/anz-bank/gosysl/cmd/sysl-go-rest
sysl pb example.sysl -o example.pb
sysl-go-rest example.pb pkg

Compiling the protobuf file

Protoc and Golang-Protobuf-plugin Use protoc compiler with golang Plugin to generate golang source code sysl.pb.go:

protoc --go_out=. pb/sysl.proto

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJSONProperty

func GetJSONProperty(name string, t *pb.Type, sep string) string

GetJSONProperty extracts JSON property name from attribute and defaults to type name

func GetMethodName

func GetMethodName(ep *pb.Endpoint) string

GetMethodName creates the interface method name from pattern path

func GetPackage

func GetPackage(outDir string) string

GetPackage extracts package name from output directory

func GetPrimitiveType

func GetPrimitiveType(tp *pb.Type_Primitive) (string, error)

GetPrimitiveType return Golang type string for Sysl primitive data type

func GetSimpleType

func GetSimpleType(t *pb.Type) (string, error)

GetSimpleType returns Golang type string for non-composite types (no lists and sets)

func GetType

func GetType(t *pb.Type) (string, *pb.Type, error)

GetType creates golang type for given sysl type

func GetTypeLine

func GetTypeLine(t *pb.Type) (int32, error)

GetTypeLine returns the line for a given Sysl type from its SourceContext

func NamesSortedBySourceContext

func NamesSortedBySourceContext(types map[string]*pb.Type) ([]string, error)

NamesSortedBySourceContext sorts the keys of the input types according to occurrence in Sysl definition file, derived from SourceContext

func SortLineNames

func SortLineNames(lineNames []LineName) []string

SortLineNames sorts a slice of LineName in place and returns a slice of sorted names

func SplitUppercase

func SplitUppercase(str string) []string

SplitUppercase splits into fields at all upper case letters and converts fields to lower case

func WriteInterface

func WriteInterface(w io.Writer, app *pb.Application, epNames []string) error

WriteInterface creates for methods called in REST endpoints.

func WriteMiddleware

func WriteMiddleware(w io.Writer, app *pb.Application, epNames []string)

WriteMiddleware writes interface returning required middleware functions for REST endpoints

func WriteRest

func WriteRest(w io.Writer, app *pb.Application, epNames []string) error

WriteRest creates the contextkeys, routes and handlers for actual REST handlers

func WriteStruct

func WriteStruct(w io.Writer, name string, t *pb.Type, jsonSep string) error

WriteStruct creates a Golang `struct` type definition from a Sysl Tuple type definition

func WriteStructField

func WriteStructField(w io.Writer, fName string, fType *pb.Type, sep string) error

WriteStructField creates a single line inside a struct definition

func WriteTypes

func WriteTypes(w io.Writer, app *pb.Application) error

WriteTypes creates all types definition in SourceContext order for given Sysl type definition

Types

type CodeResult

type CodeResult struct {
	Rest       []byte
	Storer     []byte
	Middleware []byte
}

CodeResult contains source files' contents as []byte

func Generate

func Generate(module *pb.Module, pkg string) (CodeResult, error)

Generate creates CodeResult for given Sysl definitions as Proto message (pb.Module)

type LineName

type LineName struct {
	// contains filtered or unexported fields
}

LineName contains name, such as type or endpoint name and corresponding line

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL