proto

package
v0.0.0-...-c21b5ec Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Template = template.Must(template.New("").Funcs(map[string]interface{}{
	"UsecaseParamsToProtoMessageDef": UsecaseParamsToProtoMessageDef,
	"ToImportList": func(rootParam TemplateParam) []string {
		m := map[string]string{
			"google.protobuf.Empty": "google/protobuf/empty.proto",
		}
		extract := func(s string) []string {
			list := make([]string, 0, 10)
			for _, s := range strings.FieldsFunc(s, func(c rune) bool {
				return unicode.IsSpace(c) || c == ';'
			}) {
				list = append(list, m[s])
			}
			return list
		}
		list := make([]string, 0, 10)

		list = append(list, extract(UsecaseParamsToProtoMessageDef(rootParam))...)
		for _, usecase := range rootParam.Usecases {
			if usecase.Output == nil {
				list = append(list, m["google.protobuf.Empty"])
				break
			}
		}

		return removeDuplicateAndEmpty(list)
	},
	"plus": func(a, b int) string { return strconv.Itoa(a + b) },
}).Parse(strings.TrimSpace(`
syntax = "proto3";
package {{.Package}};

{{- if .JavaPackage}}
option java_package = "{{.JavaPackage}}";
{{- end}}
{{- if .JavaOuterClassName}}
option java_outer_classname = "{{.JavaOuterClassName}}";
{{- end}}

{{- range ToImportList . }}
import "{{.}}";
{{- end}}

{{- range .Usecases}}

service {{.Name}} {
  rpc {{.Method.Name}} ({{.Name}}Input) returns ({{if .Output}}{{.Name}}Output{{else}}google.protobuf.Empty{{end}});
}
{{- end}}

{{UsecaseParamsToProtoMessageDef .}}
`)))

Functions

func KnownTypesToProtoType

func KnownTypesToProtoType(t types.Type) (string, bool)

func UsecaseParamsToProtoMessageDef

func UsecaseParamsToProtoMessageDef(rootParam TemplateParam) string

Types

type TemplateParam

type TemplateParam struct {
	Package            string
	JavaPackage        string
	JavaOuterClassName string
	Usecases           []genapi.Usecase
}

Directories

Path Synopsis
go-client
go-server

Jump to

Keyboard shortcuts

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