decgen

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2018 License: MIT Imports: 9 Imported by: 0

README

decgen

Introduction

decgen can generate boilerplate code to handle

  • tracing requests using opentrace,
  • manage database/sql transactions,
  • create adapters to use generated grpc servers as clients,
  • protect the methods on a struct with a mutex,

decgen primarily works by generating implementations of interfaces that utilize other implementations of those interfaces.

usage

Downloading decgen is done using go get.

go get github.com/robbert229/decgen
trace

To use decgen to generate a decorator first you need to create your interface.

type Service interface {
    Do(ctx, *Request) (*Response, error)
}

decgen -i Service -s TracingService -o ./tracer.go -t trace .

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Templates = map[string]string{
		"sqltx":       sqltxTemplate,
		"trace":       traceTemplate,
		"grpcadapter": grpcadapterTemplate,
		"mutex":       mutexTemplate,
	}
)

Functions

func FuncCall

func FuncCall(g *generator.Generator) interface{}

FuncCall returns a signature of the function represented by f f can be one of: ast.Expr, ast.SelectorExpr, types.Type, types.Signature

func FuncCallGRPCAdapter

func FuncCallGRPCAdapter(g *generator.Generator) interface{}

FuncCallGRPCAdapter returns the parameters used to adapt a grpc client call to a grpc server.

func FuncGRPCAdapterServer

func FuncGRPCAdapterServer(g *generator.Generator) interface{}

FuncGRPCAdapterServer returns the name of the grpc server given the client name.

func FuncMutates

func FuncMutates(g *generator.Generator) interface{}

FuncMutates returns a boolean that denotes if a given function mutates things.

func FuncResults

func FuncResults(g *generator.Generator) interface{}

FuncResults returns the slice of results being returned from a function as well as the assignment operator used.

func FuncReturnErr

func FuncReturnErr(g *generator.Generator) interface{}

FuncReturnErr creates a list of results using their nil values excluding the last value if it is an error. This allows users to return a wrapped error, or what ever they so desire.

func FuncReturnOK

func FuncReturnOK(g *generator.Generator) interface{}

FuncReturnOK returns the slice of results from a function where if the last result is an error it is replaced with nil.

func FuncSignature

func FuncSignature(g *generator.Generator) interface{}

FuncSignature builds the interface of the method.

Types

type Generator

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

Generator is capable of generating a decorator using its template.

func NewGenerator

func NewGenerator(template string, validators ...validatorFunc) *Generator

NewGenerator returns a new generator.

func (*Generator) Generate

func (g *Generator) Generate(template, sourcePackage, interfaceName, outputFile, outputStruct string) error

Generate generates an implementation of an interface that decorates another implementation of the interface using transactions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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