template

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const FileExtension = "tpl"

FileExtension defines the template file extension used by Godin

Variables

View Source
var PartialTemplates = map[string]string{
	"service_method":                    "partials/service_method.tpl",
	"logging_method":                    "partials/logging_method.tpl",
	"request":                           "partials/request.tpl",
	"endpoint":                          "partials/endpoint.tpl",
	"response":                          "partials/response.tpl",
	"grpc_encode_request":               "partials/grpc/request_response/encode_request.tpl",
	"grpc_encode_response":              "partials/grpc/request_response/encode_response.tpl",
	"grpc_decode_request":               "partials/grpc/request_response/decode_request.tpl",
	"grpc_decode_response":              "partials/grpc/request_response/decode_response.tpl",
	"grpc_request_decoder":              "partials/grpc/encode_decode/request_decoder.tpl",
	"grpc_request_encoder":              "partials/grpc/encode_decode/request_encoder.tpl",
	"grpc_response_decoder":             "partials/grpc/encode_decode/response_decoder.tpl",
	"grpc_response_encoder":             "partials/grpc/encode_decode/response_encoder.tpl",
	"amqp_publish_encode":               "partials/amqp/encode_decode/publish_encode.tpl",
	"amqp_subscribe_decode":             "partials/amqp/encode_decode/subscribe_decode.tpl",
	"amqp_subscribe_decoder_interfaces": "partials/amqp/encode_decode/subscribe_decoder_interfaces.tpl",
}

Functions

This section is empty.

Types

type BaseTemplate

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

BaseTemplate provides the basic templating functionality required for Godin

func (*BaseTemplate) Filename

func (b *BaseTemplate) Filename() string

Filename returns the filename of the currently loaded template

func (*BaseTemplate) FormatCode

func (b *BaseTemplate) FormatCode(source []byte) ([]byte, error)

FormatCode will use go/format to format the given raw code

func (*BaseTemplate) PartialsGlob

func (b *BaseTemplate) PartialsGlob() string

PartialsGlob returns a glob-path which matches all templates inside the partial folder

func (*BaseTemplate) TemplatePath

func (b *BaseTemplate) TemplatePath() string

TemplatePath returns the absolute template path to the current base template Since packr2: this just returns the filename, the virtual filesystem has a different chroot

type Context

type Context struct {
	Service  Service
	Godin    Godin
	Protobuf Protobuf
	Docker   Docker
	Project  Project
}

func NewContextFromConfig

func NewContextFromConfig() Context

NewContextFromConfig will initialize the context will all the data from the configuration The context is not fully populated after this call, but all configuration values are accessible.

func PopulateFromService

func PopulateFromService(ctx Context, service *parse.Service) Context

PopulateFromService will populate an existing Context with the available data from the parse service-file

type Docker

type Docker struct {
	Registry string
}

type File

type File struct {
	BaseTemplate
	// contains filtered or unexported fields
}

func NewFile

func NewFile(name string, isGoSource bool) *File

func (*File) Render

func (f *File) Render(fs packr.Box, templateContext Context) (rendered []byte, err error)

Render the specified template file

type FileAppendWriter

type FileAppendWriter struct {
	Writer
}

func NewFileAppendWriter

func NewFileAppendWriter(path string, data []byte) *FileAppendWriter

NewFileAppendWriter returns a new appending file-writer for Godin templates

func (*FileAppendWriter) Write

func (f *FileAppendWriter) Write() error

Write will open the given file and try to append the given data to it The file is NOT created if it doesn't exist.

type FileWriter

type FileWriter struct {
	Writer
}

func NewFileWriter

func NewFileWriter(path string, data []byte) *FileWriter

NewFileWriter initializes a new FileWriter

func (*FileWriter) Write

func (f *FileWriter) Write(overwrite bool) error

Write dumps the given data into a file and creates it if necessary. The overwrite flag can be set to overwrite any existing data.

type GenerateOptions

type GenerateOptions struct {
	Template   string
	IsGoSource bool
	Context    Context
	TargetFile string
	Overwrite  bool
}

