gengokit

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

gengokit

  1. Generates Golang code for a gokit microservice that includes:
    • Logging
    • Metrics/Instrumentation
    • gRPC transport
    • http/json transport (including all encoding/decoding)
    • no-op handler methods for each service rpc, ready for business logic to be added
  2. Generates Golang code for a cli gokit microservice client that includes:
    • gRPC transport
    • http/json transport (including all encoding/decoding)
    • handler methods that marshal command line arguments into server requests

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncMap = template.FuncMap{
	"ToLower":  strings.ToLower,
	"ToUpper":  strings.ToUpper,
	"Title":    strings.Title,
	"GoName":   pkg.GoCamelCase,
	"Contains": strings.Contains,
}

FuncMap contains a series of utility functions to be passed into templates and used within those templates.

Functions

func ApplyTemplate

func ApplyTemplate(templ string, templName string, data interface{}, funcMap template.FuncMap) (io.Reader, error)

ApplyTemplate is a helper methods that packages can call to render a template with any data and func map

Types

type Config

type Config struct {
	GoPackage   string
	ServicePath string // 服务输出目录
	PBPackage   string
	PBPath      string // .pb.go 输出目录
	Version     string
	VersionDate string

	PreviousFiles map[string]io.Reader
	// transport all|grpc|nats
	Transport string
	// generate client CLI
	GenClient bool
}

type Data

type Data struct {
	// import path for the directory containing the definition .proto files
	ImportPath string
	// import path for .pb.go files containing service structs
	PBImportPath string
	// PackageName is the name of the package containing the service definition
	PackageName string
	// GRPC/Protobuff service, with all parameters and return values accessible
	Service *svcdef.Service
	// A helper struct for generating http transport functionality.
	HTTPHelper *httptransport.Helper
	FuncMap    template.FuncMap
	// generate config
	Config Config

	Version     string
	VersionDate string
}

Data is passed to templates as the executing struct; its fields and methods are used to modify the template

func NewData

func NewData(sd *svcdef.Svcdef, conf Config) (*Data, error)

NewData GoKit 数据源

func (*Data) ApplyTemplate

func (e *Data) ApplyTemplate(templ string, templName string) (io.Reader, error)

ApplyTemplate applies the passed template with the Data

func (*Data) ApplyTemplateFromPath

func (e *Data) ApplyTemplateFromPath(templFP string) (io.Reader, error)

ApplyTemplateFromPath 使用模板路径执行模板呈现

type RenderStatus added in v0.2.6

type RenderStatus interface {
	IsFirst() bool    // 是否首次呈现
	IsModified() bool // 是否改写
}

RenderStatus 表示 Renderable 状态的接口

type Renderable

type Renderable interface {
	Render(string, *Data) (io.Reader, error)
}

Directories

Path Synopsis
Package generator generates a gokit service based on a service definition.
Package generator generates a gokit service based on a service definition.
Package httptransport provides functions and template helpers for templating the http-transport of a go-kit based service.
Package httptransport provides functions and template helpers for templating the http-transport of a go-kit based service.
Package service manages the exported methods in the service handler code adding/removing exported methods to match the service definition.
Package service manages the exported methods in the service handler code adding/removing exported methods to match the service definition.
This file is here to hold the `go generate` command above.
This file is here to hold the `go generate` command above.

Jump to

Keyboard shortcuts

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