func DockerfileOptions

func DockerfileOptions() GenerateOptions

func DomainErrorsOptions added in v0.5.0

func DomainErrorsOptions() GenerateOptions

func FileOptions

func FileOptions(name string, tplContext Context, targetPath string) GenerateOptions

func GitignoreOptions

func GitignoreOptions() GenerateOptions

func K8sDeploymentOptions

func K8sDeploymentOptions() GenerateOptions

func K8sServiceOptions

func K8sServiceOptions() GenerateOptions

func MainStubOptions added in v0.6.0

func MainStubOptions(ctx Context) GenerateOptions

func MakefileOptions added in v0.6.0

func MakefileOptions(ctx Context) GenerateOptions

func MiddlewareOptions

func MiddlewareOptions() GenerateOptions

func RequestResponseOptions

func RequestResponseOptions(ctx Context) GenerateOptions

func ServiceStubOptions

func ServiceStubOptions() GenerateOptions

type Generator

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

func NewGenerator

func NewGenerator(opts GenerateOptions) *Generator

func (*Generator) GenerateFile

func (g *Generator) GenerateFile(box packr.Box) error

type Godin

type Godin struct {
	Version string
	Commit  string
	Build   string
}

type Method

type Method struct {
	// required for partials which do not have access to the Service struct
	ServiceName      string
	Comments         []string
	Name             string
	Params           []Variable
	Returns          []Variable
	Request          string
	Response         string
	ProtobufRequest  string
	ProtobufResponse string
}

func MethodFromType

func MethodFromType(function *types.Function) Method

func (Method) ParamList

func (m Method) ParamList() string

func (Method) RequestName

func (m Method) RequestName() string

func (Method) ResponseName

func (m Method) ResponseName() string

func (Method) ReturnImplementationMissing

func (m Method) ReturnImplementationMissing() string

ReturnImplementationMissing will produce a list of nil returns and an error. For example, the return params are (name string, err error) the method will return "nil, fmt.Errorf("NOT IMPLEMENTED")"

func (Method) ReturnList

func (m Method) ReturnList() string

func (Method) ReturnVariableList

func (m Method) ReturnVariableList() string

ReturnVariableList returns all return variable names as comma-separated string

type Partial

type Partial struct {
	BaseTemplate
	// contains filtered or unexported fields
}

func NewPartial

func NewPartial(name string, isGoSource bool) *Partial

func (*Partial) Render

func (p *Partial) Render(fs packr.Box, templateContext interface{}) (rendered []byte, err error)

type Project added in v0.5.0

type Project struct {
	Created time.Time
	Updated time.Time
}

type Protobuf

type Protobuf struct {
	Package string
	Service string
	Path    string
}

type Publisher added in v0.5.0

type Publisher struct {
	Publishing      rabbitmq.Publishing
	Name            string
	ProtobufMessage string
}

type Service

type Service struct {
	Name              string
	Namespace         string
	Methods           []Method
	Module            string
	LoggingMiddleware bool
	Subscriber        []Subscriber
	Publisher         []Publisher
	Transport         Transport
}

type Subscriber added in v0.5.0

type Subscriber struct {
	Handler      string
	Subscription rabbitmq.Subscription
	Protobuf     struct {
		Import  string
		Message string
	}
}

type Template

type Template interface {
	Render(tplContext Context) ([]byte, error)
}

type Transport added in v0.5.0

type Transport struct {
	GRPC bool
	AMQP bool
}

type Variable

type Variable struct {
	Name string
	Type string
}

func (Variable) NilValue

func (v Variable) NilValue() string

NilValue returns the appropriate nil value for the variable

func (Variable) ResolveType

func (v Variable) ResolveType() string

ResolveType resolves the type to use inside a template. It covers different combinations which should suffice most cases.

type Writer

type Writer struct {
	Path string
	// contains filtered or unexported fields
}

There must be two writers: FULL and APPEND Each accepting a rendered template

Jump to

Keyboard shortcuts

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