Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
74803d86a3 | ||
|
bec037ce64 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,3 @@
|
|||||||
/protoc-gen-gotemplate
|
|
||||||
|
|
||||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
|
15
.travis.yml
15
.travis.yml
@@ -1,15 +0,0 @@
|
|||||||
language: go
|
|
||||||
go: 1.8.x
|
|
||||||
install:
|
|
||||||
- go get github.com/Masterminds/glide
|
|
||||||
- wget https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/.travis/install-protoc.sh && chmod +x install-protoc.sh && ./install-protoc.sh 3.2.0
|
|
||||||
- go get -u github.com/golang/protobuf/protoc-gen-go
|
|
||||||
script:
|
|
||||||
- make install
|
|
||||||
- make test
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/local
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- "PATH=$PATH:$HOME/local/bin"
|
|
28
Makefile
28
Makefile
@@ -1,28 +0,0 @@
|
|||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
go build -v -i -o protoc-gen-gotemplate .
|
|
||||||
|
|
||||||
.PHONY: install
|
|
||||||
install:
|
|
||||||
go install .
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
test: install
|
|
||||||
cd examples/enum && make
|
|
||||||
cd examples/import && make
|
|
||||||
cd examples/dummy && make
|
|
||||||
cd examples/flow && make
|
|
||||||
cd examples/concat && make
|
|
||||||
cd examples/flow && make
|
|
||||||
cd examples/sitemap && make
|
|
||||||
cd examples/go-generate && make
|
|
||||||
cd examples/single-package-mode && make
|
|
||||||
# cd examples/go-kit && make
|
|
||||||
|
|
||||||
.PHONY: docker.build
|
|
||||||
docker.build:
|
|
||||||
docker build --pull -t moul/protoc-gen-gotemplate .
|
|
||||||
|
|
||||||
.PHONY: docker.push
|
|
||||||
docker.push: docker.build
|
|
||||||
docker push moul/protoc-gen-gotemplate
|
|
82
README.md
82
README.md
@@ -1,32 +1,19 @@
|
|||||||
# `protoc-gen-gotemplate`
|
# protoc-gen-gotemplate
|
||||||
:open_file_folder: protocol generator + golang text/template (protobuf)
|
:open_file_folder: protocol generator + golang text/template (protobuf)
|
||||||
|
|
||||||
A generic **code**/script/data generator based on [Protobuf](https://developers.google.com/protocol-buffers/).
|
Generic protocol buffer generator backed by Golang's [text/template](https://golang.org/pkg/text/template).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
This project is a generator plugin for the Google Protocol Buffers compiler (`protoc`).
|
This is a generator plugin for the Google Protocol Buffers compiler (`protoc`).
|
||||||
|
|
||||||
The plugin parses **protobuf** files, generates an **ast**, and walks a local **templates directory** to generate files using the [Golang's `text/template` engine](https://golang.org/pkg/text/template/).
|
The plugin can generate files based on a template directory using the [Golang's `text/template`](https://golang.org/pkg/text/template/) engine.
|
||||||
|
|
||||||
## Philosophy
|
|
||||||
|
|
||||||
* protobuf-first
|
|
||||||
* no built-in template, only user defined templates
|
|
||||||
* kiss, *keep it stupid simple*
|
|
||||||
|
|
||||||
## Under the hood
|
|
||||||
|
|
||||||
1. the *user* `protobuf` files are parsed by [`protoc`](https://github.com/google/protobuf/releases)
|
|
||||||
2. the `ast` is generated by [`protoc-gen-go` helpers](https://github.com/golang/protobuf/tree/master/protoc-gen-go)
|
|
||||||
3. the `ast` is given to [Golang's `text/template` engine](https://golang.org/pkg/text/template/) for each *user* template files
|
|
||||||
4. the *funcmap* enriching the template engine is based on [Masterminds/sprig](https://github.com/Masterminds/sprig), and contains type-manipulation, iteration and language-specific helpers
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
`protoc-gen-gotemplate` requires a **template_dir** directory *(by default `./templates`)*.
|
`protoc-gen-gotemplate` requires a **template_dir** directory *(by default `./templates`)*.
|
||||||
|
|
||||||
Every file ending with `.tmpl` will be processed and written to the destination folder, following the file hierarchy of the `template_dir`, and remove the `.tmpl` extension.
|
Every files ending with `.tmpl` will be processed and written in the destination folder, following the file hierarchy of the `template_dir`, and removing the `.tmpl` extension.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -39,77 +26,24 @@ input.proto templates/doc.txt.tmpl templates/config.json.tmpl
|
|||||||
doc.txt config.json
|
doc.txt config.json
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
---
|
||||||
|
|
||||||
You can specify custom options, as follow:
|
You can specify a custom `template_dir` or enable `debug`:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$> protoc --gotemplate_out=debug=true,template_dir=/path/to/template/directory:. input.proto
|
$> protoc --gotemplate_out=debug=true,template_dir=/path/to/template/directory:. input.proto
|
||||||
```
|
```
|
||||||
|
|
||||||
| Option | Default Value | Accepted Values | Description
|
---
|
||||||
|-----------------------|---------------|---------------------------|-----------------------
|
|
||||||
| `template_dir` | `./template` | absolute or relative path | path to look for templates
|
|
||||||
| `destination_dir` | `.` | absolute or relative path | base path to write output
|
|
||||||
| `single-package-mode` | *false* | `true` or `false` | if *true*, `protoc` won't accept multiple packages to be compiled at once (*!= from `all`*), but will support `Message` lookup across the imported protobuf dependencies
|
|
||||||
| `debug` | *false* | `true` or `false` | if *true*, `protoc` will generate a more verbose output
|
|
||||||
| `all` | *false* | `true` or `false` | if *true*, protobuf files without `Service` will also be parsed
|
|
||||||
|
|
||||||
##### Hints
|
|
||||||
|
|
||||||
Shipping the templates with your project is very smart and useful when contributing on git-based projects.
|
|
||||||
|
|
||||||
Another workflow consists in having a dedicated repository for generic templates which is then versioned and vendored with multiple projects (npm package, golang vendor package, ...)
|
|
||||||
|
|
||||||
See [examples](./examples).
|
See [examples](./examples).
|
||||||
|
|
||||||
## Funcmap
|
|
||||||
|
|
||||||
This project uses [Masterminds/sprig](https://github.com/Masterminds/sprig) library and additional functions to extend the builtin [text/template](https://golang.org/pkg/text/template) helpers.
|
|
||||||
|
|
||||||
Non-exhaustive list of new helpers:s
|
|
||||||
|
|
||||||
* **all the functions from [sprig](https://github.com/Masterminds/sprig)**
|
|
||||||
* `json`
|
|
||||||
* `prettyjson`
|
|
||||||
* `first`
|
|
||||||
* `last`
|
|
||||||
* `splitArray`
|
|
||||||
* `upperFirst`
|
|
||||||
* `lowerFirst`
|
|
||||||
* `camelCase`
|
|
||||||
* `lowerCamelCase`
|
|
||||||
* `kebabCase`
|
|
||||||
* `snakeCase`
|
|
||||||
* `getProtoFile`
|
|
||||||
* `getMessageType`
|
|
||||||
* `getEnumValue`
|
|
||||||
* `isFieldMessage`
|
|
||||||
* `isFieldRepeated`
|
|
||||||
* `goType`
|
|
||||||
* `goTypeWithPackage`
|
|
||||||
* `jsType`
|
|
||||||
* `jsSuffixReserved`
|
|
||||||
* `namespacedFlowType`
|
|
||||||
* `httpVerb`
|
|
||||||
* `httpPath`
|
|
||||||
* `shortType`
|
|
||||||
* `urlHasVarsFromMessage`
|
|
||||||
|
|
||||||
See the project helpers for the complete list.
|
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
* Install the **Go** compiler and tools from https://golang.org/doc/install
|
* Install the **Go** compiler and tools from https://golang.org/doc/install
|
||||||
* Install **protobuf**: `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}`
|
* Install **protobuf**: `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}`
|
||||||
* Install **protoc-gen-gotemplate**: `go get -u github.com/moul/protoc-gen-gotemplate`
|
* Install **protoc-gen-gotemplate**: `go get -u github.com/moul/protoc-gen-gotemplate`
|
||||||
|
|
||||||
## Projects using `protoc-gen-gotemplate`
|
|
||||||
|
|
||||||
* [kafka-gateway](https://github.com/moul/kafka-gateway/): Kafka gateway/proxy (gRPC + http) using Go-Kit
|
|
||||||
* [translator](https://github.com/moul/translator): Translator Micro-service using Gettext and Go-Kit
|
|
||||||
* [acl](https://github.com/moul/acl): ACL micro-service (gRPC/protobuf + http/json)
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
|
208
encoder.go
208
encoder.go
@@ -11,42 +11,38 @@ import (
|
|||||||
|
|
||||||
"github.com/golang/protobuf/protoc-gen-go/descriptor"
|
"github.com/golang/protobuf/protoc-gen-go/descriptor"
|
||||||
"github.com/golang/protobuf/protoc-gen-go/plugin"
|
"github.com/golang/protobuf/protoc-gen-go/plugin"
|
||||||
|
"github.com/kr/fs"
|
||||||
|
"github.com/moul/funcmap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenericTemplateBasedEncoder struct {
|
type GenericTemplateBasedEncoder struct {
|
||||||
templateDir string
|
templateDir string
|
||||||
service *descriptor.ServiceDescriptorProto
|
service *descriptor.ServiceDescriptorProto
|
||||||
file *descriptor.FileDescriptorProto
|
file *descriptor.FileDescriptorProto
|
||||||
enum []*descriptor.EnumDescriptorProto
|
debug bool
|
||||||
debug bool
|
|
||||||
destinationDir string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ast struct {
|
type Ast struct {
|
||||||
BuildDate time.Time `json:"build-date"`
|
BuildDate time.Time `json:"build-date"`
|
||||||
BuildHostname string `json:"build-hostname"`
|
BuildHostname string `json:"build-hostname"`
|
||||||
BuildUser string `json:"build-user"`
|
BuildUser string `json:"build-user"`
|
||||||
GoPWD string `json:"go-pwd,omitempty"`
|
GoPWD string `json:"go-pwd",omitempty`
|
||||||
PWD string `json:"pwd"`
|
PWD string `json:"pwd"`
|
||||||
Debug bool `json:"debug"`
|
Debug bool `json:"debug"`
|
||||||
DestinationDir string `json:"destination-dir"`
|
File *descriptor.FileDescriptorProto `json:"file"`
|
||||||
File *descriptor.FileDescriptorProto `json:"file"`
|
RawFilename string `json:"raw-filename"`
|
||||||
RawFilename string `json:"raw-filename"`
|
Filename string `json:"filename"`
|
||||||
Filename string `json:"filename"`
|
Service *descriptor.ServiceDescriptorProto `json:"service"`
|
||||||
TemplateDir string `json:"template-dir"`
|
|
||||||
Service *descriptor.ServiceDescriptorProto `json:"service"`
|
|
||||||
Enum []*descriptor.EnumDescriptorProto `json:"enum"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGenericServiceTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) {
|
func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool) (e *GenericTemplateBasedEncoder) {
|
||||||
e = &GenericTemplateBasedEncoder{
|
e = &GenericTemplateBasedEncoder{
|
||||||
service: service,
|
service: service,
|
||||||
file: file,
|
file: file,
|
||||||
templateDir: templateDir,
|
templateDir: templateDir,
|
||||||
debug: debug,
|
debug: debug,
|
||||||
destinationDir: destinationDir,
|
|
||||||
enum: file.GetEnumType(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
log.Printf("new encoder: file=%q service=%q template-dir=%q", file.GetName(), service.GetName(), templateDir)
|
log.Printf("new encoder: file=%q service=%q template-dir=%q", file.GetName(), service.GetName(), templateDir)
|
||||||
}
|
}
|
||||||
@@ -54,46 +50,35 @@ func NewGenericServiceTemplateBasedEncoder(templateDir string, service *descript
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGenericTemplateBasedEncoder(templateDir string, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) {
|
|
||||||
e = &GenericTemplateBasedEncoder{
|
|
||||||
service: nil,
|
|
||||||
file: file,
|
|
||||||
templateDir: templateDir,
|
|
||||||
enum: file.GetEnumType(),
|
|
||||||
debug: debug,
|
|
||||||
destinationDir: destinationDir,
|
|
||||||
}
|
|
||||||
if debug {
|
|
||||||
log.Printf("new encoder: file=%q template-dir=%q", file.GetName(), templateDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *GenericTemplateBasedEncoder) templates() ([]string, error) {
|
func (e *GenericTemplateBasedEncoder) templates() ([]string, error) {
|
||||||
filenames := []string{}
|
filenames := []string{}
|
||||||
|
|
||||||
err := filepath.Walk(e.templateDir, func(path string, info os.FileInfo, err error) error {
|
walker := fs.Walk(e.templateDir)
|
||||||
|
for walker.Step() {
|
||||||
|
if err := walker.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if walker.Stat().IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if filepath.Ext(walker.Path()) != ".tmpl" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
rel, err := filepath.Rel(e.templateDir, walker.Path())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
|
||||||
if info.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if filepath.Ext(path) != ".tmpl" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
rel, err := filepath.Rel(e.templateDir, path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if e.debug {
|
if e.debug {
|
||||||
log.Printf("new template: %q", rel)
|
log.Printf("new template: %q", rel)
|
||||||
}
|
}
|
||||||
|
|
||||||
filenames = append(filenames, rel)
|
filenames = append(filenames, rel)
|
||||||
return nil
|
}
|
||||||
})
|
|
||||||
return filenames, err
|
return filenames, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *GenericTemplateBasedEncoder) genAst(templateFilename string) (*Ast, error) {
|
func (e *GenericTemplateBasedEncoder) genAst(templateFilename string) (*Ast, error) {
|
||||||
@@ -108,88 +93,91 @@ func (e *GenericTemplateBasedEncoder) genAst(templateFilename string) (*Ast, err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast := Ast{
|
ast := Ast{
|
||||||
BuildDate: time.Now(),
|
BuildDate: time.Now(),
|
||||||
BuildHostname: hostname,
|
BuildHostname: hostname,
|
||||||
BuildUser: os.Getenv("USER"),
|
BuildUser: os.Getenv("USER"),
|
||||||
PWD: pwd,
|
PWD: pwd,
|
||||||
GoPWD: goPwd,
|
GoPWD: goPwd,
|
||||||
File: e.file,
|
File: e.file,
|
||||||
TemplateDir: e.templateDir,
|
RawFilename: templateFilename,
|
||||||
DestinationDir: e.destinationDir,
|
// Filename: "",
|
||||||
RawFilename: templateFilename,
|
Service: e.service,
|
||||||
Filename: "",
|
|
||||||
Service: e.service,
|
|
||||||
Enum: e.enum,
|
|
||||||
}
|
}
|
||||||
buffer := new(bytes.Buffer)
|
|
||||||
tmpl, err := template.New("").Funcs(ProtoHelpersFuncMap).Parse(templateFilename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := tmpl.Execute(buffer, ast); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ast.Filename = buffer.String()
|
|
||||||
return &ast, nil
|
return &ast, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *GenericTemplateBasedEncoder) buildContent(templateFilename string) (string, string, error) {
|
func (e *GenericTemplateBasedEncoder) buildContent(templateFilename string) (string, error) {
|
||||||
// initialize template engine
|
// initialize template engine
|
||||||
fullPath := filepath.Join(e.templateDir, templateFilename)
|
fullPath := filepath.Join(e.templateDir, templateFilename)
|
||||||
templateName := filepath.Base(fullPath)
|
templateName := filepath.Base(fullPath)
|
||||||
tmpl, err := template.New(templateName).Funcs(ProtoHelpersFuncMap).ParseFiles(fullPath)
|
tmpl, err := template.New(templateName).Funcs(funcmap.FuncMap).ParseFiles(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
ast, err := e.genAst(templateFilename)
|
ast, err := e.genAst(templateFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// translate the filename
|
||||||
|
ast.Filename, err = e.translateString(templateFilename, templateFilename)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate the content
|
// generate the content
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
if err := tmpl.Execute(buffer, ast); err != nil {
|
if err := tmpl.Execute(buffer, ast); err != nil {
|
||||||
return "", "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.String(), ast.Filename, nil
|
return buffer.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *GenericTemplateBasedEncoder) translateString(input string, templateFilename string) (string, error) {
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
tmpl, err := template.New("").Funcs(funcmap.FuncMap).Parse(input)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
ast, err := e.genAst(templateFilename)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tmpl.Execute(buffer, ast); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return buffer.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *GenericTemplateBasedEncoder) Files() []*plugin_go.CodeGeneratorResponse_File {
|
func (e *GenericTemplateBasedEncoder) Files() []*plugin_go.CodeGeneratorResponse_File {
|
||||||
|
files := []*plugin_go.CodeGeneratorResponse_File{}
|
||||||
|
|
||||||
templates, err := e.templates()
|
templates, err := e.templates()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("cannot get templates from %q: %v", e.templateDir, err)
|
log.Fatalf("cannot get templates from %q: %v", e.templateDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
length := len(templates)
|
|
||||||
files := make([]*plugin_go.CodeGeneratorResponse_File, 0, length)
|
|
||||||
errChan := make(chan error, length)
|
|
||||||
resultChan := make(chan *plugin_go.CodeGeneratorResponse_File, length)
|
|
||||||
for _, templateFilename := range templates {
|
for _, templateFilename := range templates {
|
||||||
go func(tmpl string) {
|
content, err := e.buildContent(templateFilename)
|
||||||
content, translatedFilename, err := e.buildContent(tmpl)
|
if err != nil {
|
||||||
if err != nil {
|
panic(err)
|
||||||
errChan <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
filename := translatedFilename[:len(translatedFilename)-len(".tmpl")]
|
|
||||||
|
|
||||||
resultChan <- &plugin_go.CodeGeneratorResponse_File{
|
|
||||||
Content: &content,
|
|
||||||
Name: &filename,
|
|
||||||
}
|
|
||||||
}(templateFilename)
|
|
||||||
}
|
|
||||||
for i := 0; i < length; i++ {
|
|
||||||
select {
|
|
||||||
case f := <-resultChan:
|
|
||||||
files = append(files, f)
|
|
||||||
case err = <-errChan:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
translatedFilename, err := e.translateString(templateFilename, templateFilename)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
filename := translatedFilename[0 : len(translatedFilename)-len(".tmpl")]
|
||||||
|
|
||||||
|
files = append(files, &plugin_go.CodeGeneratorResponse_File{
|
||||||
|
Content: &content,
|
||||||
|
Name: &filename,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
mkdir -p output
|
|
||||||
protoc -I. --gotemplate_out=template_dir=templates,debug=true,all=true:output proto/*.proto
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: re
|
|
||||||
re: clean build
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
rm -rf output
|
|
@@ -1,3 +0,0 @@
|
|||||||
I'm Eric
|
|
||||||
I'm Francis
|
|
||||||
I'm Arnold
|
|
@@ -1 +0,0 @@
|
|||||||
This is static text.This is static text.This is static text.
|
|
@@ -1,2 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package Eric;
|
|
@@ -1,2 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package Francis;
|
|
@@ -1,2 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package Arnold;
|
|
@@ -1 +0,0 @@
|
|||||||
I'm {{.File.Package}}
|
|
@@ -1 +0,0 @@
|
|||||||
This is static text.
|
|
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"build-date": "2017-05-02T11:50:25.063291628+02:00",
|
"build-date": "2016-11-09T18:39:15.154031816+01:00",
|
||||||
"build-hostname": "manfred-spacegray.local",
|
"build-hostname": "moul-rose.local",
|
||||||
"build-user": "moul",
|
"build-user": "moul",
|
||||||
"pwd": "/Users/moul/Git/moul/protoc-gen-gotemplate/examples/dummy",
|
"go-pwd": "github.com/moul/protoc-gen-gotemplate/examples/dummy",
|
||||||
|
"pwd": "/Users/moul/go/src/github.com/moul/protoc-gen-gotemplate/examples/dummy",
|
||||||
"debug": false,
|
"debug": false,
|
||||||
"destination-dir": ".",
|
|
||||||
"file": {
|
"file": {
|
||||||
"name": "dummy.proto",
|
"name": "dummy.proto",
|
||||||
"package": "dummy",
|
"package": "dummy",
|
||||||
@@ -822,7 +822,6 @@
|
|||||||
},
|
},
|
||||||
"raw-filename": "export.json.tmpl",
|
"raw-filename": "export.json.tmpl",
|
||||||
"filename": "export.json.tmpl",
|
"filename": "export.json.tmpl",
|
||||||
"template-dir": "templates",
|
|
||||||
"service": {
|
"service": {
|
||||||
"name": "DummyService",
|
"name": "DummyService",
|
||||||
"method": [
|
"method": [
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
mkdir -p output
|
|
||||||
protoc -I. --gotemplate_out=template_dir=templates,debug=true,all=true:output proto/*.proto
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: re
|
|
||||||
re: clean build
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
rm -rf output
|
|
@@ -1,9 +0,0 @@
|
|||||||
-red
|
|
||||||
-blue
|
|
||||||
-black
|
|
||||||
-yellow
|
|
||||||
-green
|
|
||||||
-dark
|
|
||||||
-white
|
|
||||||
-gray
|
|
||||||
-orange
|
|
@@ -1,14 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package Sample;
|
|
||||||
|
|
||||||
enum Colors {
|
|
||||||
red = 0;
|
|
||||||
blue = 1;
|
|
||||||
black = 2;
|
|
||||||
yellow = 3;
|
|
||||||
green = 4;
|
|
||||||
dark = 5;
|
|
||||||
white = 6;
|
|
||||||
gray = 7;
|
|
||||||
orange = 8;
|
|
||||||
}
|
|
@@ -1,2 +0,0 @@
|
|||||||
{{range $m := "colors" | getEnumValue .Enum }}-{{$m.Name}}
|
|
||||||
{{end}}
|
|
@@ -1,13 +0,0 @@
|
|||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
mkdir -p output
|
|
||||||
protoc -I. --gotemplate_out=template_dir=templates,debug=true:output ./protos/*.proto
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: re
|
|
||||||
re: clean build
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
rm -rf output
|
|
@@ -1,311 +0,0 @@
|
|||||||
// @flow
|
|
||||||
// GENERATED CODE -- DO NOT EDIT!
|
|
||||||
|
|
||||||
import base64 from 'base64-js'
|
|
||||||
import test_pb from './test_pb'
|
|
||||||
|
|
||||||
|
|
||||||
export type TestEnum = {|
|
|
||||||
ELEMENT_A?: 0;
|
|
||||||
ELEMENT_B?: 1;
|
|
||||||
|};
|
|
||||||
|
|
||||||
|
|
||||||
export type TestMessage$TestNestedEnum = {|
|
|
||||||
ELEMENT_C?: 0;
|
|
||||||
ELEMENT_D?: 1;
|
|
||||||
|};
|
|
||||||
|
|
||||||
|
|
||||||
export type TestMessage$TestNestedMessage = {
|
|
||||||
getS?: () => string;
|
|
||||||
setS?: (s: string) => void;
|
|
||||||
getT?: () => number;
|
|
||||||
setT?: (t: number) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type TestMessage = {
|
|
||||||
getA?: () => string;
|
|
||||||
setA?: (a: string) => void;
|
|
||||||
getB?: () => number;
|
|
||||||
setB?: (b: number) => void;
|
|
||||||
getC?: () => number;
|
|
||||||
setC?: (c: number) => void;
|
|
||||||
getD?: () => number;
|
|
||||||
setD?: (d: number) => void;
|
|
||||||
getE?: () => number;
|
|
||||||
setE?: (e: number) => void;
|
|
||||||
getNList?: () => Array<string>;
|
|
||||||
setNList?: (n: Array<string>) => void;
|
|
||||||
addN?: (n: string) => void;
|
|
||||||
clearNList?: () => void;
|
|
||||||
getOList?: () => Array<number>;
|
|
||||||
setOList?: (o: Array<number>) => void;
|
|
||||||
addO?: (o: number) => void;
|
|
||||||
clearOList?: () => void;
|
|
||||||
getPList?: () => Array<number>;
|
|
||||||
setPList?: (p: Array<number>) => void;
|
|
||||||
addP?: (p: number) => void;
|
|
||||||
clearPList?: () => void;
|
|
||||||
getQList?: () => Array<number>;
|
|
||||||
setQList?: (q: Array<number>) => void;
|
|
||||||
addQ?: (q: number) => void;
|
|
||||||
clearQList?: () => void;
|
|
||||||
getRList?: () => Array<number>;
|
|
||||||
setRList?: (r: Array<number>) => void;
|
|
||||||
addR?: (r: number) => void;
|
|
||||||
clearRList?: () => void;
|
|
||||||
getU?: () => test$TestEnum;
|
|
||||||
setU?: (u: test$TestEnum) => void;
|
|
||||||
getV?: () => test$TestMessage$TestNestedEnum;
|
|
||||||
setV?: (v: test$TestMessage$TestNestedEnum) => void;
|
|
||||||
getWList?: () => Array<test$TestMessage$TestNestedMessage>;
|
|
||||||
setWList?: (w: Array<test$TestMessage$TestNestedMessage>) => void;
|
|
||||||
addW?: (w: test$TestMessage$TestNestedMessage) => void;
|
|
||||||
clearWList?: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestNoStreamRequest = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestNoStreamReply = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
getErrMsg?: () => string;
|
|
||||||
setErrMsg?: (err_msg: string) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestStreamRequestRequest = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestStreamRequestReply = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
getErrMsg?: () => string;
|
|
||||||
setErrMsg?: (err_msg: string) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestStreamReplyRequest = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestStreamReplyReply = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
getErrMsg?: () => string;
|
|
||||||
setErrMsg?: (err_msg: string) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestStreamBothRequest = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestStreamBothReply = {
|
|
||||||
getMessage?: () => test$TestMessage;
|
|
||||||
setMessage?: (message: test$TestMessage) => void;
|
|
||||||
clearMessage?: () => void;
|
|
||||||
hasMessage?: () => boolean;
|
|
||||||
getErrMsg?: () => string;
|
|
||||||
setErrMsg?: (err_msg: string) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const serializeToBase64 = (byteArray: Uint8Array): string => base64.fromByteArray(byteArray)
|
|
||||||
const deserializeFromBase64 = (base64Encoded: string): Uint8Array => new Uint8Array(base64.toByteArray(base64Encoded))
|
|
||||||
|
|
||||||
|
|
||||||
function serialize_test_TestNoStreamRequest(arg : TestNoStreamRequest): string {
|
|
||||||
if (!(arg instanceof test_pb.TestNoStreamRequest)) {
|
|
||||||
throw new Error('Expected argument of type TestNoStreamRequest')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestNoStreamRequest(base64Encoded: string): TestNoStreamRequest {
|
|
||||||
return test_pb.TestNoStreamRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestNoStreamReply(arg : TestNoStreamReply): string {
|
|
||||||
if (!(arg instanceof test_pb.TestNoStreamReply)) {
|
|
||||||
throw new Error('Expected argument of type TestNoStreamReply')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestNoStreamReply(base64Encoded: string): TestNoStreamReply {
|
|
||||||
return test_pb.TestNoStreamReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function serialize_test_TestStreamRequestRequest(arg : TestStreamRequestRequest): string {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamRequestRequest)) {
|
|
||||||
throw new Error('Expected argument of type TestStreamRequestRequest')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamRequestRequest(base64Encoded: string): TestStreamRequestRequest {
|
|
||||||
return test_pb.TestStreamRequestRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamRequestReply(arg : TestStreamRequestReply): string {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamRequestReply)) {
|
|
||||||
throw new Error('Expected argument of type TestStreamRequestReply')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamRequestReply(base64Encoded: string): TestStreamRequestReply {
|
|
||||||
return test_pb.TestStreamRequestReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function serialize_test_TestStreamReplyRequest(arg : TestStreamReplyRequest): string {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamReplyRequest)) {
|
|
||||||
throw new Error('Expected argument of type TestStreamReplyRequest')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamReplyRequest(base64Encoded: string): TestStreamReplyRequest {
|
|
||||||
return test_pb.TestStreamReplyRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamReplyReply(arg : TestStreamReplyReply): string {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamReplyReply)) {
|
|
||||||
throw new Error('Expected argument of type TestStreamReplyReply')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamReplyReply(base64Encoded: string): TestStreamReplyReply {
|
|
||||||
return test_pb.TestStreamReplyReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function serialize_test_TestStreamBothRequest(arg : TestStreamBothRequest): string {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamBothRequest)) {
|
|
||||||
throw new Error('Expected argument of type TestStreamBothRequest')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamBothRequest(base64Encoded: string): TestStreamBothRequest {
|
|
||||||
return test_pb.TestStreamBothRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamBothReply(arg : TestStreamBothReply): string {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamBothReply)) {
|
|
||||||
throw new Error('Expected argument of type TestStreamBothReply')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamBothReply(base64Encoded: string): TestStreamBothReply {
|
|
||||||
return test_pb.TestStreamBothReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export default {
|
|
||||||
|
|
||||||
TestService: {
|
|
||||||
|
|
||||||
testNoStream: {
|
|
||||||
path: '/test.TestService/TestNoStream',
|
|
||||||
requestStream: false,
|
|
||||||
responseStream: false,
|
|
||||||
requestType: test_pb.TestNoStreamRequest,
|
|
||||||
responseType: test_pb.TestNoStreamReply,
|
|
||||||
requestSerialize: serialize_test_TestNoStreamRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestNoStreamRequest,
|
|
||||||
responseSerialize: serialize_test_TestNoStreamReply,
|
|
||||||
responseDeserialize: deserialize_test_TestNoStreamReply,
|
|
||||||
},
|
|
||||||
testStreamRequest: {
|
|
||||||
path: '/test.TestService/TestStreamRequest',
|
|
||||||
requestStream: true,
|
|
||||||
responseStream: false,
|
|
||||||
requestType: test_pb.TestStreamRequestRequest,
|
|
||||||
responseType: test_pb.TestStreamRequestReply,
|
|
||||||
requestSerialize: serialize_test_TestStreamRequestRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestStreamRequestRequest,
|
|
||||||
responseSerialize: serialize_test_TestStreamRequestReply,
|
|
||||||
responseDeserialize: deserialize_test_TestStreamRequestReply,
|
|
||||||
},
|
|
||||||
testStreamReply: {
|
|
||||||
path: '/test.TestService/TestStreamReply',
|
|
||||||
requestStream: false,
|
|
||||||
responseStream: true,
|
|
||||||
requestType: test_pb.TestStreamReplyRequest,
|
|
||||||
responseType: test_pb.TestStreamReplyReply,
|
|
||||||
requestSerialize: serialize_test_TestStreamReplyRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestStreamReplyRequest,
|
|
||||||
responseSerialize: serialize_test_TestStreamReplyReply,
|
|
||||||
responseDeserialize: deserialize_test_TestStreamReplyReply,
|
|
||||||
},
|
|
||||||
testStreamBoth: {
|
|
||||||
path: '/test.TestService/TestStreamBoth',
|
|
||||||
requestStream: true,
|
|
||||||
responseStream: true,
|
|
||||||
requestType: test_pb.TestStreamBothRequest,
|
|
||||||
responseType: test_pb.TestStreamBothReply,
|
|
||||||
requestSerialize: serialize_test_TestStreamBothRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestStreamBothRequest,
|
|
||||||
responseSerialize: serialize_test_TestStreamBothReply,
|
|
||||||
responseDeserialize: deserialize_test_TestStreamBothReply,
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,52 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package test;
|
|
||||||
|
|
||||||
option go_package = "github.com/united-drivers/models/go/test;testpb";
|
|
||||||
|
|
||||||
service TestService {
|
|
||||||
rpc TestNoStream(TestNoStreamRequest) returns (TestNoStreamReply);
|
|
||||||
rpc TestStreamRequest(stream TestStreamRequestRequest) returns (TestStreamRequestReply);
|
|
||||||
rpc TestStreamReply(TestStreamReplyRequest) returns (stream TestStreamReplyReply);
|
|
||||||
rpc TestStreamBoth(stream TestStreamBothRequest) returns (stream TestStreamBothReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum TestEnum {
|
|
||||||
ELEMENT_A = 0;
|
|
||||||
ELEMENT_B = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message TestMessage {
|
|
||||||
string a = 1;
|
|
||||||
int32 b = 2;
|
|
||||||
int64 c = 3;
|
|
||||||
float d = 4;
|
|
||||||
double e = 5;
|
|
||||||
repeated string n = 14;
|
|
||||||
repeated int32 o = 15;
|
|
||||||
repeated int64 p = 16;
|
|
||||||
repeated float q = 17;
|
|
||||||
repeated double r = 18;
|
|
||||||
|
|
||||||
message TestNestedMessage {
|
|
||||||
string s = 1;
|
|
||||||
int32 t = 2;
|
|
||||||
}
|
|
||||||
enum TestNestedEnum {
|
|
||||||
ELEMENT_C = 0;
|
|
||||||
ELEMENT_D = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TestEnum u = 19;
|
|
||||||
TestNestedEnum v = 20;
|
|
||||||
repeated TestNestedMessage w = 21;
|
|
||||||
}
|
|
||||||
|
|
||||||
message TestNoStreamRequest { TestMessage message = 1; }
|
|
||||||
message TestNoStreamReply { TestMessage message = 1; string err_msg = 2; }
|
|
||||||
message TestStreamRequestRequest { TestMessage message = 1; }
|
|
||||||
message TestStreamRequestReply { TestMessage message = 1; string err_msg = 2; }
|
|
||||||
message TestStreamReplyRequest { TestMessage message = 1; }
|
|
||||||
message TestStreamReplyReply { TestMessage message = 1; string err_msg = 2; }
|
|
||||||
message TestStreamBothRequest { TestMessage message = 1; }
|
|
||||||
message TestStreamBothReply { TestMessage message = 1; string err_msg = 2; }
|
|
@@ -1,110 +0,0 @@
|
|||||||
// @flow
|
|
||||||
// GENERATED CODE -- DO NOT EDIT!
|
|
||||||
|
|
||||||
{{- $Package:=.File.Package}}
|
|
||||||
|
|
||||||
import base64 from 'base64-js'
|
|
||||||
import {{$Package}}_pb from './{{$Package}}_pb'
|
|
||||||
|
|
||||||
{{- range .File.Dependency}}
|
|
||||||
import {{. | replace "/" "_" | trimSuffix ".proto" }}_pb from '../{{. | trimSuffix ".proto" }}_pb'
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
{{- define "fieldMethods"}}
|
|
||||||
{{- if isFieldRepeated .}}
|
|
||||||
get{{.Name | camelCase}}List?: () => {{. | jsType}};
|
|
||||||
set{{.Name | camelCase}}List?: ({{.Name}}: {{. | jsType}}) => void;
|
|
||||||
add{{.Name | camelCase}}?: ({{.Name}}: {{. | jsType | trimPrefix "Array<" | trimSuffix ">"}}) => void;
|
|
||||||
clear{{.Name | camelCase}}List?: () => void;
|
|
||||||
{{- else}}
|
|
||||||
get{{.Name | camelCase}}?: () => {{. | jsType}};
|
|
||||||
set{{.Name | camelCase}}?: ({{.Name}}: {{. | jsType}}) => void;
|
|
||||||
|
|
||||||
{{- if isFieldMessage .}}
|
|
||||||
clear{{.Name | camelCase}}?: () => void;
|
|
||||||
has{{.Name | camelCase}}?: () => boolean;
|
|
||||||
{{- end}}
|
|
||||||
{{- end}}
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
{{range .File.EnumType}}
|
|
||||||
export type {{.Name}} = {|
|
|
||||||
{{- range .Value}}
|
|
||||||
{{.Name}}?: {{.Number}};
|
|
||||||
{{- end}}
|
|
||||||
|};
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
{{- range .File.MessageType}}
|
|
||||||
{{- $MessageType := .Name}}
|
|
||||||
|
|
||||||
{{range .EnumType}}
|
|
||||||
export type {{$MessageType}}${{.Name}} = {|
|
|
||||||
{{- range .Value}}
|
|
||||||
{{.Name}}?: {{.Number}};
|
|
||||||
{{- end}}
|
|
||||||
|};
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
{{range .NestedType}}
|
|
||||||
export type {{$MessageType}}${{.Name}} = {
|
|
||||||
{{- range .Field}}
|
|
||||||
{{- template "fieldMethods" .}}
|
|
||||||
{{- end}}
|
|
||||||
};
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
export type {{.Name}} = {
|
|
||||||
{{- range .Field}}
|
|
||||||
{{- template "fieldMethods" .}}
|
|
||||||
{{- end}}
|
|
||||||
};
|
|
||||||
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
const serializeToBase64 = (byteArray: Uint8Array): string => base64.fromByteArray(byteArray)
|
|
||||||
const deserializeFromBase64 = (base64Encoded: string): Uint8Array => new Uint8Array(base64.toByteArray(base64Encoded))
|
|
||||||
|
|
||||||
{{range .File.Service}}{{range .Method}}
|
|
||||||
function serialize_{{$Package}}_{{.InputType | shortType}}(arg : {{.InputType | shortType}}): string {
|
|
||||||
if (!(arg instanceof {{$Package}}_pb.{{.InputType | shortType}})) {
|
|
||||||
throw new Error('Expected argument of type {{.InputType | shortType}}')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.InputType | shortType}}(base64Encoded: string): {{.InputType | shortType}} {
|
|
||||||
return {{$Package}}_pb.{{.InputType | shortType}}.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_{{$Package}}_{{.OutputType | shortType}}(arg : {{.OutputType | shortType}}): string {
|
|
||||||
if (!(arg instanceof {{$Package}}_pb.{{.OutputType | shortType}})) {
|
|
||||||
throw new Error('Expected argument of type {{.OutputType | shortType}}')
|
|
||||||
}
|
|
||||||
return serializeToBase64(arg.serializeBinary())
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.OutputType | shortType}}(base64Encoded: string): {{.OutputType | shortType}} {
|
|
||||||
return {{$Package}}_pb.{{.OutputType | shortType}}.deserializeBinary(deserializeFromBase64(base64Encoded))
|
|
||||||
}
|
|
||||||
|
|
||||||
{{end}}{{end}}
|
|
||||||
export default {
|
|
||||||
{{range .File.Service}}
|
|
||||||
{{.Name}}: {
|
|
||||||
{{$serviceName:=.Name}}
|
|
||||||
{{range .Method}}{{.Name | lowerCamelCase}}: {
|
|
||||||
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
|
|
||||||
requestStream: {{.ClientStreaming | default "false"}},
|
|
||||||
responseStream: {{.ServerStreaming | default "false"}},
|
|
||||||
requestType: {{$Package}}_pb.{{.InputType | shortType}},
|
|
||||||
responseType: {{$Package}}_pb.{{.OutputType | shortType}},
|
|
||||||
requestSerialize: serialize_{{$Package}}_{{.InputType | shortType}},
|
|
||||||
requestDeserialize: deserialize_{{$Package}}_{{.InputType | shortType}},
|
|
||||||
responseSerialize: serialize_{{$Package}}_{{.OutputType | shortType}},
|
|
||||||
responseDeserialize: deserialize_{{$Package}}_{{.OutputType | shortType}},
|
|
||||||
},
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
}
|
|
@@ -1,2 +0,0 @@
|
|||||||
all:
|
|
||||||
go generate
|
|
@@ -1,4 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
//go:generate protoc --go_out=./gen/ example.proto
|
|
||||||
//go:generate protoc --gotemplate_out=./gen/ example.proto
|
|
@@ -1,16 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package example;
|
|
||||||
|
|
||||||
service Sum {
|
|
||||||
rpc Sum(SumRequest) returns (SumReply) {};
|
|
||||||
}
|
|
||||||
|
|
||||||
message SumRequest {
|
|
||||||
int32 a = 1;
|
|
||||||
int32 b = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message SumReply {
|
|
||||||
int32 c = 1;
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
// Code generated by protoc-gen-gotemplate
|
|
||||||
package example
|
|
||||||
|
|
||||||
// Methods
|
|
||||||
// -------
|
|
||||||
// * Sum
|
|
||||||
//
|
|
||||||
// Message types
|
|
||||||
// -------------
|
|
||||||
// * SumRequest
|
|
||||||
// * SumReply
|
|
@@ -1,89 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: example.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package example is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
example.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
SumRequest
|
|
||||||
SumReply
|
|
||||||
*/
|
|
||||||
package example
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type SumRequest struct {
|
|
||||||
A int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
|
|
||||||
B int32 `protobuf:"varint,2,opt,name=b" json:"b,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SumRequest) Reset() { *m = SumRequest{} }
|
|
||||||
func (m *SumRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*SumRequest) ProtoMessage() {}
|
|
||||||
func (*SumRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *SumRequest) GetA() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.A
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SumRequest) GetB() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.B
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
type SumReply struct {
|
|
||||||
C int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SumReply) Reset() { *m = SumReply{} }
|
|
||||||
func (m *SumReply) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*SumReply) ProtoMessage() {}
|
|
||||||
func (*SumReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
|
|
||||||
func (m *SumReply) GetC() int32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.C
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*SumRequest)(nil), "example.SumRequest")
|
|
||||||
proto.RegisterType((*SumReply)(nil), "example.SumReply")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("example.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 124 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0xad, 0x48, 0xcc,
|
|
||||||
0x2d, 0xc8, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x87, 0x72, 0x95, 0x34, 0xb8,
|
|
||||||
0xb8, 0x82, 0x4b, 0x73, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x78, 0xb8, 0x18, 0x13,
|
|
||||||
0x25, 0x18, 0x15, 0x18, 0x35, 0x58, 0x83, 0x18, 0x13, 0x41, 0xbc, 0x24, 0x09, 0x26, 0x08, 0x2f,
|
|
||||||
0x49, 0x49, 0x82, 0x8b, 0x03, 0xac, 0xb2, 0x20, 0xa7, 0x12, 0x24, 0x93, 0x0c, 0x53, 0x97, 0x6c,
|
|
||||||
0x64, 0xc6, 0xc5, 0x1c, 0x5c, 0x9a, 0x2b, 0xa4, 0x0f, 0xa1, 0x84, 0xf5, 0x60, 0x56, 0x21, 0x0c,
|
|
||||||
0x96, 0x12, 0x44, 0x15, 0x2c, 0xc8, 0xa9, 0x54, 0x62, 0x48, 0x62, 0x03, 0xbb, 0xc5, 0x18, 0x10,
|
|
||||||
0x00, 0x00, 0xff, 0xff, 0x2b, 0xf1, 0xe9, 0x56, 0x9c, 0x00, 0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,14 +0,0 @@
|
|||||||
// Code generated by protoc-gen-gotemplate
|
|
||||||
package {{.File.Package}}
|
|
||||||
|
|
||||||
// Methods
|
|
||||||
// -------
|
|
||||||
{{- range .Service.Method}}
|
|
||||||
// * {{.Name}}
|
|
||||||
{{- end}}
|
|
||||||
//
|
|
||||||
// Message types
|
|
||||||
// -------------
|
|
||||||
{{- range .File.MessageType}}
|
|
||||||
// * {{.Name}}
|
|
||||||
{{- end}}
|
|
2
examples/go-kit/.gitignore
vendored
2
examples/go-kit/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
/vendor/
|
|
||||||
/server
|
|
@@ -1,24 +0,0 @@
|
|||||||
SOURCES := $(shell find . -name "*.proto" -not -path ./vendor/\*)
|
|
||||||
|
|
||||||
TARGETS_GO := $(foreach source, $(SOURCES), $(source)_go)
|
|
||||||
TARGETS_TMPL := $(foreach source, $(SOURCES), $(source)_tmpl)
|
|
||||||
|
|
||||||
service_name = $(word 2,$(subst /, ,$1))
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build: server
|
|
||||||
|
|
||||||
server: $(TARGETS_GO) $(TARGETS_TMPL)
|
|
||||||
glide install
|
|
||||||
go build -o server .
|
|
||||||
|
|
||||||
$(TARGETS_GO): %_go:
|
|
||||||
protoc --go_out=plugins=grpc:. "$*"
|
|
||||||
@mkdir -p services/$(call service_name,$*)/gen/pb
|
|
||||||
@mv ./services/$(call service_name,$*)/$(call service_name,$*).pb.go ./services/$(call service_name,$*)/gen/pb/pb.go
|
|
||||||
|
|
||||||
$(TARGETS_TMPL): %_tmpl:
|
|
||||||
@mkdir -p $(dir $*)gen
|
|
||||||
protoc -I. --gotemplate_out=destination_dir=services/$(call service_name,$*)/gen,template_dir=templates:services "$*"
|
|
||||||
@rm -rf services/services # need to investigate why this directory is created
|
|
||||||
gofmt -w $(dir $*)gen
|
|
48
examples/go-kit/glide.lock
generated
48
examples/go-kit/glide.lock
generated
@@ -1,48 +0,0 @@
|
|||||||
hash: e225ab17b49f8d6601b2bd813d43ad34ee04380d29c278c11919efd454c7b2d7
|
|
||||||
updated: 2017-03-16T17:03:34.437968115+01:00
|
|
||||||
imports:
|
|
||||||
- name: github.com/dgrijalva/jwt-go
|
|
||||||
version: 2268707a8f0843315e2004ee4f1d021dc08baedf
|
|
||||||
- name: github.com/go-kit/kit
|
|
||||||
version: fadad6fffe0466b19df9efd9acde5c9a52df5fa4
|
|
||||||
subpackages:
|
|
||||||
- auth/jwt
|
|
||||||
- endpoint
|
|
||||||
- log
|
|
||||||
- transport/grpc
|
|
||||||
- transport/http
|
|
||||||
- name: github.com/go-logfmt/logfmt
|
|
||||||
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
|
|
||||||
- name: github.com/go-stack/stack
|
|
||||||
version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82
|
|
||||||
- name: github.com/golang/protobuf
|
|
||||||
version: c9c7427a2a70d2eb3bafa0ab2dc163e45f143317
|
|
||||||
subpackages:
|
|
||||||
- proto
|
|
||||||
- name: github.com/gorilla/handlers
|
|
||||||
version: 3a5767ca75ece5f7f1440b1d16975247f8d8b221
|
|
||||||
- name: github.com/kr/logfmt
|
|
||||||
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
|
|
||||||
- name: golang.org/x/net
|
|
||||||
version: a6577fac2d73be281a500b310739095313165611
|
|
||||||
subpackages:
|
|
||||||
- context
|
|
||||||
- context/ctxhttp
|
|
||||||
- http2
|
|
||||||
- http2/hpack
|
|
||||||
- idna
|
|
||||||
- internal/timeseries
|
|
||||||
- lex/httplex
|
|
||||||
- trace
|
|
||||||
- name: google.golang.org/grpc
|
|
||||||
version: 777daa17ff9b5daef1cfdf915088a2ada3332bf0
|
|
||||||
subpackages:
|
|
||||||
- codes
|
|
||||||
- credentials
|
|
||||||
- grpclog
|
|
||||||
- internal
|
|
||||||
- metadata
|
|
||||||
- naming
|
|
||||||
- peer
|
|
||||||
- transport
|
|
||||||
testImports: []
|
|
@@ -1,20 +0,0 @@
|
|||||||
package: github.com/moul/protoc-gen-gotemplate/examples/go-kit
|
|
||||||
import:
|
|
||||||
- package: github.com/go-kit/kit
|
|
||||||
subpackages:
|
|
||||||
- auth/jwt
|
|
||||||
- endpoint
|
|
||||||
- log
|
|
||||||
- transport/grpc
|
|
||||||
- transport/http
|
|
||||||
- package: github.com/golang/protobuf
|
|
||||||
subpackages:
|
|
||||||
- proto
|
|
||||||
version: c9c7427a2a70d2eb3bafa0ab2dc163e45f143317
|
|
||||||
- package: github.com/gorilla/handlers
|
|
||||||
- package: golang.org/x/net
|
|
||||||
subpackages:
|
|
||||||
- context
|
|
||||||
- http2
|
|
||||||
version: a6577fac2d73be281a500b310739095313165611
|
|
||||||
- package: google.golang.org/grpc
|
|
@@ -1,93 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
|
||||||
"github.com/gorilla/handlers"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
session_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session"
|
|
||||||
session_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints"
|
|
||||||
session_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
|
||||||
session_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/grpc"
|
|
||||||
session_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/http"
|
|
||||||
|
|
||||||
sprint_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint"
|
|
||||||
sprint_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints"
|
|
||||||
sprint_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb"
|
|
||||||
sprint_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/grpc"
|
|
||||||
sprint_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/http"
|
|
||||||
|
|
||||||
user_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user"
|
|
||||||
user_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
|
||||||
user_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
||||||
user_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/grpc"
|
|
||||||
user_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
errc := make(chan error)
|
|
||||||
s := grpc.NewServer()
|
|
||||||
var logger log.Logger
|
|
||||||
{
|
|
||||||
logger = log.NewLogfmtLogger(os.Stdout)
|
|
||||||
logger = log.With(logger, "ts", log.DefaultTimestampUTC)
|
|
||||||
logger = log.With(logger, "caller", log.DefaultCaller)
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize services
|
|
||||||
{
|
|
||||||
svc := session_svc.New()
|
|
||||||
endpoints := session_endpoints.MakeEndpoints(svc)
|
|
||||||
srv := session_grpctransport.MakeGRPCServer(endpoints)
|
|
||||||
session_pb.RegisterSessionServiceServer(s, srv)
|
|
||||||
session_httptransport.RegisterHandlers(svc, mux, endpoints)
|
|
||||||
}
|
|
||||||
{
|
|
||||||
svc := sprint_svc.New()
|
|
||||||
endpoints := sprint_endpoints.MakeEndpoints(svc)
|
|
||||||
srv := sprint_grpctransport.MakeGRPCServer(endpoints)
|
|
||||||
sprint_pb.RegisterSprintServiceServer(s, srv)
|
|
||||||
sprint_httptransport.RegisterHandlers(svc, mux, endpoints)
|
|
||||||
}
|
|
||||||
{
|
|
||||||
svc := user_svc.New()
|
|
||||||
endpoints := user_endpoints.MakeEndpoints(svc)
|
|
||||||
srv := user_grpctransport.MakeGRPCServer(endpoints)
|
|
||||||
user_pb.RegisterUserServiceServer(s, srv)
|
|
||||||
user_httptransport.RegisterHandlers(svc, mux, endpoints)
|
|
||||||
}
|
|
||||||
|
|
||||||
// start servers
|
|
||||||
go func() {
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
errc <- fmt.Errorf("%s", <-c)
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
logger := log.With(logger, "transport", "HTTP")
|
|
||||||
logger.Log("addr", ":8000")
|
|
||||||
errc <- http.ListenAndServe(":8000", handlers.LoggingHandler(os.Stderr, mux))
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
logger := log.With(logger, "transport", "gRPC")
|
|
||||||
ln, err := net.Listen("tcp", ":9000")
|
|
||||||
if err != nil {
|
|
||||||
errc <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logger.Log("addr", ":9000")
|
|
||||||
errc <- s.Serve(ln)
|
|
||||||
}()
|
|
||||||
|
|
||||||
logger.Log("exit", <-errc)
|
|
||||||
}
|
|
@@ -1,45 +0,0 @@
|
|||||||
package session_clientgrpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
|
|
||||||
jwt "github.com/go-kit/kit/auth/jwt"
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
"github.com/go-kit/kit/log"
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
func New(conn *grpc.ClientConn, logger log.Logger) pb.SessionServiceServer {
|
|
||||||
|
|
||||||
var loginEndpoint endpoint.Endpoint
|
|
||||||
{
|
|
||||||
loginEndpoint = grpctransport.NewClient(
|
|
||||||
conn,
|
|
||||||
"session.SessionService",
|
|
||||||
"Login",
|
|
||||||
EncodeLoginRequest,
|
|
||||||
DecodeLoginResponse,
|
|
||||||
pb.LoginResponse{},
|
|
||||||
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
|
||||||
).Endpoint()
|
|
||||||
}
|
|
||||||
|
|
||||||
return &endpoints.Endpoints{
|
|
||||||
|
|
||||||
LoginEndpoint: loginEndpoint,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func EncodeLoginRequest(_ context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.LoginRequest)
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeLoginResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
|
||||||
response := grpcResponse.(*pb.LoginResponse)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
@@ -1,46 +0,0 @@
|
|||||||
package session_endpoints
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = endpoint.Chain
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = context.Background
|
|
||||||
|
|
||||||
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
|
||||||
|
|
||||||
type Endpoints struct {
|
|
||||||
LoginEndpoint endpoint.Endpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Endpoints) Login(ctx oldcontext.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) {
|
|
||||||
out, err := e.LoginEndpoint(ctx, in)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.LoginResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return out.(*pb.LoginResponse), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeLoginEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint {
|
|
||||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.LoginRequest)
|
|
||||||
rep, err := svc.Login(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.LoginResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return rep, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeEndpoints(svc pb.SessionServiceServer) Endpoints {
|
|
||||||
return Endpoints{
|
|
||||||
|
|
||||||
LoginEndpoint: MakeLoginEndpoint(svc),
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,178 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: services/session/session.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package session is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
services/session/session.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
LoginRequest
|
|
||||||
LoginResponse
|
|
||||||
*/
|
|
||||||
package session
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type LoginRequest struct {
|
|
||||||
Username string `protobuf:"bytes,1,opt,name=username" json:"username,omitempty"`
|
|
||||||
Password string `protobuf:"bytes,2,opt,name=password" json:"password,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *LoginRequest) Reset() { *m = LoginRequest{} }
|
|
||||||
func (m *LoginRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*LoginRequest) ProtoMessage() {}
|
|
||||||
func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *LoginRequest) GetUsername() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Username
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *LoginRequest) GetPassword() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Password
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type LoginResponse struct {
|
|
||||||
Token string `protobuf:"bytes,1,opt,name=token" json:"token,omitempty"`
|
|
||||||
ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *LoginResponse) Reset() { *m = LoginResponse{} }
|
|
||||||
func (m *LoginResponse) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*LoginResponse) ProtoMessage() {}
|
|
||||||
func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
|
|
||||||
func (m *LoginResponse) GetToken() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Token
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *LoginResponse) GetErrMsg() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.ErrMsg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest")
|
|
||||||
proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for SessionService service
|
|
||||||
|
|
||||||
type SessionServiceClient interface {
|
|
||||||
Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type sessionServiceClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSessionServiceClient(cc *grpc.ClientConn) SessionServiceClient {
|
|
||||||
return &sessionServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *sessionServiceClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) {
|
|
||||||
out := new(LoginResponse)
|
|
||||||
err := grpc.Invoke(ctx, "/session.SessionService/Login", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for SessionService service
|
|
||||||
|
|
||||||
type SessionServiceServer interface {
|
|
||||||
Login(context.Context, *LoginRequest) (*LoginResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterSessionServiceServer(s *grpc.Server, srv SessionServiceServer) {
|
|
||||||
s.RegisterService(&_SessionService_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _SessionService_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(LoginRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(SessionServiceServer).Login(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/session.SessionService/Login",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(SessionServiceServer).Login(ctx, req.(*LoginRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _SessionService_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "session.SessionService",
|
|
||||||
HandlerType: (*SessionServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "Login",
|
|
||||||
Handler: _SessionService_Login_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "services/session/session.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("services/session/session.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 188 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0x4e, 0x2d, 0x2a,
|
|
||||||
0xcb, 0x4c, 0x4e, 0x2d, 0xd6, 0x2f, 0x4e, 0x2d, 0x2e, 0xce, 0xcc, 0xcf, 0x83, 0xd1, 0x7a, 0x05,
|
|
||||||
0x45, 0xf9, 0x25, 0xf9, 0x42, 0xec, 0x50, 0xae, 0x92, 0x1b, 0x17, 0x8f, 0x4f, 0x7e, 0x7a, 0x66,
|
|
||||||
0x5e, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, 0x89, 0x90, 0x14, 0x17, 0x47, 0x69, 0x71, 0x6a, 0x51,
|
|
||||||
0x5e, 0x62, 0x6e, 0xaa, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x9c, 0x0f, 0x92, 0x2b, 0x48,
|
|
||||||
0x2c, 0x2e, 0x2e, 0xcf, 0x2f, 0x4a, 0x91, 0x60, 0x82, 0xc8, 0xc1, 0xf8, 0x4a, 0x76, 0x5c, 0xbc,
|
|
||||||
0x50, 0x73, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0x44, 0xb8, 0x58, 0x4b, 0xf2, 0xb3, 0x53,
|
|
||||||
0xf3, 0xa0, 0xa6, 0x40, 0x38, 0x42, 0xe2, 0x5c, 0xec, 0xa9, 0x45, 0x45, 0xf1, 0xb9, 0xc5, 0xe9,
|
|
||||||
0x50, 0x13, 0xd8, 0x52, 0x8b, 0x8a, 0x7c, 0x8b, 0xd3, 0x8d, 0xbc, 0xb8, 0xf8, 0x82, 0x21, 0x4e,
|
|
||||||
0x0a, 0x86, 0xb8, 0x5c, 0xc8, 0x82, 0x8b, 0x15, 0x6c, 0xa2, 0x90, 0xa8, 0x1e, 0xcc, 0xed, 0xc8,
|
|
||||||
0x2e, 0x95, 0x12, 0x43, 0x17, 0x86, 0x58, 0xac, 0xc4, 0x90, 0xc4, 0x06, 0xf6, 0xa3, 0x31, 0x20,
|
|
||||||
0x00, 0x00, 0xff, 0xff, 0x29, 0x3f, 0x91, 0xc7, 0x05, 0x01, 0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,65 +0,0 @@
|
|||||||
package session_grpctransport
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
// avoid import errors
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
|
|
||||||
func MakeGRPCServer(endpoints endpoints.Endpoints) pb.SessionServiceServer {
|
|
||||||
var options []grpctransport.ServerOption
|
|
||||||
_ = options
|
|
||||||
return &grpcServer{
|
|
||||||
|
|
||||||
login: grpctransport.NewServer(
|
|
||||||
endpoints.LoginEndpoint,
|
|
||||||
decodeRequest,
|
|
||||||
encodeLoginResponse,
|
|
||||||
options...,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type grpcServer struct {
|
|
||||||
login grpctransport.Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *grpcServer) Login(ctx oldcontext.Context, req *pb.LoginRequest) (*pb.LoginResponse, error) {
|
|
||||||
_, rep, err := s.login.ServeGRPC(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rep.(*pb.LoginResponse), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeLoginResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
|
||||||
resp := response.(*pb.LoginResponse)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamHandler interface {
|
|
||||||
Do(server interface{}, req interface{}) (err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type server struct {
|
|
||||||
e endpoints.StreamEndpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s server) Do(server interface{}, req interface{}) (err error) {
|
|
||||||
if err := s.e(server, req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,46 +0,0 @@
|
|||||||
package session_httptransport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
gokit_endpoint "github.com/go-kit/kit/endpoint"
|
|
||||||
httptransport "github.com/go-kit/kit/transport/http"
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = log.Printf
|
|
||||||
var _ = gokit_endpoint.Chain
|
|
||||||
var _ = httptransport.NewClient
|
|
||||||
|
|
||||||
func MakeLoginHandler(svc pb.SessionServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
endpoint,
|
|
||||||
decodeLoginRequest,
|
|
||||||
encodeResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeLoginRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
||||||
var req pb.LoginRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
|
||||||
return json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterHandlers(svc pb.SessionServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error {
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/Login\" (service=Session)")
|
|
||||||
mux.Handle("/Login", MakeLoginHandler(svc, endpoints.LoginEndpoint))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,19 +0,0 @@
|
|||||||
package sessionsvc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct{}
|
|
||||||
|
|
||||||
func New() pb.SessionServiceServer {
|
|
||||||
return &Service{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) {
|
|
||||||
return nil, fmt.Errorf("not implemented")
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package session;
|
|
||||||
|
|
||||||
service SessionService {
|
|
||||||
rpc Login(LoginRequest) returns (LoginResponse) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
message LoginRequest {
|
|
||||||
string username = 1;
|
|
||||||
string password = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message LoginResponse {
|
|
||||||
string token = 1;
|
|
||||||
string err_msg = 2;
|
|
||||||
}
|
|
@@ -1,95 +0,0 @@
|
|||||||
package sprint_clientgrpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
|
|
||||||
jwt "github.com/go-kit/kit/auth/jwt"
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
"github.com/go-kit/kit/log"
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
func New(conn *grpc.ClientConn, logger log.Logger) pb.SprintServiceServer {
|
|
||||||
|
|
||||||
var addsprintEndpoint endpoint.Endpoint
|
|
||||||
{
|
|
||||||
addsprintEndpoint = grpctransport.NewClient(
|
|
||||||
conn,
|
|
||||||
"sprint.SprintService",
|
|
||||||
"AddSprint",
|
|
||||||
EncodeAddSprintRequest,
|
|
||||||
DecodeAddSprintResponse,
|
|
||||||
pb.AddSprintResponse{},
|
|
||||||
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
|
||||||
).Endpoint()
|
|
||||||
}
|
|
||||||
|
|
||||||
var closesprintEndpoint endpoint.Endpoint
|
|
||||||
{
|
|
||||||
closesprintEndpoint = grpctransport.NewClient(
|
|
||||||
conn,
|
|
||||||
"sprint.SprintService",
|
|
||||||
"CloseSprint",
|
|
||||||
EncodeCloseSprintRequest,
|
|
||||||
DecodeCloseSprintResponse,
|
|
||||||
pb.CloseSprintResponse{},
|
|
||||||
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
|
||||||
).Endpoint()
|
|
||||||
}
|
|
||||||
|
|
||||||
var getsprintEndpoint endpoint.Endpoint
|
|
||||||
{
|
|
||||||
getsprintEndpoint = grpctransport.NewClient(
|
|
||||||
conn,
|
|
||||||
"sprint.SprintService",
|
|
||||||
"GetSprint",
|
|
||||||
EncodeGetSprintRequest,
|
|
||||||
DecodeGetSprintResponse,
|
|
||||||
pb.GetSprintResponse{},
|
|
||||||
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
|
||||||
).Endpoint()
|
|
||||||
}
|
|
||||||
|
|
||||||
return &endpoints.Endpoints{
|
|
||||||
|
|
||||||
AddSprintEndpoint: addsprintEndpoint,
|
|
||||||
|
|
||||||
CloseSprintEndpoint: closesprintEndpoint,
|
|
||||||
|
|
||||||
GetSprintEndpoint: getsprintEndpoint,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func EncodeAddSprintRequest(_ context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.AddSprintRequest)
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeAddSprintResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
|
||||||
response := grpcResponse.(*pb.AddSprintResponse)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func EncodeCloseSprintRequest(_ context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.CloseSprintRequest)
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeCloseSprintResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
|
||||||
response := grpcResponse.(*pb.CloseSprintResponse)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func EncodeGetSprintRequest(_ context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.GetSprintRequest)
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeGetSprintResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
|
||||||
response := grpcResponse.(*pb.GetSprintResponse)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
@@ -1,92 +0,0 @@
|
|||||||
package sprint_endpoints
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb"
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = endpoint.Chain
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = context.Background
|
|
||||||
|
|
||||||
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
|
||||||
|
|
||||||
type Endpoints struct {
|
|
||||||
AddSprintEndpoint endpoint.Endpoint
|
|
||||||
|
|
||||||
CloseSprintEndpoint endpoint.Endpoint
|
|
||||||
|
|
||||||
GetSprintEndpoint endpoint.Endpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Endpoints) AddSprint(ctx oldcontext.Context, in *pb.AddSprintRequest) (*pb.AddSprintResponse, error) {
|
|
||||||
out, err := e.AddSprintEndpoint(ctx, in)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.AddSprintResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return out.(*pb.AddSprintResponse), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Endpoints) CloseSprint(ctx oldcontext.Context, in *pb.CloseSprintRequest) (*pb.CloseSprintResponse, error) {
|
|
||||||
out, err := e.CloseSprintEndpoint(ctx, in)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.CloseSprintResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return out.(*pb.CloseSprintResponse), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Endpoints) GetSprint(ctx oldcontext.Context, in *pb.GetSprintRequest) (*pb.GetSprintResponse, error) {
|
|
||||||
out, err := e.GetSprintEndpoint(ctx, in)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.GetSprintResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return out.(*pb.GetSprintResponse), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeAddSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint {
|
|
||||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.AddSprintRequest)
|
|
||||||
rep, err := svc.AddSprint(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.AddSprintResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return rep, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeCloseSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint {
|
|
||||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.CloseSprintRequest)
|
|
||||||
rep, err := svc.CloseSprint(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.CloseSprintResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return rep, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeGetSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint {
|
|
||||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.GetSprintRequest)
|
|
||||||
rep, err := svc.GetSprint(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.GetSprintResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return rep, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeEndpoints(svc pb.SprintServiceServer) Endpoints {
|
|
||||||
return Endpoints{
|
|
||||||
|
|
||||||
AddSprintEndpoint: MakeAddSprintEndpoint(svc),
|
|
||||||
|
|
||||||
CloseSprintEndpoint: MakeCloseSprintEndpoint(svc),
|
|
||||||
|
|
||||||
GetSprintEndpoint: MakeGetSprintEndpoint(svc),
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,357 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: services/sprint/sprint.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package sprint is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
services/sprint/sprint.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
AddSprintRequest
|
|
||||||
AddSprintResponse
|
|
||||||
CloseSprintRequest
|
|
||||||
CloseSprintResponse
|
|
||||||
GetSprintRequest
|
|
||||||
GetSprintResponse
|
|
||||||
Sprint
|
|
||||||
*/
|
|
||||||
package sprint
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type AddSprintRequest struct {
|
|
||||||
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *AddSprintRequest) Reset() { *m = AddSprintRequest{} }
|
|
||||||
func (m *AddSprintRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*AddSprintRequest) ProtoMessage() {}
|
|
||||||
func (*AddSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *AddSprintRequest) GetName() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddSprintResponse struct {
|
|
||||||
Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"`
|
|
||||||
ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *AddSprintResponse) Reset() { *m = AddSprintResponse{} }
|
|
||||||
func (m *AddSprintResponse) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*AddSprintResponse) ProtoMessage() {}
|
|
||||||
func (*AddSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
|
|
||||||
func (m *AddSprintResponse) GetSprint() *Sprint {
|
|
||||||
if m != nil {
|
|
||||||
return m.Sprint
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *AddSprintResponse) GetErrMsg() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.ErrMsg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type CloseSprintRequest struct {
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *CloseSprintRequest) Reset() { *m = CloseSprintRequest{} }
|
|
||||||
func (m *CloseSprintRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*CloseSprintRequest) ProtoMessage() {}
|
|
||||||
func (*CloseSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
|
||||||
|
|
||||||
func (m *CloseSprintRequest) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type CloseSprintResponse struct {
|
|
||||||
ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *CloseSprintResponse) Reset() { *m = CloseSprintResponse{} }
|
|
||||||
func (m *CloseSprintResponse) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*CloseSprintResponse) ProtoMessage() {}
|
|
||||||
func (*CloseSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
|
||||||
|
|
||||||
func (m *CloseSprintResponse) GetErrMsg() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.ErrMsg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetSprintRequest struct {
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetSprintRequest) Reset() { *m = GetSprintRequest{} }
|
|
||||||
func (m *GetSprintRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*GetSprintRequest) ProtoMessage() {}
|
|
||||||
func (*GetSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
|
||||||
|
|
||||||
func (m *GetSprintRequest) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetSprintResponse struct {
|
|
||||||
Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"`
|
|
||||||
ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetSprintResponse) Reset() { *m = GetSprintResponse{} }
|
|
||||||
func (m *GetSprintResponse) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*GetSprintResponse) ProtoMessage() {}
|
|
||||||
func (*GetSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
|
||||||
|
|
||||||
func (m *GetSprintResponse) GetSprint() *Sprint {
|
|
||||||
if m != nil {
|
|
||||||
return m.Sprint
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetSprintResponse) GetErrMsg() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.ErrMsg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type Sprint struct {
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
CreatedAt uint32 `protobuf:"varint,2,opt,name=created_at,json=createdAt" json:"created_at,omitempty"`
|
|
||||||
Name string `protobuf:"bytes,3,opt,name=name" json:"name,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Sprint) Reset() { *m = Sprint{} }
|
|
||||||
func (m *Sprint) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*Sprint) ProtoMessage() {}
|
|
||||||
func (*Sprint) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
|
||||||
|
|
||||||
func (m *Sprint) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Sprint) GetCreatedAt() uint32 {
|
|
||||||
if m != nil {
|
|
||||||
return m.CreatedAt
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Sprint) GetName() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*AddSprintRequest)(nil), "sprint.AddSprintRequest")
|
|
||||||
proto.RegisterType((*AddSprintResponse)(nil), "sprint.AddSprintResponse")
|
|
||||||
proto.RegisterType((*CloseSprintRequest)(nil), "sprint.CloseSprintRequest")
|
|
||||||
proto.RegisterType((*CloseSprintResponse)(nil), "sprint.CloseSprintResponse")
|
|
||||||
proto.RegisterType((*GetSprintRequest)(nil), "sprint.GetSprintRequest")
|
|
||||||
proto.RegisterType((*GetSprintResponse)(nil), "sprint.GetSprintResponse")
|
|
||||||
proto.RegisterType((*Sprint)(nil), "sprint.Sprint")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for SprintService service
|
|
||||||
|
|
||||||
type SprintServiceClient interface {
|
|
||||||
AddSprint(ctx context.Context, in *AddSprintRequest, opts ...grpc.CallOption) (*AddSprintResponse, error)
|
|
||||||
CloseSprint(ctx context.Context, in *CloseSprintRequest, opts ...grpc.CallOption) (*CloseSprintResponse, error)
|
|
||||||
GetSprint(ctx context.Context, in *GetSprintRequest, opts ...grpc.CallOption) (*GetSprintResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type sprintServiceClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSprintServiceClient(cc *grpc.ClientConn) SprintServiceClient {
|
|
||||||
return &sprintServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *sprintServiceClient) AddSprint(ctx context.Context, in *AddSprintRequest, opts ...grpc.CallOption) (*AddSprintResponse, error) {
|
|
||||||
out := new(AddSprintResponse)
|
|
||||||
err := grpc.Invoke(ctx, "/sprint.SprintService/AddSprint", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *sprintServiceClient) CloseSprint(ctx context.Context, in *CloseSprintRequest, opts ...grpc.CallOption) (*CloseSprintResponse, error) {
|
|
||||||
out := new(CloseSprintResponse)
|
|
||||||
err := grpc.Invoke(ctx, "/sprint.SprintService/CloseSprint", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *sprintServiceClient) GetSprint(ctx context.Context, in *GetSprintRequest, opts ...grpc.CallOption) (*GetSprintResponse, error) {
|
|
||||||
out := new(GetSprintResponse)
|
|
||||||
err := grpc.Invoke(ctx, "/sprint.SprintService/GetSprint", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for SprintService service
|
|
||||||
|
|
||||||
type SprintServiceServer interface {
|
|
||||||
AddSprint(context.Context, *AddSprintRequest) (*AddSprintResponse, error)
|
|
||||||
CloseSprint(context.Context, *CloseSprintRequest) (*CloseSprintResponse, error)
|
|
||||||
GetSprint(context.Context, *GetSprintRequest) (*GetSprintResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterSprintServiceServer(s *grpc.Server, srv SprintServiceServer) {
|
|
||||||
s.RegisterService(&_SprintService_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _SprintService_AddSprint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(AddSprintRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(SprintServiceServer).AddSprint(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/sprint.SprintService/AddSprint",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(SprintServiceServer).AddSprint(ctx, req.(*AddSprintRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _SprintService_CloseSprint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(CloseSprintRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(SprintServiceServer).CloseSprint(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/sprint.SprintService/CloseSprint",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(SprintServiceServer).CloseSprint(ctx, req.(*CloseSprintRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _SprintService_GetSprint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(GetSprintRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(SprintServiceServer).GetSprint(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/sprint.SprintService/GetSprint",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(SprintServiceServer).GetSprint(ctx, req.(*GetSprintRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _SprintService_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "sprint.SprintService",
|
|
||||||
HandlerType: (*SprintServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "AddSprint",
|
|
||||||
Handler: _SprintService_AddSprint_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "CloseSprint",
|
|
||||||
Handler: _SprintService_CloseSprint_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "GetSprint",
|
|
||||||
Handler: _SprintService_GetSprint_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "services/sprint/sprint.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("services/sprint/sprint.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 290 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x52, 0x4d, 0x4b, 0xc3, 0x40,
|
|
||||||
0x10, 0x6d, 0xaa, 0x44, 0x32, 0xa5, 0xa5, 0x1d, 0x0f, 0xc6, 0xa8, 0x20, 0x8b, 0x14, 0x4f, 0x11,
|
|
||||||
0xea, 0x2f, 0x68, 0x3d, 0x28, 0x88, 0x97, 0xb4, 0xf7, 0x12, 0xbb, 0x43, 0x09, 0xd8, 0x24, 0xee,
|
|
||||||
0xac, 0xfe, 0x5f, 0xff, 0x89, 0xb0, 0xbb, 0xcd, 0x57, 0x8b, 0x27, 0x4f, 0xc9, 0xec, 0xbc, 0x7d,
|
|
||||||
0x6f, 0xe6, 0xbd, 0x85, 0x6b, 0x26, 0xf5, 0x9d, 0x6d, 0x88, 0x1f, 0xb8, 0x54, 0x59, 0xae, 0xdd,
|
|
||||||
0x27, 0x2e, 0x55, 0xa1, 0x0b, 0xf4, 0x6d, 0x25, 0xa6, 0x30, 0x9e, 0x4b, 0xb9, 0x34, 0x45, 0x42,
|
|
||||||
0x9f, 0x5f, 0xc4, 0x1a, 0x11, 0x4e, 0xf3, 0x74, 0x47, 0xa1, 0x77, 0xeb, 0xdd, 0x07, 0x89, 0xf9,
|
|
||||||
0x17, 0x2b, 0x98, 0x34, 0x70, 0x5c, 0x16, 0x39, 0x13, 0x4e, 0xc1, 0xd1, 0x18, 0xe8, 0x60, 0x36,
|
|
||||||
0x8a, 0x9d, 0x86, 0xc3, 0xb9, 0x2e, 0x5e, 0xc0, 0x19, 0x29, 0xb5, 0xde, 0xf1, 0x36, 0xec, 0x1b,
|
|
||||||
0x4e, 0x9f, 0x94, 0x7a, 0xe3, 0xad, 0xb8, 0x03, 0x7c, 0xfa, 0x28, 0x98, 0xda, 0xfa, 0x23, 0xe8,
|
|
||||||
0x67, 0xd2, 0xa9, 0xf7, 0x33, 0x29, 0x62, 0x38, 0x6f, 0xa1, 0x9c, 0x7a, 0x83, 0xd5, 0x6b, 0xb1,
|
|
||||||
0x0a, 0x18, 0x3f, 0x93, 0xfe, 0x9b, 0x73, 0x05, 0x93, 0x06, 0xe6, 0xbf, 0xf6, 0x79, 0x05, 0xdf,
|
|
||||||
0x42, 0xbb, 0x7a, 0x78, 0x03, 0xb0, 0x51, 0x94, 0x6a, 0x92, 0xeb, 0x54, 0x9b, 0x5b, 0xc3, 0x24,
|
|
||||||
0x70, 0x27, 0xf3, 0xda, 0xf2, 0x93, 0xda, 0xf2, 0xd9, 0x8f, 0x07, 0x43, 0xcb, 0xb6, 0xb4, 0x49,
|
|
||||||
0xe2, 0x02, 0x82, 0x2a, 0x04, 0x0c, 0xf7, 0xc3, 0x75, 0xf3, 0x8b, 0x2e, 0x8f, 0x74, 0xec, 0x86,
|
|
||||||
0xa2, 0x87, 0x2f, 0x30, 0x68, 0x98, 0x89, 0xd1, 0x1e, 0x7b, 0x98, 0x43, 0x74, 0x75, 0xb4, 0x57,
|
|
||||||
0x31, 0x2d, 0x20, 0xa8, 0x2c, 0xac, 0xa7, 0xe9, 0x3a, 0x5f, 0x4f, 0x73, 0xe0, 0xb7, 0xe8, 0xbd,
|
|
||||||
0xfb, 0xe6, 0x35, 0x3e, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x9e, 0xb2, 0x1e, 0xad, 0x02,
|
|
||||||
0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,109 +0,0 @@
|
|||||||
package sprint_grpctransport
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
// avoid import errors
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
|
|
||||||
func MakeGRPCServer(endpoints endpoints.Endpoints) pb.SprintServiceServer {
|
|
||||||
var options []grpctransport.ServerOption
|
|
||||||
_ = options
|
|
||||||
return &grpcServer{
|
|
||||||
|
|
||||||
addsprint: grpctransport.NewServer(
|
|
||||||
endpoints.AddSprintEndpoint,
|
|
||||||
decodeRequest,
|
|
||||||
encodeAddSprintResponse,
|
|
||||||
options...,
|
|
||||||
),
|
|
||||||
|
|
||||||
closesprint: grpctransport.NewServer(
|
|
||||||
endpoints.CloseSprintEndpoint,
|
|
||||||
decodeRequest,
|
|
||||||
encodeCloseSprintResponse,
|
|
||||||
options...,
|
|
||||||
),
|
|
||||||
|
|
||||||
getsprint: grpctransport.NewServer(
|
|
||||||
endpoints.GetSprintEndpoint,
|
|
||||||
decodeRequest,
|
|
||||||
encodeGetSprintResponse,
|
|
||||||
options...,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type grpcServer struct {
|
|
||||||
addsprint grpctransport.Handler
|
|
||||||
|
|
||||||
closesprint grpctransport.Handler
|
|
||||||
|
|
||||||
getsprint grpctransport.Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *grpcServer) AddSprint(ctx oldcontext.Context, req *pb.AddSprintRequest) (*pb.AddSprintResponse, error) {
|
|
||||||
_, rep, err := s.addsprint.ServeGRPC(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rep.(*pb.AddSprintResponse), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeAddSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
|
||||||
resp := response.(*pb.AddSprintResponse)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *grpcServer) CloseSprint(ctx oldcontext.Context, req *pb.CloseSprintRequest) (*pb.CloseSprintResponse, error) {
|
|
||||||
_, rep, err := s.closesprint.ServeGRPC(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rep.(*pb.CloseSprintResponse), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeCloseSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
|
||||||
resp := response.(*pb.CloseSprintResponse)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *grpcServer) GetSprint(ctx oldcontext.Context, req *pb.GetSprintRequest) (*pb.GetSprintResponse, error) {
|
|
||||||
_, rep, err := s.getsprint.ServeGRPC(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rep.(*pb.GetSprintResponse), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeGetSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
|
||||||
resp := response.(*pb.GetSprintResponse)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamHandler interface {
|
|
||||||
Do(server interface{}, req interface{}) (err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type server struct {
|
|
||||||
e endpoints.StreamEndpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s server) Do(server interface{}, req interface{}) (err error) {
|
|
||||||
if err := s.e(server, req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,86 +0,0 @@
|
|||||||
package sprint_httptransport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
gokit_endpoint "github.com/go-kit/kit/endpoint"
|
|
||||||
httptransport "github.com/go-kit/kit/transport/http"
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = log.Printf
|
|
||||||
var _ = gokit_endpoint.Chain
|
|
||||||
var _ = httptransport.NewClient
|
|
||||||
|
|
||||||
func MakeAddSprintHandler(svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
endpoint,
|
|
||||||
decodeAddSprintRequest,
|
|
||||||
encodeResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeAddSprintRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
||||||
var req pb.AddSprintRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeCloseSprintHandler(svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
endpoint,
|
|
||||||
decodeCloseSprintRequest,
|
|
||||||
encodeResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeCloseSprintRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
||||||
var req pb.CloseSprintRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeGetSprintHandler(svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
endpoint,
|
|
||||||
decodeGetSprintRequest,
|
|
||||||
encodeResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeGetSprintRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
||||||
var req pb.GetSprintRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
|
||||||
return json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterHandlers(svc pb.SprintServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error {
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/AddSprint\" (service=Sprint)")
|
|
||||||
mux.Handle("/AddSprint", MakeAddSprintHandler(svc, endpoints.AddSprintEndpoint))
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/CloseSprint\" (service=Sprint)")
|
|
||||||
mux.Handle("/CloseSprint", MakeCloseSprintHandler(svc, endpoints.CloseSprintEndpoint))
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/GetSprint\" (service=Sprint)")
|
|
||||||
mux.Handle("/GetSprint", MakeGetSprintHandler(svc, endpoints.GetSprintEndpoint))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
package sprintsvc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct{}
|
|
||||||
|
|
||||||
func New() pb.SprintServiceServer {
|
|
||||||
return &Service{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) AddSprint(ctx context.Context, in *pb.AddSprintRequest) (*pb.AddSprintResponse, error) {
|
|
||||||
return nil, fmt.Errorf("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) CloseSprint(ctx context.Context, in *pb.CloseSprintRequest) (*pb.CloseSprintResponse, error) {
|
|
||||||
return nil, fmt.Errorf("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) GetSprint(ctx context.Context, in *pb.GetSprintRequest) (*pb.GetSprintResponse, error) {
|
|
||||||
return nil, fmt.Errorf("not implemented")
|
|
||||||
}
|
|
@@ -1,38 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package sprint;
|
|
||||||
|
|
||||||
service SprintService {
|
|
||||||
rpc AddSprint(AddSprintRequest) returns (AddSprintResponse) {}
|
|
||||||
rpc CloseSprint(CloseSprintRequest) returns (CloseSprintResponse) {}
|
|
||||||
rpc GetSprint(GetSprintRequest) returns (GetSprintResponse) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
message AddSprintRequest {
|
|
||||||
string name = 1;
|
|
||||||
}
|
|
||||||
message AddSprintResponse {
|
|
||||||
Sprint sprint = 1;
|
|
||||||
string err_msg = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CloseSprintRequest {
|
|
||||||
string id = 1;
|
|
||||||
}
|
|
||||||
message CloseSprintResponse {
|
|
||||||
string err_msg = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetSprintRequest {
|
|
||||||
string id = 1;
|
|
||||||
}
|
|
||||||
message GetSprintResponse {
|
|
||||||
Sprint sprint = 1;
|
|
||||||
string err_msg = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Sprint {
|
|
||||||
string id = 1;
|
|
||||||
uint32 created_at = 2;
|
|
||||||
string name = 3;
|
|
||||||
}
|
|
@@ -1,70 +0,0 @@
|
|||||||
package user_clientgrpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
|
|
||||||
jwt "github.com/go-kit/kit/auth/jwt"
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
"github.com/go-kit/kit/log"
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
func New(conn *grpc.ClientConn, logger log.Logger) pb.UserServiceServer {
|
|
||||||
|
|
||||||
var createuserEndpoint endpoint.Endpoint
|
|
||||||
{
|
|
||||||
createuserEndpoint = grpctransport.NewClient(
|
|
||||||
conn,
|
|
||||||
"user.UserService",
|
|
||||||
"CreateUser",
|
|
||||||
EncodeCreateUserRequest,
|
|
||||||
DecodeCreateUserResponse,
|
|
||||||
pb.CreateUserResponse{},
|
|
||||||
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
|
||||||
).Endpoint()
|
|
||||||
}
|
|
||||||
|
|
||||||
var getuserEndpoint endpoint.Endpoint
|
|
||||||
{
|
|
||||||
getuserEndpoint = grpctransport.NewClient(
|
|
||||||
conn,
|
|
||||||
"user.UserService",
|
|
||||||
"GetUser",
|
|
||||||
EncodeGetUserRequest,
|
|
||||||
DecodeGetUserResponse,
|
|
||||||
pb.GetUserResponse{},
|
|
||||||
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
|
||||||
).Endpoint()
|
|
||||||
}
|
|
||||||
|
|
||||||
return &endpoints.Endpoints{
|
|
||||||
|
|
||||||
CreateUserEndpoint: createuserEndpoint,
|
|
||||||
|
|
||||||
GetUserEndpoint: getuserEndpoint,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func EncodeCreateUserRequest(_ context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.CreateUserRequest)
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeCreateUserResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
|
||||||
response := grpcResponse.(*pb.CreateUserResponse)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func EncodeGetUserRequest(_ context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.GetUserRequest)
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeGetUserResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
|
||||||
response := grpcResponse.(*pb.GetUserResponse)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
@@ -1,69 +0,0 @@
|
|||||||
package user_endpoints
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = endpoint.Chain
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = context.Background
|
|
||||||
|
|
||||||
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
|
||||||
|
|
||||||
type Endpoints struct {
|
|
||||||
CreateUserEndpoint endpoint.Endpoint
|
|
||||||
|
|
||||||
GetUserEndpoint endpoint.Endpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Endpoints) CreateUser(ctx oldcontext.Context, in *pb.CreateUserRequest) (*pb.CreateUserResponse, error) {
|
|
||||||
out, err := e.CreateUserEndpoint(ctx, in)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.CreateUserResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return out.(*pb.CreateUserResponse), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Endpoints) GetUser(ctx oldcontext.Context, in *pb.GetUserRequest) (*pb.GetUserResponse, error) {
|
|
||||||
out, err := e.GetUserEndpoint(ctx, in)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.GetUserResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return out.(*pb.GetUserResponse), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeCreateUserEndpoint(svc pb.UserServiceServer) endpoint.Endpoint {
|
|
||||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.CreateUserRequest)
|
|
||||||
rep, err := svc.CreateUser(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.CreateUserResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return rep, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeGetUserEndpoint(svc pb.UserServiceServer) endpoint.Endpoint {
|
|
||||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.GetUserRequest)
|
|
||||||
rep, err := svc.GetUser(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.GetUserResponse{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return rep, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeEndpoints(svc pb.UserServiceServer) Endpoints {
|
|
||||||
return Endpoints{
|
|
||||||
|
|
||||||
CreateUserEndpoint: MakeCreateUserEndpoint(svc),
|
|
||||||
|
|
||||||
GetUserEndpoint: MakeGetUserEndpoint(svc),
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,276 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: services/user/user.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package user is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
services/user/user.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
CreateUserRequest
|
|
||||||
CreateUserResponse
|
|
||||||
GetUserRequest
|
|
||||||
GetUserResponse
|
|
||||||
User
|
|
||||||
*/
|
|
||||||
package user
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type CreateUserRequest struct {
|
|
||||||
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *CreateUserRequest) Reset() { *m = CreateUserRequest{} }
|
|
||||||
func (m *CreateUserRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*CreateUserRequest) ProtoMessage() {}
|
|
||||||
func (*CreateUserRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *CreateUserRequest) GetName() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateUserResponse struct {
|
|
||||||
User *User `protobuf:"bytes,1,opt,name=user" json:"user,omitempty"`
|
|
||||||
ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *CreateUserResponse) Reset() { *m = CreateUserResponse{} }
|
|
||||||
func (m *CreateUserResponse) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*CreateUserResponse) ProtoMessage() {}
|
|
||||||
func (*CreateUserResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
|
|
||||||
func (m *CreateUserResponse) GetUser() *User {
|
|
||||||
if m != nil {
|
|
||||||
return m.User
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *CreateUserResponse) GetErrMsg() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.ErrMsg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetUserRequest struct {
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetUserRequest) Reset() { *m = GetUserRequest{} }
|
|
||||||
func (m *GetUserRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*GetUserRequest) ProtoMessage() {}
|
|
||||||
func (*GetUserRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
|
||||||
|
|
||||||
func (m *GetUserRequest) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetUserResponse struct {
|
|
||||||
User *User `protobuf:"bytes,1,opt,name=user" json:"user,omitempty"`
|
|
||||||
ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetUserResponse) Reset() { *m = GetUserResponse{} }
|
|
||||||
func (m *GetUserResponse) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*GetUserResponse) ProtoMessage() {}
|
|
||||||
func (*GetUserResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
|
||||||
|
|
||||||
func (m *GetUserResponse) GetUser() *User {
|
|
||||||
if m != nil {
|
|
||||||
return m.User
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetUserResponse) GetErrMsg() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.ErrMsg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *User) Reset() { *m = User{} }
|
|
||||||
func (m *User) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*User) ProtoMessage() {}
|
|
||||||
func (*User) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
|
||||||
|
|
||||||
func (m *User) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *User) GetName() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*CreateUserRequest)(nil), "user.CreateUserRequest")
|
|
||||||
proto.RegisterType((*CreateUserResponse)(nil), "user.CreateUserResponse")
|
|
||||||
proto.RegisterType((*GetUserRequest)(nil), "user.GetUserRequest")
|
|
||||||
proto.RegisterType((*GetUserResponse)(nil), "user.GetUserResponse")
|
|
||||||
proto.RegisterType((*User)(nil), "user.User")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for UserService service
|
|
||||||
|
|
||||||
type UserServiceClient interface {
|
|
||||||
CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error)
|
|
||||||
GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type userServiceClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewUserServiceClient(cc *grpc.ClientConn) UserServiceClient {
|
|
||||||
return &userServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *userServiceClient) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error) {
|
|
||||||
out := new(CreateUserResponse)
|
|
||||||
err := grpc.Invoke(ctx, "/user.UserService/CreateUser", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *userServiceClient) GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserResponse, error) {
|
|
||||||
out := new(GetUserResponse)
|
|
||||||
err := grpc.Invoke(ctx, "/user.UserService/GetUser", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for UserService service
|
|
||||||
|
|
||||||
type UserServiceServer interface {
|
|
||||||
CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error)
|
|
||||||
GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterUserServiceServer(s *grpc.Server, srv UserServiceServer) {
|
|
||||||
s.RegisterService(&_UserService_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _UserService_CreateUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(CreateUserRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(UserServiceServer).CreateUser(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/user.UserService/CreateUser",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(UserServiceServer).CreateUser(ctx, req.(*CreateUserRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _UserService_GetUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(GetUserRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(UserServiceServer).GetUser(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/user.UserService/GetUser",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(UserServiceServer).GetUser(ctx, req.(*GetUserRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _UserService_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "user.UserService",
|
|
||||||
HandlerType: (*UserServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "CreateUser",
|
|
||||||
Handler: _UserService_CreateUser_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "GetUser",
|
|
||||||
Handler: _UserService_GetUser_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "services/user/user.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("services/user/user.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 236 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x4e, 0x2d, 0x2a,
|
|
||||||
0xcb, 0x4c, 0x4e, 0x2d, 0xd6, 0x2f, 0x2d, 0x4e, 0x2d, 0x02, 0x13, 0x7a, 0x05, 0x45, 0xf9, 0x25,
|
|
||||||
0xf9, 0x42, 0x2c, 0x20, 0xb6, 0x92, 0x3a, 0x97, 0xa0, 0x73, 0x51, 0x6a, 0x62, 0x49, 0x6a, 0x68,
|
|
||||||
0x71, 0x6a, 0x51, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, 0x89, 0x90, 0x10, 0x17, 0x4b, 0x5e, 0x62,
|
|
||||||
0x6e, 0xaa, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x98, 0xad, 0xe4, 0xcb, 0x25, 0x84, 0xac,
|
|
||||||
0xb0, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x48, 0x8e, 0x0b, 0x6c, 0x0c, 0x58, 0x25, 0xb7, 0x11,
|
|
||||||
0x97, 0x1e, 0xd8, 0x7c, 0xb0, 0x0a, 0xb0, 0xb8, 0x90, 0x38, 0x17, 0x7b, 0x6a, 0x51, 0x51, 0x7c,
|
|
||||||
0x6e, 0x71, 0xba, 0x04, 0x13, 0xd8, 0x30, 0xb6, 0xd4, 0xa2, 0x22, 0xdf, 0xe2, 0x74, 0x25, 0x05,
|
|
||||||
0x2e, 0x3e, 0xf7, 0xd4, 0x12, 0x64, 0x4b, 0xf9, 0xb8, 0x98, 0x32, 0x53, 0xa0, 0x56, 0x32, 0x65,
|
|
||||||
0xa6, 0x28, 0x79, 0x71, 0xf1, 0xc3, 0x55, 0x50, 0x6a, 0x9b, 0x16, 0x17, 0x0b, 0x48, 0x19, 0xba,
|
|
||||||
0x1d, 0x70, 0x8f, 0x32, 0x21, 0x3c, 0x6a, 0xd4, 0xc5, 0xc8, 0xc5, 0x0d, 0x52, 0x1c, 0x0c, 0x09,
|
|
||||||
0x38, 0x21, 0x47, 0x2e, 0x2e, 0x84, 0xc7, 0x85, 0xc4, 0x21, 0x96, 0x62, 0x84, 0x99, 0x94, 0x04,
|
|
||||||
0xa6, 0x04, 0xc4, 0xd5, 0x4a, 0x0c, 0x42, 0x16, 0x5c, 0xec, 0x50, 0xaf, 0x08, 0x89, 0x40, 0x94,
|
|
||||||
0xa1, 0xfa, 0x5d, 0x4a, 0x14, 0x4d, 0x14, 0xa6, 0x33, 0x89, 0x0d, 0x1c, 0x57, 0xc6, 0x80, 0x00,
|
|
||||||
0x00, 0x00, 0xff, 0xff, 0xce, 0xde, 0xa3, 0x2e, 0xc7, 0x01, 0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,87 +0,0 @@
|
|||||||
package user_grpctransport
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
// avoid import errors
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
|
|
||||||
func MakeGRPCServer(endpoints endpoints.Endpoints) pb.UserServiceServer {
|
|
||||||
var options []grpctransport.ServerOption
|
|
||||||
_ = options
|
|
||||||
return &grpcServer{
|
|
||||||
|
|
||||||
createuser: grpctransport.NewServer(
|
|
||||||
endpoints.CreateUserEndpoint,
|
|
||||||
decodeRequest,
|
|
||||||
encodeCreateUserResponse,
|
|
||||||
options...,
|
|
||||||
),
|
|
||||||
|
|
||||||
getuser: grpctransport.NewServer(
|
|
||||||
endpoints.GetUserEndpoint,
|
|
||||||
decodeRequest,
|
|
||||||
encodeGetUserResponse,
|
|
||||||
options...,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type grpcServer struct {
|
|
||||||
createuser grpctransport.Handler
|
|
||||||
|
|
||||||
getuser grpctransport.Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *grpcServer) CreateUser(ctx oldcontext.Context, req *pb.CreateUserRequest) (*pb.CreateUserResponse, error) {
|
|
||||||
_, rep, err := s.createuser.ServeGRPC(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rep.(*pb.CreateUserResponse), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeCreateUserResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
|
||||||
resp := response.(*pb.CreateUserResponse)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *grpcServer) GetUser(ctx oldcontext.Context, req *pb.GetUserRequest) (*pb.GetUserResponse, error) {
|
|
||||||
_, rep, err := s.getuser.ServeGRPC(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rep.(*pb.GetUserResponse), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeGetUserResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
|
||||||
resp := response.(*pb.GetUserResponse)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamHandler interface {
|
|
||||||
Do(server interface{}, req interface{}) (err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type server struct {
|
|
||||||
e endpoints.StreamEndpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s server) Do(server interface{}, req interface{}) (err error) {
|
|
||||||
if err := s.e(server, req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,66 +0,0 @@
|
|||||||
package user_httptransport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
gokit_endpoint "github.com/go-kit/kit/endpoint"
|
|
||||||
httptransport "github.com/go-kit/kit/transport/http"
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = log.Printf
|
|
||||||
var _ = gokit_endpoint.Chain
|
|
||||||
var _ = httptransport.NewClient
|
|
||||||
|
|
||||||
func MakeCreateUserHandler(svc pb.UserServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
endpoint,
|
|
||||||
decodeCreateUserRequest,
|
|
||||||
encodeResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeCreateUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
||||||
var req pb.CreateUserRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeGetUserHandler(svc pb.UserServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
endpoint,
|
|
||||||
decodeGetUserRequest,
|
|
||||||
encodeResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeGetUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
||||||
var req pb.GetUserRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
|
||||||
return json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterHandlers(svc pb.UserServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error {
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/CreateUser\" (service=User)")
|
|
||||||
mux.Handle("/CreateUser", MakeCreateUserHandler(svc, endpoints.CreateUserEndpoint))
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/GetUser\" (service=User)")
|
|
||||||
mux.Handle("/GetUser", MakeGetUserHandler(svc, endpoints.GetUserEndpoint))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
package usersvc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct{}
|
|
||||||
|
|
||||||
func New() pb.UserServiceServer { return &Service{} }
|
|
||||||
|
|
||||||
func (svc *Service) CreateUser(ctx context.Context, in *pb.CreateUserRequest) (*pb.CreateUserResponse, error) {
|
|
||||||
return nil, fmt.Errorf("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) GetUser(ctx context.Context, in *pb.GetUserRequest) (*pb.GetUserResponse, error) {
|
|
||||||
return nil, fmt.Errorf("not implemented")
|
|
||||||
}
|
|
@@ -1,29 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package user;
|
|
||||||
|
|
||||||
service UserService {
|
|
||||||
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse) {}
|
|
||||||
rpc GetUser(GetUserRequest) returns (GetUserResponse) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
message CreateUserRequest {
|
|
||||||
string name = 1;
|
|
||||||
}
|
|
||||||
message CreateUserResponse {
|
|
||||||
User user = 1;
|
|
||||||
string err_msg = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetUserRequest {
|
|
||||||
string id = 1;
|
|
||||||
}
|
|
||||||
message GetUserResponse {
|
|
||||||
User user = 1;
|
|
||||||
string err_msg = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message User {
|
|
||||||
string id = 1;
|
|
||||||
string name = 2;
|
|
||||||
}
|
|
@@ -1,57 +0,0 @@
|
|||||||
package {{.File.Package}}_clientgrpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
jwt "github.com/go-kit/kit/auth/jwt"
|
|
||||||
|
|
||||||
pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb"
|
|
||||||
endpoints "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/endpoints"
|
|
||||||
)
|
|
||||||
|
|
||||||
{{$file:=.File}}
|
|
||||||
|
|
||||||
func New(conn *grpc.ClientConn, logger log.Logger) pb.{{.File.Package | title}}ServiceServer {
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if and (not .ServerStreaming) (not .ClientStreaming)}}
|
|
||||||
var {{.Name | lower}}Endpoint endpoint.Endpoint
|
|
||||||
{
|
|
||||||
{{.Name | lower}}Endpoint = grpctransport.NewClient(
|
|
||||||
conn,
|
|
||||||
"{{$file.Package}}.{{$file.Package | title}}Service",
|
|
||||||
"{{.Name}}",
|
|
||||||
Encode{{.Name}}Request,
|
|
||||||
Decode{{.Name}}Response,
|
|
||||||
pb.{{.Name}}Response{},
|
|
||||||
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
|
||||||
).Endpoint()
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
return &endpoints.Endpoints {
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if and (not .ServerStreaming) (not .ClientStreaming)}}
|
|
||||||
{{.Name | title}}Endpoint: {{.Name | lower}}Endpoint,
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if and (not .ServerStreaming) (not .ClientStreaming)}}
|
|
||||||
func Encode{{.Name}}Request(_ context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.{{.Name}}Request)
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Decode{{.Name}}Response(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
|
||||||
response := grpcResponse.(*pb.{{.Name}}Response)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
@@ -1,89 +0,0 @@
|
|||||||
package {{.File.Package}}_endpoints
|
|
||||||
|
|
||||||
{{$file := .File}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb"
|
|
||||||
"github.com/go-kit/kit/endpoint"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = endpoint.Chain
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = context.Background
|
|
||||||
|
|
||||||
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
|
||||||
|
|
||||||
type Endpoints struct {
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if or (.ClientStreaming) (.ServerStreaming)}}
|
|
||||||
{{.Name}}Endpoint StreamEndpoint
|
|
||||||
{{else}}
|
|
||||||
{{.Name}}Endpoint endpoint.Endpoint
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if .ServerStreaming}}
|
|
||||||
{{if .ClientStreaming}}
|
|
||||||
func (e *Endpoints){{.Name}}(server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
||||||
return fmt.Errorf("not implemented")
|
|
||||||
}
|
|
||||||
{{else}}
|
|
||||||
func (e *Endpoints){{.Name}}(in *pb.{{.Name}}Request, server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
||||||
return fmt.Errorf("not implemented")
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{else}}
|
|
||||||
{{if .ClientStreaming}}
|
|
||||||
func (e *Endpoints){{.Name}}(server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
||||||
return fmt.Errorf("not implemented")
|
|
||||||
}
|
|
||||||
{{else}}
|
|
||||||
func (e *Endpoints){{.Name}}(ctx oldcontext.Context, in *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
|
|
||||||
out, err := e.{{.Name}}Endpoint(ctx, in)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return out.(*pb.{{.OutputType | splitArray "." | last}}), err
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if or (.ServerStreaming) (.ClientStreaming)}}
|
|
||||||
func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) StreamEndpoint {
|
|
||||||
return func(server interface{}, request interface{}) error {
|
|
||||||
{{if .ClientStreaming}}
|
|
||||||
return svc.{{.Name}}(server.(pb.{{$file.Package | title}}Service_{{.Name}}Server))
|
|
||||||
{{else}}
|
|
||||||
return svc.{{.Name}}(request.(*pb.{{.Name}}Request), server.(pb.{{$file.Package | title}}Service_{{.Name}}Server))
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{else}}
|
|
||||||
func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoint.Endpoint {
|
|
||||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
||||||
req := request.(*pb.{{.InputType | splitArray "." | last}})
|
|
||||||
rep, err := svc.{{.Name}}(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return rep, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
func MakeEndpoints(svc pb.{{.File.Package | title}}ServiceServer) Endpoints {
|
|
||||||
return Endpoints{
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{.Name}}Endpoint: Make{{.Name}}Endpoint(svc),
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,92 +0,0 @@
|
|||||||
package {{.File.Package}}_grpctransport
|
|
||||||
|
|
||||||
{{$file := .File}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
oldcontext "golang.org/x/net/context"
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
|
||||||
|
|
||||||
pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb"
|
|
||||||
endpoints "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/endpoints"
|
|
||||||
)
|
|
||||||
|
|
||||||
// avoid import errors
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
|
|
||||||
func MakeGRPCServer(endpoints endpoints.Endpoints) pb.{{.File.Package | title}}ServiceServer {
|
|
||||||
var options []grpctransport.ServerOption
|
|
||||||
_ = options
|
|
||||||
return &grpcServer{
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if or (.ClientStreaming) (.ServerStreaming)}}
|
|
||||||
{{.Name | lower}}: &server{
|
|
||||||
e: endpoints.{{.Name}}Endpoint,
|
|
||||||
},
|
|
||||||
{{else}}
|
|
||||||
{{.Name | lower}}: grpctransport.NewServer(
|
|
||||||
endpoints.{{.Name}}Endpoint,
|
|
||||||
decodeRequest,
|
|
||||||
encode{{.Name}}Response,
|
|
||||||
options...,
|
|
||||||
),
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type grpcServer struct {
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if or (.ClientStreaming) (.ServerStreaming)}}
|
|
||||||
{{.Name | lower}} streamHandler
|
|
||||||
{{else}}
|
|
||||||
{{.Name | lower}} grpctransport.Handler
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if .ClientStreaming}}
|
|
||||||
func (s *grpcServer) {{.Name}}(server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
||||||
return s.{{.Name | lower}}.Do(server, nil)
|
|
||||||
}
|
|
||||||
{{else if .ServerStreaming}}
|
|
||||||
func (s *grpcServer) {{.Name}}(req *pb.{{.Name}}Request, server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
||||||
return s.{{.Name | lower}}.Do(server, req)
|
|
||||||
}
|
|
||||||
{{else}}
|
|
||||||
func (s *grpcServer) {{.Name}}(ctx oldcontext.Context, req *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
|
|
||||||
_, rep, err := s.{{.Name | lower}}.ServeGRPC(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rep.(*pb.{{.OutputType | splitArray "." | last}}), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encode{{.Name}}Response(ctx context.Context, response interface{}) (interface{}, error) {
|
|
||||||
resp := response.(*pb.{{.OutputType | splitArray "." | last}})
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
func decodeRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type streamHandler interface{
|
|
||||||
Do(server interface{}, req interface{}) (err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type server struct {
|
|
||||||
e endpoints.StreamEndpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s server) Do(server interface{}, req interface{}) (err error) {
|
|
||||||
if err := s.e(server, req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,55 +0,0 @@
|
|||||||
package {{.File.Package}}_httptransport
|
|
||||||
|
|
||||||
{{$file := .File}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"encoding/json"
|
|
||||||
"context"
|
|
||||||
|
|
||||||
pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb"
|
|
||||||
gokit_endpoint "github.com/go-kit/kit/endpoint"
|
|
||||||
httptransport "github.com/go-kit/kit/transport/http"
|
|
||||||
endpoints "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/endpoints"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = log.Printf
|
|
||||||
var _ = gokit_endpoint.Chain
|
|
||||||
var _ = httptransport.NewClient
|
|
||||||
|
|
||||||
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if and (not .ServerStreaming) (not .ClientStreaming)}}
|
|
||||||
func Make{{.Name}}Handler(svc pb.{{$file.Package | title}}ServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
endpoint,
|
|
||||||
decode{{.Name}}Request,
|
|
||||||
encodeResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decode{{.Name}}Request(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
||||||
var req pb.{{.InputType | splitArray "." | last}}
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &req, nil
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
|
||||||
return json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterHandlers(svc pb.{{$file.Package | title}}ServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error {
|
|
||||||
{{range .Service.Method}}
|
|
||||||
{{if and (not .ServerStreaming) (not .ClientStreaming)}}
|
|
||||||
log.Println("new HTTP endpoint: \"/{{.Name}}\" (service={{$file.Package | title}})")
|
|
||||||
mux.Handle("/{{.Name}}", Make{{.Name}}Handler(svc, endpoints.{{.Name}}Endpoint))
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
mkdir -p output
|
|
||||||
|
|
||||||
# generate pb.go inluding imported proto
|
|
||||||
protoc --go_out=Mproto/common.proto=github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common:./output proto/article.proto
|
|
||||||
protoc --go_out=,plugins=grpc:./output proto/common.proto
|
|
||||||
|
|
||||||
# build our go file based on our template
|
|
||||||
protoc -I. --gotemplate_out=template_dir=templates,debug=true:output proto/article.proto
|
|
||||||
|
|
||||||
.PHONY: re
|
|
||||||
re: clean build
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
rm -rf output
|
|
@@ -1,113 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: proto/article.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package article is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
proto/article.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
GetArticleRequest
|
|
||||||
GetArticleResponse
|
|
||||||
Article
|
|
||||||
*/
|
|
||||||
package article
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
import common "github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type GetArticleRequest struct {
|
|
||||||
Getarticle *common.GetArticle `protobuf:"bytes,1,opt,name=getarticle" json:"getarticle,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetArticleRequest) Reset() { *m = GetArticleRequest{} }
|
|
||||||
func (m *GetArticleRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*GetArticleRequest) ProtoMessage() {}
|
|
||||||
func (*GetArticleRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *GetArticleRequest) GetGetarticle() *common.GetArticle {
|
|
||||||
if m != nil {
|
|
||||||
return m.Getarticle
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetArticleResponse struct {
|
|
||||||
Article *Article `protobuf:"bytes,1,opt,name=article" json:"article,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetArticleResponse) Reset() { *m = GetArticleResponse{} }
|
|
||||||
func (m *GetArticleResponse) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*GetArticleResponse) ProtoMessage() {}
|
|
||||||
func (*GetArticleResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
|
|
||||||
func (m *GetArticleResponse) GetArticle() *Article {
|
|
||||||
if m != nil {
|
|
||||||
return m.Article
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Article struct {
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Article) Reset() { *m = Article{} }
|
|
||||||
func (m *Article) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*Article) ProtoMessage() {}
|
|
||||||
func (*Article) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
|
||||||
|
|
||||||
func (m *Article) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Article) GetName() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*GetArticleRequest)(nil), "article.GetArticleRequest")
|
|
||||||
proto.RegisterType((*GetArticleResponse)(nil), "article.GetArticleResponse")
|
|
||||||
proto.RegisterType((*Article)(nil), "article.Article")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("proto/article.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 208 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0x28, 0xca, 0x2f,
|
|
||||||
0xc9, 0xd7, 0x4f, 0x2c, 0x2a, 0xc9, 0x4c, 0xce, 0x49, 0xd5, 0x03, 0xf3, 0x84, 0xd8, 0xa1, 0x5c,
|
|
||||||
0x29, 0x21, 0x88, 0x6c, 0x72, 0x7e, 0x6e, 0x6e, 0x7e, 0x1e, 0x44, 0x52, 0xc9, 0x9d, 0x4b, 0xd0,
|
|
||||||
0x3d, 0xb5, 0xc4, 0x11, 0xa2, 0x22, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0xc8, 0x88, 0x8b,
|
|
||||||
0x2b, 0x3d, 0xb5, 0x04, 0xaa, 0x4d, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x48, 0x0f, 0xaa,
|
|
||||||
0x0f, 0x49, 0x39, 0x92, 0x2a, 0x25, 0x07, 0x2e, 0x21, 0x64, 0x83, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a,
|
|
||||||
0x53, 0x85, 0xb4, 0xb8, 0xd8, 0x51, 0x8d, 0x11, 0xd0, 0x83, 0x39, 0x0e, 0xa6, 0x14, 0xa6, 0x40,
|
|
||||||
0x49, 0x97, 0x8b, 0x1d, 0x2a, 0x26, 0xc4, 0xc7, 0xc5, 0x94, 0x99, 0x02, 0xd6, 0xc1, 0x19, 0xc4,
|
|
||||||
0x94, 0x99, 0x22, 0x24, 0xc4, 0xc5, 0x92, 0x97, 0x98, 0x9b, 0x2a, 0xc1, 0x04, 0x16, 0x01, 0xb3,
|
|
||||||
0x8d, 0x42, 0xb9, 0xb8, 0xa0, 0x3a, 0x8b, 0xcb, 0x92, 0x85, 0xdc, 0xb9, 0xb8, 0x10, 0xd6, 0x0b,
|
|
||||||
0x49, 0xc1, 0x6d, 0xc1, 0xf0, 0x9c, 0x94, 0x34, 0x56, 0x39, 0x88, 0x7b, 0x95, 0x18, 0x9c, 0x24,
|
|
||||||
0xa2, 0xc4, 0x72, 0xf3, 0x53, 0x52, 0x73, 0x8a, 0x61, 0xa1, 0x68, 0x0d, 0xa5, 0x93, 0xd8, 0xc0,
|
|
||||||
0x21, 0x66, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x16, 0x18, 0x87, 0xc4, 0x65, 0x01, 0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,70 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: proto/common.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package common is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
proto/common.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
GetArticle
|
|
||||||
*/
|
|
||||||
package common
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type GetArticle struct {
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
|
||||||
Tenant string `protobuf:"bytes,2,opt,name=tenant" json:"tenant,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetArticle) Reset() { *m = GetArticle{} }
|
|
||||||
func (m *GetArticle) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*GetArticle) ProtoMessage() {}
|
|
||||||
func (*GetArticle) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *GetArticle) GetId() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Id
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *GetArticle) GetTenant() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Tenant
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*GetArticle)(nil), "common.GetArticle")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("proto/common.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 110 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x2f,
|
|
||||||
0xc9, 0xd7, 0x4f, 0xce, 0xcf, 0xcd, 0xcd, 0xcf, 0xd3, 0x03, 0x73, 0x84, 0xd8, 0x20, 0x3c, 0x25,
|
|
||||||
0x13, 0x2e, 0x2e, 0xf7, 0xd4, 0x12, 0xc7, 0xa2, 0x92, 0xcc, 0xe4, 0x9c, 0x54, 0x21, 0x3e, 0x2e,
|
|
||||||
0xa6, 0xcc, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0xa6, 0xcc, 0x14, 0x21, 0x31, 0x2e,
|
|
||||||
0xb6, 0x92, 0xd4, 0xbc, 0xc4, 0xbc, 0x12, 0x09, 0x26, 0xb0, 0x18, 0x94, 0xe7, 0x24, 0x16, 0x25,
|
|
||||||
0x92, 0x9b, 0x9f, 0x92, 0x9a, 0x53, 0x0c, 0x35, 0xd4, 0x1a, 0x42, 0x25, 0xb1, 0x81, 0x0d, 0x37,
|
|
||||||
0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x89, 0x5a, 0x1d, 0x73, 0x72, 0x00, 0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
// Code generated by protoc-gen-gotemplate
|
|
||||||
package article
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/moul/protoc-gen-gotemplate/examples/import/output/models/article"
|
|
||||||
"github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Repository interface {
|
|
||||||
GetArticle(getarticle *common.GetArticle ) (*article.Article, error)
|
|
||||||
}
|
|
@@ -1,19 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package article;
|
|
||||||
|
|
||||||
option go_package = "models/article;article";
|
|
||||||
|
|
||||||
import "proto/common.proto";
|
|
||||||
|
|
||||||
message GetArticleRequest { common.GetArticle getarticle = 1;}
|
|
||||||
message GetArticleResponse { Article article = 1;}
|
|
||||||
|
|
||||||
message Article{
|
|
||||||
string id = 1;
|
|
||||||
string name = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
service articlesvc {
|
|
||||||
rpc GetArticle (GetArticleRequest) returns (GetArticleResponse){}
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package common;
|
|
||||||
|
|
||||||
option go_package = "models/common;common";
|
|
||||||
|
|
||||||
message GetArticle{
|
|
||||||
string id = 1;
|
|
||||||
string tenant = 2;
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
// Code generated by protoc-gen-gotemplate
|
|
||||||
package {{.File.Package}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/moul/protoc-gen-gotemplate/examples/import/output/models/article"
|
|
||||||
"github.com/moul/protoc-gen-gotemplate/examples/import/output/models/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Repository interface {
|
|
||||||
{{range $m := .Service.Method}}{{with $t := $m.InputType | getMessageType $.File}} {{$m.Name}}({{range $f := $t.Field}}{{$f.Name|lowerCamelCase}} {{$f| goTypeWithPackage }} {{end}}) ({{with $out := $m.OutputType | getMessageType $.File}}{{range $f := $out.Field}}{{$f | goTypeWithPackage}}, {{end}}{{end}} error){{end}}{{end}}
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
SOURCES := $(shell find . -name "*.proto" -not -path ./vendor/\*)
|
|
||||||
|
|
||||||
TARGETS_K8S := $(foreach source, $(SOURCES), $(source)_k8s)
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build: $(TARGETS_K8S)
|
|
||||||
|
|
||||||
$(TARGETS_K8S): %_k8s:
|
|
||||||
@mkdir -p $(dir $*)gen
|
|
||||||
protoc $(PROTOC_OPTS) --gotemplate_out=debug=true,template_dir=./templates:$(dir $*)gen "$*"
|
|
@@ -1,18 +0,0 @@
|
|||||||
apiVersion: extensions/v1beta1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: nginx
|
|
||||||
labels:
|
|
||||||
method: Hello-World-nginx
|
|
||||||
spec:
|
|
||||||
replicas: 3
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: nginx
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: nginx
|
|
||||||
image: nginx
|
|
||||||
ports:
|
|
||||||
- containerPort: 80
|
|
@@ -1,10 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: nginx
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: nginx
|
|
||||||
ports:
|
|
||||||
- name: http
|
|
||||||
port: 80
|
|
@@ -1,11 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package nginx;
|
|
||||||
|
|
||||||
message Empty {
|
|
||||||
}
|
|
||||||
|
|
||||||
service Nginx {
|
|
||||||
rpc Hello(Empty) returns (Empty) {}
|
|
||||||
rpc World(Empty) returns (Empty) {}
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
apiVersion: extensions/v1beta1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: {{.File.Package}}
|
|
||||||
labels:
|
|
||||||
method: {{range .Service.Method}}{{.Name}}-{{end}}{{.File.Package}}
|
|
||||||
spec:
|
|
||||||
replicas: 3
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: {{.File.Package}}
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: nginx
|
|
||||||
image: nginx
|
|
||||||
ports:
|
|
||||||
- containerPort: 80
|
|
@@ -1,10 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: {{.File.Package}}
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: {{.File.Package}}
|
|
||||||
ports:
|
|
||||||
- name: http
|
|
||||||
port: 80
|
|
@@ -1,26 +0,0 @@
|
|||||||
.PHONY: re
|
|
||||||
re: clean build test
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
@mkdir -p output
|
|
||||||
|
|
||||||
@# proto-gen-go
|
|
||||||
protoc -I./proto --go_out=plugins=grpc:output proto/aaa/aaa.proto
|
|
||||||
protoc -I./proto --go_out=plugins=grpc:output proto/bbb/bbb.proto
|
|
||||||
@rm -rf output/aaa output/bbb
|
|
||||||
@mv output/github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/* output/
|
|
||||||
@rm -rf output/github.com
|
|
||||||
|
|
||||||
@# protoc-gen-gotemplate
|
|
||||||
protoc -I./proto --gotemplate_out=template_dir=templates,single-package-mode=true:output proto/bbb/bbb.proto
|
|
||||||
gofmt -w .
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
test:
|
|
||||||
go test -i ./output/...
|
|
||||||
go test -v ./output/...
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
rm -rf output
|
|
@@ -1,84 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: aaa/aaa.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package aaa is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
aaa/aaa.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
AaaRequest
|
|
||||||
AaaReply
|
|
||||||
*/
|
|
||||||
package aaa
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type AaaRequest struct {
|
|
||||||
Blah string `protobuf:"bytes,1,opt,name=blah" json:"blah,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *AaaRequest) Reset() { *m = AaaRequest{} }
|
|
||||||
func (m *AaaRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*AaaRequest) ProtoMessage() {}
|
|
||||||
func (*AaaRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *AaaRequest) GetBlah() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Blah
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type AaaReply struct {
|
|
||||||
Error string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *AaaReply) Reset() { *m = AaaReply{} }
|
|
||||||
func (m *AaaReply) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*AaaReply) ProtoMessage() {}
|
|
||||||
func (*AaaReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
|
|
||||||
func (m *AaaReply) GetError() string {
|
|
||||||
if m != nil {
|
|
||||||
return m.Error
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*AaaRequest)(nil), "the.aaa.package.AaaRequest")
|
|
||||||
proto.RegisterType((*AaaReply)(nil), "the.aaa.package.AaaReply")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("aaa/aaa.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 172 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x2c, 0x8e, 0x31, 0x0b, 0xc2, 0x30,
|
|
||||||
0x10, 0x46, 0x29, 0xa8, 0x68, 0x40, 0x84, 0xe0, 0xe0, 0x58, 0x3a, 0xb9, 0xa4, 0x19, 0xfc, 0x05,
|
|
||||||
0xba, 0x8b, 0xd0, 0xd1, 0xed, 0x5a, 0x8f, 0xb4, 0x78, 0xe9, 0xc5, 0xf4, 0x02, 0xfa, 0xef, 0xc5,
|
|
||||||
0xd8, 0xed, 0x1e, 0xbc, 0xe3, 0x7b, 0x6a, 0x0b, 0x00, 0x16, 0x00, 0xea, 0x10, 0x59, 0x58, 0xef,
|
|
||||||
0xa4, 0xc7, 0x3a, 0x23, 0x74, 0x4f, 0x70, 0x58, 0x95, 0x4a, 0x9d, 0x01, 0x1a, 0x7c, 0x25, 0x9c,
|
|
||||||
0x44, 0x6b, 0xb5, 0x68, 0x09, 0xfa, 0x43, 0x51, 0x16, 0xc7, 0x4d, 0x93, 0xef, 0xaa, 0x54, 0xeb,
|
|
||||||
0x6c, 0x04, 0xfa, 0xe8, 0xbd, 0x5a, 0x62, 0x8c, 0x1c, 0x67, 0xe1, 0x0f, 0x97, 0xdb, 0xfd, 0xea,
|
|
||||||
0x06, 0xe9, 0x53, 0x5b, 0x77, 0xec, 0xad, 0xe7, 0x44, 0x36, 0xaf, 0x75, 0xc6, 0xe1, 0x68, 0x1c,
|
|
||||||
0x0b, 0xfa, 0x40, 0x20, 0x68, 0xf1, 0x0d, 0x3e, 0x10, 0x4e, 0x76, 0x1a, 0x46, 0x47, 0x68, 0xe6,
|
|
||||||
0x08, 0xe3, 0xf9, 0x81, 0x96, 0x93, 0x84, 0x24, 0xbf, 0xd6, 0x76, 0x95, 0xdf, 0x4f, 0xdf, 0x00,
|
|
||||||
0x00, 0x00, 0xff, 0xff, 0x93, 0x24, 0x48, 0x9c, 0xbd, 0x00, 0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,200 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go.
|
|
||||||
// source: bbb/bbb.proto
|
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package bbb is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
bbb/bbb.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
BbbRequest
|
|
||||||
BbbReply
|
|
||||||
*/
|
|
||||||
package bbb
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
import the_aaa_package "github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/aaa"
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
type BbbRequest struct {
|
|
||||||
Enable bool `protobuf:"varint,1,opt,name=enable" json:"enable,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *BbbRequest) Reset() { *m = BbbRequest{} }
|
|
||||||
func (m *BbbRequest) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*BbbRequest) ProtoMessage() {}
|
|
||||||
func (*BbbRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
|
|
||||||
func (m *BbbRequest) GetEnable() bool {
|
|
||||||
if m != nil {
|
|
||||||
return m.Enable
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
type BbbReply struct {
|
|
||||||
Done bool `protobuf:"varint,1,opt,name=done" json:"done,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *BbbReply) Reset() { *m = BbbReply{} }
|
|
||||||
func (m *BbbReply) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*BbbReply) ProtoMessage() {}
|
|
||||||
func (*BbbReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
|
|
||||||
func (m *BbbReply) GetDone() bool {
|
|
||||||
if m != nil {
|
|
||||||
return m.Done
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*BbbRequest)(nil), "the.bbb.package.BbbRequest")
|
|
||||||
proto.RegisterType((*BbbReply)(nil), "the.bbb.package.BbbReply")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context
|
|
||||||
var _ grpc.ClientConn
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
|
||||||
|
|
||||||
// Client API for BbbService service
|
|
||||||
|
|
||||||
type BbbServiceClient interface {
|
|
||||||
Aaa(ctx context.Context, in *the_aaa_package.AaaRequest, opts ...grpc.CallOption) (*the_aaa_package.AaaReply, error)
|
|
||||||
Bbb(ctx context.Context, in *BbbRequest, opts ...grpc.CallOption) (*BbbReply, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type bbbServiceClient struct {
|
|
||||||
cc *grpc.ClientConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBbbServiceClient(cc *grpc.ClientConn) BbbServiceClient {
|
|
||||||
return &bbbServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *bbbServiceClient) Aaa(ctx context.Context, in *the_aaa_package.AaaRequest, opts ...grpc.CallOption) (*the_aaa_package.AaaReply, error) {
|
|
||||||
out := new(the_aaa_package.AaaReply)
|
|
||||||
err := grpc.Invoke(ctx, "/the.bbb.package.BbbService/Aaa", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *bbbServiceClient) Bbb(ctx context.Context, in *BbbRequest, opts ...grpc.CallOption) (*BbbReply, error) {
|
|
||||||
out := new(BbbReply)
|
|
||||||
err := grpc.Invoke(ctx, "/the.bbb.package.BbbService/Bbb", in, out, c.cc, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server API for BbbService service
|
|
||||||
|
|
||||||
type BbbServiceServer interface {
|
|
||||||
Aaa(context.Context, *the_aaa_package.AaaRequest) (*the_aaa_package.AaaReply, error)
|
|
||||||
Bbb(context.Context, *BbbRequest) (*BbbReply, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterBbbServiceServer(s *grpc.Server, srv BbbServiceServer) {
|
|
||||||
s.RegisterService(&_BbbService_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _BbbService_Aaa_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(the_aaa_package.AaaRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(BbbServiceServer).Aaa(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/the.bbb.package.BbbService/Aaa",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(BbbServiceServer).Aaa(ctx, req.(*the_aaa_package.AaaRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _BbbService_Bbb_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(BbbRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(BbbServiceServer).Bbb(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/the.bbb.package.BbbService/Bbb",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(BbbServiceServer).Bbb(ctx, req.(*BbbRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _BbbService_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "the.bbb.package.BbbService",
|
|
||||||
HandlerType: (*BbbServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "Aaa",
|
|
||||||
Handler: _BbbService_Aaa_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "Bbb",
|
|
||||||
Handler: _BbbService_Bbb_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "bbb/bbb.proto",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { proto.RegisterFile("bbb/bbb.proto", fileDescriptor0) }
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 242 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x41, 0x4b, 0x03, 0x31,
|
|
||||||
0x10, 0x85, 0x59, 0x2a, 0xa5, 0x04, 0x8a, 0x90, 0x83, 0x68, 0x05, 0x91, 0xe2, 0xc1, 0xcb, 0x26,
|
|
||||||
0xa0, 0xe7, 0x1e, 0xba, 0x77, 0x11, 0xea, 0xcd, 0xdb, 0xcc, 0x76, 0x48, 0x17, 0x93, 0x9d, 0xd8,
|
|
||||||
0x9d, 0x88, 0xfd, 0x0b, 0xfe, 0x6a, 0xd9, 0x34, 0xa2, 0x60, 0x6f, 0x19, 0xde, 0xbc, 0xf7, 0xbd,
|
|
||||||
0x8c, 0x9a, 0x23, 0xa2, 0x45, 0x44, 0x13, 0xf7, 0x2c, 0xac, 0xcf, 0x65, 0x47, 0x26, 0x8f, 0xd0,
|
|
||||||
0xbe, 0x81, 0xa3, 0xc5, 0x1c, 0x00, 0x2c, 0x00, 0x1c, 0xf5, 0xe5, 0x9d, 0x52, 0x0d, 0xe2, 0x86,
|
|
||||||
0xde, 0x13, 0x0d, 0xa2, 0x2f, 0xd4, 0x94, 0x7a, 0x40, 0x4f, 0x97, 0xd5, 0x6d, 0x75, 0x3f, 0xdb,
|
|
||||||
0x94, 0x69, 0x79, 0xa3, 0x66, 0x79, 0x2b, 0xfa, 0x83, 0xd6, 0xea, 0x6c, 0xcb, 0xfd, 0xcf, 0x46,
|
|
||||||
0x7e, 0x3f, 0x7c, 0x55, 0x39, 0xe6, 0x85, 0xf6, 0x1f, 0x5d, 0x4b, 0x7a, 0xa5, 0x26, 0x6b, 0x00,
|
|
||||||
0x7d, 0x6d, 0x46, 0x78, 0x66, 0x1d, 0xe1, 0x66, 0x0d, 0x50, 0x50, 0x8b, 0xab, 0xd3, 0xe2, 0x48,
|
|
||||||
0x58, 0xa9, 0x49, 0x83, 0x58, 0xec, 0x7f, 0xba, 0x9b, 0xdf, 0xa6, 0xc5, 0xfe, 0x4f, 0x8c, 0xfe,
|
|
||||||
0xd0, 0x3c, 0xbf, 0x3e, 0xb9, 0x4e, 0x76, 0x09, 0x4d, 0xcb, 0xc1, 0x06, 0x4e, 0xde, 0xe6, 0xbf,
|
|
||||||
0xb6, 0xb5, 0xa3, 0xbe, 0x76, 0x2c, 0x14, 0xa2, 0x07, 0x21, 0x4b, 0x9f, 0x10, 0xa2, 0xa7, 0xc1,
|
|
||||||
0x0e, 0x5d, 0xef, 0x3c, 0xd5, 0x25, 0xa9, 0x0e, 0xbc, 0x25, 0xcb, 0x49, 0x62, 0x92, 0xf1, 0x92,
|
|
||||||
0x38, 0xcd, 0xf6, 0xc7, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xe1, 0x26, 0xcb, 0x5b, 0x01,
|
|
||||||
0x00, 0x00,
|
|
||||||
}
|
|
@@ -1,19 +0,0 @@
|
|||||||
// file generated with protoc-gen-gotemplate
|
|
||||||
package bbb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/aaa"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct{}
|
|
||||||
|
|
||||||
func (service Service) Aaa(ctx context.Context, input *aaa.AaaRequest) (*aaa.AaaReply, error) {
|
|
||||||
return nil, fmt.Errorf("method not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (service Service) Bbb(ctx context.Context, input *BbbRequest) (*BbbReply, error) {
|
|
||||||
return nil, fmt.Errorf("method not implemented")
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option go_package = "github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/aaa";
|
|
||||||
|
|
||||||
package the.aaa.package;
|
|
||||||
|
|
||||||
message AaaRequest {
|
|
||||||
string blah = 1;
|
|
||||||
}
|
|
||||||
message AaaReply {
|
|
||||||
string error = 1;
|
|
||||||
}
|
|
@@ -1,19 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package the.bbb.package;
|
|
||||||
|
|
||||||
option go_package = "github.com/moul/protoc-gen-gotemplate/examples/single-package-mode/output/bbb";
|
|
||||||
|
|
||||||
import "aaa/aaa.proto";
|
|
||||||
|
|
||||||
service BbbService {
|
|
||||||
rpc Aaa(the.aaa.package.AaaRequest) returns (the.aaa.package.AaaReply);
|
|
||||||
rpc Bbb(BbbRequest) returns (BbbReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
message BbbRequest {
|
|
||||||
bool enable = 1;
|
|
||||||
}
|
|
||||||
message BbbReply {
|
|
||||||
bool done = 1;
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
// file generated with protoc-gen-gotemplate
|
|
||||||
package {{.File.Name | dir}}
|
|
||||||
|
|
||||||
{{- $file := .File}}
|
|
||||||
{{- $currentFile := $file.Name | getProtoFile}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
{{- range .File.Dependency}}
|
|
||||||
{{- $dependency := . | getProtoFile}}
|
|
||||||
{{$dependency.GoPkg}}
|
|
||||||
{{end}}
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct {}
|
|
||||||
|
|
||||||
{{- range .Service.Method}}
|
|
||||||
{{- $in := .InputType | getMessageType $file}}
|
|
||||||
{{- $out := .OutputType | getMessageType $file}}
|
|
||||||
func (service Service) {{.Name}}(ctx context.Context, input *{{$in.GoType $currentFile.GoPkg.Path}}) (*{{$out.GoType $currentFile.GoPkg.Path}}, error) {
|
|
||||||
return nil, fmt.Errorf("method not implemented")
|
|
||||||
}
|
|
||||||
{{end}}
|
|
@@ -1,3 +0,0 @@
|
|||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
protoc -I. --gotemplate_out=template_dir=.:. sitemap.proto
|
|
@@ -1,12 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package sitemap;
|
|
||||||
|
|
||||||
service DummyService {
|
|
||||||
rpc Posts(Request) returns (Response) {}
|
|
||||||
rpc Authors(Request) returns (Response) {}
|
|
||||||
rpc Comments(Request) returns (Response) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
message Request {}
|
|
||||||
message Response {}
|
|
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<url>
|
|
||||||
<loc>/posts</loc>
|
|
||||||
<priority>0.5</priority>
|
|
||||||
<changefreq>monthly</changefreq>
|
|
||||||
<lastmod>2017-03-31</lastmod>
|
|
||||||
</url>
|
|
||||||
<url>
|
|
||||||
<loc>/authors</loc>
|
|
||||||
<priority>0.5</priority>
|
|
||||||
<changefreq>monthly</changefreq>
|
|
||||||
<lastmod>2017-03-31</lastmod>
|
|
||||||
</url>
|
|
||||||
<url>
|
|
||||||
<loc>/comments</loc>
|
|
||||||
<priority>0.5</priority>
|
|
||||||
<changefreq>monthly</changefreq>
|
|
||||||
<lastmod>2017-03-31</lastmod>
|
|
||||||
</url>
|
|
||||||
</urlset>
|
|
@@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">{{range .Service.Method}}
|
|
||||||
<url>
|
|
||||||
<loc>/{{.Name | lower}}</loc>
|
|
||||||
<priority>0.5</priority>
|
|
||||||
<changefreq>monthly</changefreq>
|
|
||||||
<lastmod>{{now | date "2006-01-02"}}</lastmod>
|
|
||||||
</url>{{end}}
|
|
||||||
</urlset>
|
|
84
glide.lock
generated
84
glide.lock
generated
@@ -1,89 +1,15 @@
|
|||||||
hash: 1944ae13e983e8da7b26c697fc40d79d34326b8c7f56c8939fb16f1ff8caca5b
|
hash: 8e73e008df139d080692c91cd6c55549bbb6490f00ea67ee7ae1fbf6facedc86
|
||||||
updated: 2017-05-18T19:20:01.855895064+02:00
|
updated: 2016-12-01T10:08:09.672752932+01:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/aokoli/goutils
|
|
||||||
version: e57d01ace047c1a43e6a49ecf3ecc50ed2be81d1
|
|
||||||
- name: github.com/dgrijalva/jwt-go
|
|
||||||
version: c9eaceb2896dbb515dae7ec352b377a226a52721
|
|
||||||
- name: github.com/go-kit/kit
|
|
||||||
version: 9f5c614cd1e70102f80b644edbc760805ebf16d5
|
|
||||||
subpackages:
|
|
||||||
- auth/jwt
|
|
||||||
- endpoint
|
|
||||||
- log
|
|
||||||
- transport/grpc
|
|
||||||
- transport/http
|
|
||||||
- name: github.com/go-logfmt/logfmt
|
|
||||||
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
|
|
||||||
- name: github.com/go-stack/stack
|
|
||||||
version: 7a2f19628aabfe68f0766b59e74d6315f8347d22
|
|
||||||
- name: github.com/golang/glog
|
|
||||||
version: 23def4e6c14b4da8ac2ed8007337bc5eb5007998
|
|
||||||
- name: github.com/golang/protobuf
|
- name: github.com/golang/protobuf
|
||||||
version: 8ee79997227bf9b34611aee7946ae64735e6fd93
|
version: 98fa357170587e470c5f27d3c3ea0947b71eb455
|
||||||
subpackages:
|
subpackages:
|
||||||
- proto
|
- proto
|
||||||
- protoc-gen-go/descriptor
|
- protoc-gen-go/descriptor
|
||||||
- protoc-gen-go/generator
|
- protoc-gen-go/generator
|
||||||
- protoc-gen-go/plugin
|
- protoc-gen-go/plugin
|
||||||
- name: github.com/gorilla/handlers
|
|
||||||
version: e1b2144f2167de0e1042d1d35e5cba5119d4fb5d
|
|
||||||
- name: github.com/grpc-ecosystem/grpc-gateway
|
|
||||||
version: 589b126116b5fc961939b3e156c29e4d9d58222f
|
|
||||||
subpackages:
|
|
||||||
- protoc-gen-grpc-gateway/descriptor
|
|
||||||
- protoc-gen-grpc-gateway/httprule
|
|
||||||
- utilities
|
|
||||||
- name: github.com/huandu/xstrings
|
|
||||||
version: 3959339b333561bf62a38b424fd41517c2c90f40
|
|
||||||
- name: github.com/imdario/mergo
|
|
||||||
version: 3e95a51e0639b4cf372f2ccf74c86749d747fbdc
|
|
||||||
- name: github.com/kr/fs
|
- name: github.com/kr/fs
|
||||||
version: 2788f0dbd16903de03cb8186e5c7d97b69ad387b
|
version: 2788f0dbd16903de03cb8186e5c7d97b69ad387b
|
||||||
- name: github.com/kr/logfmt
|
- name: github.com/moul/funcmap
|
||||||
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
|
version: f798117cf01752496ce9b8739b2b1ed21e3a6c1c
|
||||||
- name: github.com/Masterminds/semver
|
|
||||||
version: 59c29afe1a994eacb71c833025ca7acf874bb1da
|
|
||||||
- name: github.com/Masterminds/sprig
|
|
||||||
version: 2f4371ac162f912989f01cc2b6af4ba6660e6a30
|
|
||||||
- name: github.com/satori/go.uuid
|
|
||||||
version: 879c5887cd475cd7864858769793b2ceb0d44feb
|
|
||||||
- name: golang.org/x/crypto
|
|
||||||
version: 0fe963104e9d1877082f8fb38f816fcd97eb1d10
|
|
||||||
subpackages:
|
|
||||||
- pbkdf2
|
|
||||||
- scrypt
|
|
||||||
- name: golang.org/x/net
|
|
||||||
version: da2b4fa28524a3baf148c1b94df4440267063c88
|
|
||||||
subpackages:
|
|
||||||
- context
|
|
||||||
- context/ctxhttp
|
|
||||||
- http2
|
|
||||||
- http2/hpack
|
|
||||||
- idna
|
|
||||||
- internal/timeseries
|
|
||||||
- lex/httplex
|
|
||||||
- trace
|
|
||||||
- name: golang.org/x/text
|
|
||||||
version: a49bea13b776691cb1b49873e5d8df96ec74831a
|
|
||||||
subpackages:
|
|
||||||
- secure/bidirule
|
|
||||||
- transform
|
|
||||||
- unicode/bidi
|
|
||||||
- unicode/norm
|
|
||||||
- name: google.golang.org/genproto
|
|
||||||
version: bb3573be0c484136831138976d444b8754777aff
|
|
||||||
subpackages:
|
|
||||||
- googleapis/api/annotations
|
|
||||||
- name: google.golang.org/grpc
|
|
||||||
version: 777daa17ff9b5daef1cfdf915088a2ada3332bf0
|
|
||||||
subpackages:
|
|
||||||
- codes
|
|
||||||
- credentials
|
|
||||||
- grpclog
|
|
||||||
- internal
|
|
||||||
- metadata
|
|
||||||
- naming
|
|
||||||
- peer
|
|
||||||
- transport
|
|
||||||
testImports: []
|
testImports: []
|
||||||
|
@@ -7,10 +7,5 @@ import:
|
|||||||
- protoc-gen-go/generator
|
- protoc-gen-go/generator
|
||||||
- protoc-gen-go/plugin
|
- protoc-gen-go/plugin
|
||||||
- package: github.com/kr/fs
|
- package: github.com/kr/fs
|
||||||
- package: github.com/Masterminds/sprig
|
- package: github.com/moul/funcmap
|
||||||
- package: github.com/huandu/xstrings
|
version: ~1.1.0
|
||||||
- package: google.golang.org/genproto
|
|
||||||
subpackages:
|
|
||||||
- googleapis/api/annotations
|
|
||||||
- package: github.com/grpc-ecosystem/grpc-gateway
|
|
||||||
version: 1.2.2
|
|
||||||
|
343
helpers.go
343
helpers.go
@@ -1,343 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/Masterminds/sprig"
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/golang/protobuf/protoc-gen-go/descriptor"
|
|
||||||
ggdescriptor "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
"github.com/huandu/xstrings"
|
|
||||||
options "google.golang.org/genproto/googleapis/api/annotations"
|
|
||||||
)
|
|
||||||
|
|
||||||
var jsReservedRe *regexp.Regexp = regexp.MustCompile(`(^|[^A-Za-z])(do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)($|[^A-Za-z])`)
|
|
||||||
|
|
||||||
var ProtoHelpersFuncMap = template.FuncMap{
|
|
||||||
"string": func(i interface {
|
|
||||||
String() string
|
|
||||||
}) string {
|
|
||||||
return i.String()
|
|
||||||
},
|
|
||||||
"json": func(v interface{}) string {
|
|
||||||
a, _ := json.Marshal(v)
|
|
||||||
return string(a)
|
|
||||||
},
|
|
||||||
"prettyjson": func(v interface{}) string {
|
|
||||||
a, _ := json.MarshalIndent(v, "", " ")
|
|
||||||
return string(a)
|
|
||||||
},
|
|
||||||
"splitArray": func(sep string, s string) []string {
|
|
||||||
return strings.Split(s, sep)
|
|
||||||
},
|
|
||||||
"first": func(a []string) string {
|
|
||||||
return a[0]
|
|
||||||
},
|
|
||||||
"last": func(a []string) string {
|
|
||||||
return a[len(a)-1]
|
|
||||||
},
|
|
||||||
"upperFirst": func(s string) string {
|
|
||||||
return strings.ToUpper(s[:1]) + s[1:]
|
|
||||||
},
|
|
||||||
"lowerFirst": func(s string) string {
|
|
||||||
return strings.ToLower(s[:1]) + s[1:]
|
|
||||||
},
|
|
||||||
"camelCase": func(s string) string {
|
|
||||||
if len(s) > 1 {
|
|
||||||
return xstrings.ToCamelCase(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.ToUpper(s[:1])
|
|
||||||
},
|
|
||||||
"lowerCamelCase": func(s string) string {
|
|
||||||
if len(s) > 1 {
|
|
||||||
s = xstrings.ToCamelCase(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.ToLower(s[:1]) + s[1:]
|
|
||||||
},
|
|
||||||
"kebabCase": func(s string) string {
|
|
||||||
return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1)
|
|
||||||
},
|
|
||||||
"snakeCase": xstrings.ToSnakeCase,
|
|
||||||
"getProtoFile": getProtoFile,
|
|
||||||
"getMessageType": getMessageType,
|
|
||||||
"getEnumValue": getEnumValue,
|
|
||||||
"isFieldMessage": isFieldMessage,
|
|
||||||
"isFieldRepeated": isFieldRepeated,
|
|
||||||
"goType": goType,
|
|
||||||
"goTypeWithPackage": goTypeWithPackage,
|
|
||||||
"jsType": jsType,
|
|
||||||
"jsSuffixReserved": jsSuffixReservedKeyword,
|
|
||||||
"namespacedFlowType": namespacedFlowType,
|
|
||||||
"httpVerb": httpVerb,
|
|
||||||
"httpPath": httpPath,
|
|
||||||
"shortType": shortType,
|
|
||||||
"urlHasVarsFromMessage": urlHasVarsFromMessage,
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
for k, v := range sprig.TxtFuncMap() {
|
|
||||||
ProtoHelpersFuncMap[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getProtoFile(name string) *ggdescriptor.File {
|
|
||||||
if registry == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
file, err := registry.LookupFile(name)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMessageType(f *descriptor.FileDescriptorProto, name string) *ggdescriptor.Message {
|
|
||||||
if registry != nil {
|
|
||||||
msg, err := registry.LookupMsg(".", name)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return msg
|
|
||||||
}
|
|
||||||
|
|
||||||
// name is in the form .packageName.MessageTypeName.InnerMessageTypeName...
|
|
||||||
// e.g. .article.ProductTag
|
|
||||||
splits := strings.Split(name, ".")
|
|
||||||
target := splits[len(splits)-1]
|
|
||||||
for _, m := range f.MessageType {
|
|
||||||
if target == *m.Name {
|
|
||||||
return &ggdescriptor.Message{
|
|
||||||
DescriptorProto: m,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getEnumValue(f []*descriptor.EnumDescriptorProto, name string) []*descriptor.EnumValueDescriptorProto {
|
|
||||||
for _, item := range f {
|
|
||||||
if strings.EqualFold(*item.Name, name) {
|
|
||||||
return item.GetValue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isFieldMessage(f *descriptor.FieldDescriptorProto) bool {
|
|
||||||
if f.Type != nil && *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isFieldRepeated(f *descriptor.FieldDescriptorProto) bool {
|
|
||||||
if f.Type != nil && f.Label != nil && *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func goTypeWithPackage(f *descriptor.FieldDescriptorProto) string {
|
|
||||||
pkg := ""
|
|
||||||
if *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE {
|
|
||||||
pkg = getPackageTypeName(*f.TypeName)
|
|
||||||
}
|
|
||||||
return goType(pkg, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func goType(pkg string, f *descriptor.FieldDescriptorProto) string {
|
|
||||||
switch *f.Type {
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]float64"
|
|
||||||
}
|
|
||||||
return "float64"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]float32"
|
|
||||||
}
|
|
||||||
return "float32"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_INT64:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]int64"
|
|
||||||
}
|
|
||||||
return "int64"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_UINT64:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]uint64"
|
|
||||||
}
|
|
||||||
return "uint64"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_INT32:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]uint32"
|
|
||||||
}
|
|
||||||
return "uint32"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]bool"
|
|
||||||
}
|
|
||||||
return "bool"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]string"
|
|
||||||
}
|
|
||||||
return "string"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
|
||||||
if pkg != "" {
|
|
||||||
pkg = pkg + "."
|
|
||||||
}
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return fmt.Sprintf("[]*%s%s", pkg, shortType(*f.TypeName))
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("*%s%s", pkg, shortType(*f.TypeName))
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]byte"
|
|
||||||
}
|
|
||||||
return "byte"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_UINT32:
|
|
||||||
if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return "[]uint32"
|
|
||||||
}
|
|
||||||
return "uint32"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_ENUM:
|
|
||||||
return fmt.Sprintf("*%s.%s", pkg, shortType(*f.TypeName))
|
|
||||||
default:
|
|
||||||
return "interface{}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func jsType(f *descriptor.FieldDescriptorProto) string {
|
|
||||||
template := "%s"
|
|
||||||
if isFieldRepeated(f) == true {
|
|
||||||
template = "Array<%s>"
|
|
||||||
}
|
|
||||||
|
|
||||||
switch *f.Type {
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_ENUM:
|
|
||||||
return fmt.Sprintf(template, namespacedFlowType(*f.TypeName))
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FLOAT,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_INT64,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_UINT64,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_INT32,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FIXED64,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_FIXED32,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_UINT32,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SFIXED32,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SFIXED64,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SINT32,
|
|
||||||
descriptor.FieldDescriptorProto_TYPE_SINT64:
|
|
||||||
return fmt.Sprintf(template, "number")
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
|
||||||
return fmt.Sprintf(template, "boolean")
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
|
||||||
return fmt.Sprintf(template, "Uint8Array")
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
|
||||||
return fmt.Sprintf(template, "string")
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf(template, "any")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func jsSuffixReservedKeyword(s string) string {
|
|
||||||
return jsReservedRe.ReplaceAllString(s, "${1}${2}_${3}")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPackageTypeName(s string) string {
|
|
||||||
if strings.Contains(s, ".") {
|
|
||||||
return strings.Split(s, ".")[1]
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func shortType(s string) string {
|
|
||||||
t := strings.Split(s, ".")
|
|
||||||
return t[len(t)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func namespacedFlowType(s string) string {
|
|
||||||
trimmed := strings.TrimLeft(s, ".")
|
|
||||||
splitted := strings.Split(trimmed, ".")
|
|
||||||
return strings.Join(splitted, "$")
|
|
||||||
}
|
|
||||||
|
|
||||||
func httpPath(m *descriptor.MethodDescriptorProto) string {
|
|
||||||
|
|
||||||
ext, err := proto.GetExtension(m.Options, options.E_Http)
|
|
||||||
if err != nil {
|
|
||||||
return err.Error()
|
|
||||||
}
|
|
||||||
opts, ok := ext.(*options.HttpRule)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Sprintf("extension is %T; want an HttpRule", ext)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch t := opts.Pattern.(type) {
|
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
case *options.HttpRule_Get:
|
|
||||||
return t.Get
|
|
||||||
case *options.HttpRule_Post:
|
|
||||||
return t.Post
|
|
||||||
case *options.HttpRule_Put:
|
|
||||||
return t.Put
|
|
||||||
case *options.HttpRule_Delete:
|
|
||||||
return t.Delete
|
|
||||||
case *options.HttpRule_Patch:
|
|
||||||
return t.Patch
|
|
||||||
case *options.HttpRule_Custom:
|
|
||||||
return t.Custom.Path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func httpVerb(m *descriptor.MethodDescriptorProto) string {
|
|
||||||
|
|
||||||
ext, err := proto.GetExtension(m.Options, options.E_Http)
|
|
||||||
if err != nil {
|
|
||||||
return err.Error()
|
|
||||||
}
|
|
||||||
opts, ok := ext.(*options.HttpRule)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Sprintf("extension is %T; want an HttpRule", ext)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch t := opts.Pattern.(type) {
|
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
case *options.HttpRule_Get:
|
|
||||||
return "GET"
|
|
||||||
case *options.HttpRule_Post:
|
|
||||||
return "POST"
|
|
||||||
case *options.HttpRule_Put:
|
|
||||||
return "PUT"
|
|
||||||
case *options.HttpRule_Delete:
|
|
||||||
return "DELETE"
|
|
||||||
case *options.HttpRule_Patch:
|
|
||||||
return "PATCH"
|
|
||||||
case *options.HttpRule_Custom:
|
|
||||||
return t.Custom.Kind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func urlHasVarsFromMessage(path string, d *descriptor.DescriptorProto) bool {
|
|
||||||
for _, field := range d.Field {
|
|
||||||
if !isFieldMessage(field) {
|
|
||||||
if strings.Contains(path, fmt.Sprintf("{%s}", *field.Name)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
79
main.go
79
main.go
@@ -8,12 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/golang/protobuf/protoc-gen-go/generator"
|
"github.com/golang/protobuf/protoc-gen-go/generator"
|
||||||
"github.com/golang/protobuf/protoc-gen-go/plugin"
|
|
||||||
ggdescriptor "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
registry *ggdescriptor.Registry // some helpers need access to registry
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -35,13 +29,8 @@ func main() {
|
|||||||
g.CommandLineParameters(g.Request.GetParameter())
|
g.CommandLineParameters(g.Request.GetParameter())
|
||||||
|
|
||||||
// Parse parameters
|
// Parse parameters
|
||||||
var (
|
templateDir := "./templates"
|
||||||
templateDir = "./templates"
|
debug := false
|
||||||
destinationDir = "."
|
|
||||||
debug = false
|
|
||||||
all = false
|
|
||||||
singlePackageMode = false
|
|
||||||
)
|
|
||||||
if parameter := g.Request.GetParameter(); parameter != "" {
|
if parameter := g.Request.GetParameter(); parameter != "" {
|
||||||
for _, param := range strings.Split(parameter, ",") {
|
for _, param := range strings.Split(parameter, ",") {
|
||||||
parts := strings.Split(param, "=")
|
parts := strings.Split(param, "=")
|
||||||
@@ -53,33 +42,10 @@ func main() {
|
|||||||
case "template_dir":
|
case "template_dir":
|
||||||
templateDir = parts[1]
|
templateDir = parts[1]
|
||||||
break
|
break
|
||||||
case "destination_dir":
|
|
||||||
destinationDir = parts[1]
|
|
||||||
break
|
|
||||||
case "single-package-mode":
|
|
||||||
switch strings.ToLower(parts[1]) {
|
|
||||||
case "true", "t":
|
|
||||||
singlePackageMode = true
|
|
||||||
case "false", "f":
|
|
||||||
default:
|
|
||||||
log.Printf("Err: invalid value for single-package-mode: %q", parts[1])
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case "debug":
|
case "debug":
|
||||||
switch strings.ToLower(parts[1]) {
|
if parts[1] == "true" {
|
||||||
case "true", "t":
|
|
||||||
debug = true
|
debug = true
|
||||||
case "false", "f":
|
} else {
|
||||||
default:
|
|
||||||
log.Printf("Err: invalid value for debug: %q", parts[1])
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case "all":
|
|
||||||
switch strings.ToLower(parts[1]) {
|
|
||||||
case "true", "t":
|
|
||||||
all = true
|
|
||||||
case "false", "f":
|
|
||||||
default:
|
|
||||||
log.Printf("Err: invalid value for debug: %q", parts[1])
|
log.Printf("Err: invalid value for debug: %q", parts[1])
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -89,44 +55,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplMap := make(map[string]*plugin_go.CodeGeneratorResponse_File)
|
|
||||||
concatOrAppend := func(file *plugin_go.CodeGeneratorResponse_File) {
|
|
||||||
if val, ok := tmplMap[file.GetName()]; ok {
|
|
||||||
*val.Content += file.GetContent()
|
|
||||||
} else {
|
|
||||||
tmplMap[file.GetName()] = file
|
|
||||||
g.Response.File = append(g.Response.File, file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if singlePackageMode {
|
|
||||||
registry = ggdescriptor.NewRegistry()
|
|
||||||
if err := registry.Load(g.Request); err != nil {
|
|
||||||
g.Error(err, "registry: failed to load the request")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate the encoders
|
// Generate the encoders
|
||||||
for _, file := range g.Request.GetProtoFile() {
|
for _, file := range g.Request.GetProtoFile() {
|
||||||
if all {
|
|
||||||
if singlePackageMode {
|
|
||||||
if _, err := registry.LookupFile(file.GetName()); err != nil {
|
|
||||||
g.Error(err, "registry: failed to lookup file %q", file.GetName())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
encoder := NewGenericTemplateBasedEncoder(templateDir, file, debug, destinationDir)
|
|
||||||
for _, tmpl := range encoder.Files() {
|
|
||||||
concatOrAppend(tmpl)
|
|
||||||
}
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, service := range file.GetService() {
|
for _, service := range file.GetService() {
|
||||||
encoder := NewGenericServiceTemplateBasedEncoder(templateDir, service, file, debug, destinationDir)
|
encoder := NewGenericTemplateBasedEncoder(templateDir, service, file, debug)
|
||||||
for _, tmpl := range encoder.Files() {
|
g.Response.File = append(g.Response.File, encoder.Files()...)
|
||||||
concatOrAppend(tmpl)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
247
slides/README.md
247
slides/README.md
@@ -1,247 +0,0 @@
|
|||||||
# [fit] Protobuf & Code Generation
|
|
||||||
|
|
||||||
### 2016, by Manfred Touron (@moul)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# overview
|
|
||||||
|
|
||||||
* go-kit is an amazing framework to develop strong micro services
|
|
||||||
* but it requires a lot of boilerplate code
|
|
||||||
* return on experience on go-kit boilerplate code generation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# protobuf?
|
|
||||||
|
|
||||||
* limited to exchanges (methods and models)
|
|
||||||
* extendable with plugins
|
|
||||||
* contract-based
|
|
||||||
* universal
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# code generation?
|
|
||||||
|
|
||||||
* the good old ./generate.sh bash script
|
|
||||||
* go:generate
|
|
||||||
* make
|
|
||||||
* protobuf + [protoc-gen-gotemplate](https://github.com/moul/protoc-gen-gotemplate)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# go-kit
|
|
||||||
|
|
||||||
* protobuf-first, rpc-first service framework in Golang
|
|
||||||
* abstract services, endpoints, transports
|
|
||||||
* requires a lot of boilerplate code in multiple packages
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# example: `session.proto`
|
|
||||||
|
|
||||||
```protobuf
|
|
||||||
syntax = "proto3";
|
|
||||||
package session;
|
|
||||||
|
|
||||||
service SessionService {
|
|
||||||
rpc Login(LoginRequest) returns (LoginResponse) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
message LoginRequest {
|
|
||||||
string username = 1;
|
|
||||||
string password = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message LoginResponse {
|
|
||||||
string token = 1;
|
|
||||||
string err_msg = 2;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# example: `session.go`
|
|
||||||
|
|
||||||
```go
|
|
||||||
package sessionsvc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct{}
|
|
||||||
|
|
||||||
func New() pb.SessionServiceServer {
|
|
||||||
return &Service{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) {
|
|
||||||
// custon code here
|
|
||||||
return nil, fmt.Errorf("not implemented")
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
##### example: `{{.File.Package}}/gen/transports/http/http.go.tmpl`
|
|
||||||
|
|
||||||
```go
|
|
||||||
// source: templates/{{.File.Package}}/gen/transports/http/http.go.tmpl
|
|
||||||
package {{.File.Package}}_httptransport
|
|
||||||
import (
|
|
||||||
gokit_endpoint "github.com/go-kit/kit/endpoint"
|
|
||||||
httptransport "github.com/go-kit/kit/transport/http"
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb"
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
```go
|
|
||||||
// result: services/user/gen/transports/http/http.go
|
|
||||||
package user_httptransport
|
|
||||||
import (
|
|
||||||
gokit_endpoint "github.com/go-kit/kit/endpoint"
|
|
||||||
httptransport "github.com/go-kit/kit/transport/http"
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
##### example: `{{.File.Package}}/gen/transports/http/http.go.tmpl`
|
|
||||||
|
|
||||||
```go
|
|
||||||
// source: templates/{{.File.Package}}/gen/transports/http/http.go.tmpl
|
|
||||||
{{range .Service.Method}}
|
|
||||||
func Make{{.Name}}Handler(ctx context.Context, svc pb.{{$file.Package | title}}ServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
ctx,
|
|
||||||
endpoint,
|
|
||||||
decode{{.Name}}Request,
|
|
||||||
encode{{.Name}}Response,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
```
|
|
||||||
|
|
||||||
```go
|
|
||||||
// result: services/user/gen/transports/http/http.go
|
|
||||||
func MakeGetUserHandler(ctx context.Context, svc pb.UserServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
|
||||||
return httptransport.NewServer(
|
|
||||||
ctx,
|
|
||||||
endpoint,
|
|
||||||
decodeGetUserRequest,
|
|
||||||
encodeGetUserResponse,
|
|
||||||
[]httptransport.ServerOption{}...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
##### example: `{{.File.Package}}/gen/transports/http/http.go.tmpl`
|
|
||||||
|
|
||||||
```go
|
|
||||||
// source: templates/{{.File.Package}}/gen/transports/http/http.go.tmpl
|
|
||||||
func RegisterHandlers(ctx context.Context, svc pb.{{$file.Package | title}}ServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error {
|
|
||||||
{{range .Service.Method}}
|
|
||||||
log.Println("new HTTP endpoint: \"/{{.Name}}\" (service={{$file.Package | title}})")
|
|
||||||
mux.Handle("/{{.Name}}", Make{{.Name}}Handler(ctx, svc, endpoints.{{.Name}}Endpoint))
|
|
||||||
{{end}}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```go
|
|
||||||
// result: services/user/gen/transports/http/http.go
|
|
||||||
func RegisterHandlers(ctx context.Context, svc pb.UserServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error {
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/CreateUser\" (service=User)")
|
|
||||||
mux.Handle("/CreateUser", MakeCreateUserHandler(ctx, svc, endpoints.CreateUserEndpoint))
|
|
||||||
|
|
||||||
log.Println("new HTTP endpoint: \"/GetUser\" (service=User)")
|
|
||||||
mux.Handle("/GetUser", MakeGetUserHandler(ctx, svc, endpoints.GetUserEndpoint))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
#### `protoc --gogo_out=plugins=grpc:. ./services/*/*.proto`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
#### `protoc --gotemplate_out=template_dir=./templates:services ./services/*/*.proto`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## 3 services
|
|
||||||
## 6 methods
|
|
||||||
## 149 custom lines
|
|
||||||
## 1429 generated lines
|
|
||||||
## business focus
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# generation usages
|
|
||||||
|
|
||||||
* go-kit boilerplate (see [examples/go-kit](https://github.com/moul/protoc-gen-gotemplate/tree/master/examples/go-kit))
|
|
||||||
* k8s configuration
|
|
||||||
* Dockerfile
|
|
||||||
* documentation
|
|
||||||
* unit-tests
|
|
||||||
* fun
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# pros
|
|
||||||
|
|
||||||
* small custom codebase
|
|
||||||
* templates shipped with code
|
|
||||||
* hardly typed, no reflects
|
|
||||||
* genericity
|
|
||||||
* contrat terms (protobuf) respected
|
|
||||||
* not limited to a language
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# cons
|
|
||||||
|
|
||||||
* the author needs to write its own templates
|
|
||||||
* sometimes difficult to generate valid code
|
|
||||||
* not enough helpers around the code generation yet
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# improvement ideas
|
|
||||||
|
|
||||||
* Support protobufs extensions (i.e, annotations.probo)
|
|
||||||
* Generate one file from multiple services
|
|
||||||
* Add more helpers around the code generation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# conclusion
|
|
||||||
|
|
||||||
* Useful to keep everything standard
|
|
||||||
* The awesomeness of go-kit without the hassle of writing boilerplate code
|
|
||||||
* Always up-to-date with the contracts
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# questions?
|
|
||||||
|
|
||||||
### github.com/moul/protoc-gen-gotemplate
|
|
||||||
### @moul
|
|
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
Binary file not shown.
Before Width: | Height: | Size: 124 KiB |
Binary file not shown.
25
vendor/github.com/Masterminds/semver/.travis.yml
generated
vendored
25
vendor/github.com/Masterminds/semver/.travis.yml
generated
vendored
@@ -1,25 +0,0 @@
|
|||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.5
|
|
||||||
- 1.6
|
|
||||||
- 1.7
|
|
||||||
- tip
|
|
||||||
|
|
||||||
# Setting sudo access to false will let Travis CI use containers rather than
|
|
||||||
# VMs to run the tests. For more details see:
|
|
||||||
# - http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
|
||||||
# - http://docs.travis-ci.com/user/workers/standard-infrastructure/
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
script:
|
|
||||||
- GO15VENDOREXPERIMENT=1 make setup
|
|
||||||
- GO15VENDOREXPERIMENT=1 make test
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
webhooks:
|
|
||||||
urls:
|
|
||||||
- https://webhooks.gitter.im/e/06e3328629952dabe3e0
|
|
||||||
on_success: change # options: [always|never|change] default: always
|
|
||||||
on_failure: always # options: [always|never|change] default: always
|
|
||||||
on_start: never # options: [always|never|change] default: always
|
|
45
vendor/github.com/Masterminds/semver/CHANGELOG.md
generated
vendored
45
vendor/github.com/Masterminds/semver/CHANGELOG.md
generated
vendored
@@ -1,45 +0,0 @@
|
|||||||
# Release 1.2.2 (2016-12-13)
|
|
||||||
|
|
||||||
## Fixed
|
|
||||||
- #34: Fixed issue where hyphen range was not working with pre-release parsing.
|
|
||||||
|
|
||||||
# Release 1.2.1 (2016-11-28)
|
|
||||||
|
|
||||||
## Fixed
|
|
||||||
- #24: Fixed edge case issue where constraint "> 0" does not handle "0.0.1-alpha"
|
|
||||||
properly.
|
|
||||||
|
|
||||||
# Release 1.2.0 (2016-11-04)
|
|
||||||
|
|
||||||
## Added
|
|
||||||
- #20: Added MustParse function for versions (thanks @adamreese)
|
|
||||||
- #15: Added increment methods on versions (thanks @mh-cbon)
|
|
||||||
|
|
||||||
## Fixed
|
|
||||||
- Issue #21: Per the SemVer spec (section 9) a pre-release is unstable and
|
|
||||||
might not satisfy the intended compatibility. The change here ignores pre-releases
|
|
||||||
on constraint checks (e.g., ~ or ^) when a pre-release is not part of the
|
|
||||||
constraint. For example, `^1.2.3` will ignore pre-releases while
|
|
||||||
`^1.2.3-alpha` will include them.
|
|
||||||
|
|
||||||
# Release 1.1.1 (2016-06-30)
|
|
||||||
|
|
||||||
## Changed
|
|
||||||
- Issue #9: Speed up version comparison performance (thanks @sdboyer)
|
|
||||||
- Issue #8: Added benchmarks (thanks @sdboyer)
|
|
||||||
- Updated Go Report Card URL to new location
|
|
||||||
- Updated Readme to add code snippet formatting (thanks @mh-cbon)
|
|
||||||
- Updating tagging to v[SemVer] structure for compatibility with other tools.
|
|
||||||
|
|
||||||
# Release 1.1.0 (2016-03-11)
|
|
||||||
|
|
||||||
- Issue #2: Implemented validation to provide reasons a versions failed a
|
|
||||||
constraint.
|
|
||||||
|
|
||||||
# Release 1.0.1 (2015-12-31)
|
|
||||||
|
|
||||||
- Fixed #1: * constraint failing on valid versions.
|
|
||||||
|
|
||||||
# Release 1.0.0 (2015-10-20)
|
|
||||||
|
|
||||||
- Initial release
|
|
20
vendor/github.com/Masterminds/semver/LICENSE.txt
generated
vendored
20
vendor/github.com/Masterminds/semver/LICENSE.txt
generated
vendored
@@ -1,20 +0,0 @@
|
|||||||
The Masterminds
|
|
||||||
Copyright (C) 2014-2015, Matt Butcher and Matt Farina
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
36
vendor/github.com/Masterminds/semver/Makefile
generated
vendored
36
vendor/github.com/Masterminds/semver/Makefile
generated
vendored
@@ -1,36 +0,0 @@
|
|||||||
.PHONY: setup
|
|
||||||
setup:
|
|
||||||
go get -u gopkg.in/alecthomas/gometalinter.v1
|
|
||||||
gometalinter.v1 --install
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
test: validate lint
|
|
||||||
@echo "==> Running tests"
|
|
||||||
go test -v
|
|
||||||
|
|
||||||
.PHONY: validate
|
|
||||||
validate:
|
|
||||||
@echo "==> Running static validations"
|
|
||||||
@gometalinter.v1 \
|
|
||||||
--disable-all \
|
|
||||||
--enable deadcode \
|
|
||||||
--severity deadcode:error \
|
|
||||||
--enable gofmt \
|
|
||||||
--enable gosimple \
|
|
||||||
--enable ineffassign \
|
|
||||||
--enable misspell \
|
|
||||||
--enable vet \
|
|
||||||
--tests \
|
|
||||||
--vendor \
|
|
||||||
--deadline 60s \
|
|
||||||
./... || exit_code=1
|
|
||||||
|
|
||||||
.PHONY: lint
|
|
||||||
lint:
|
|
||||||
@echo "==> Running linters"
|
|
||||||
@gometalinter.v1 \
|
|
||||||
--disable-all \
|
|
||||||
--enable golint \
|
|
||||||
--vendor \
|
|
||||||
--deadline 60s \
|
|
||||||
./... || :
|
|
163
vendor/github.com/Masterminds/semver/README.md
generated
vendored
163
vendor/github.com/Masterminds/semver/README.md
generated
vendored
@@ -1,163 +0,0 @@
|
|||||||
# SemVer
|
|
||||||
|
|
||||||
The `semver` package provides the ability to work with [Semantic Versions](http://semver.org) in Go. Specifically it provides the ability to:
|
|
||||||
|
|
||||||
* Parse semantic versions
|
|
||||||
* Sort semantic versions
|
|
||||||
* Check if a semantic version fits within a set of constraints
|
|
||||||
* Optionally work with a `v` prefix
|
|
||||||
|
|
||||||
[](https://travis-ci.org/Masterminds/semver) [](https://ci.appveyor.com/project/mattfarina/semver/branch/master) [](https://godoc.org/github.com/Masterminds/semver) [](https://goreportcard.com/report/github.com/Masterminds/semver)
|
|
||||||
|
|
||||||
## Parsing Semantic Versions
|
|
||||||
|
|
||||||
To parse a semantic version use the `NewVersion` function. For example,
|
|
||||||
|
|
||||||
```go
|
|
||||||
v, err := semver.NewVersion("1.2.3-beta.1+build345")
|
|
||||||
```
|
|
||||||
|
|
||||||
If there is an error the version wasn't parseable. The version object has methods
|
|
||||||
to get the parts of the version, compare it to other versions, convert the
|
|
||||||
version back into a string, and get the original string. For more details
|
|
||||||
please see the [documentation](https://godoc.org/github.com/Masterminds/semver).
|
|
||||||
|
|
||||||
## Sorting Semantic Versions
|
|
||||||
|
|
||||||
A set of versions can be sorted using the [`sort`](https://golang.org/pkg/sort/)
|
|
||||||
package from the standard library. For example,
|
|
||||||
|
|
||||||
```go
|
|
||||||
raw := []string{"1.2.3", "1.0", "1.3", "2", "0.4.2",}
|
|
||||||
vs := make([]*semver.Version, len(raw))
|
|
||||||
for i, r := range raw {
|
|
||||||
v, err := semver.NewVersion(r)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error parsing version: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
vs[i] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(semver.Collection(vs))
|
|
||||||
```
|
|
||||||
|
|
||||||
## Checking Version Constraints
|
|
||||||
|
|
||||||
Checking a version against version constraints is one of the most featureful
|
|
||||||
parts of the package.
|
|
||||||
|
|
||||||
```go
|
|
||||||
c, err := semver.NewConstraint(">= 1.2.3")
|
|
||||||
if err != nil {
|
|
||||||
// Handle constraint not being parseable.
|
|
||||||
}
|
|
||||||
|
|
||||||
v, _ := semver.NewVersion("1.3")
|
|
||||||
if err != nil {
|
|
||||||
// Handle version not being parseable.
|
|
||||||
}
|
|
||||||
// Check if the version meets the constraints. The a variable will be true.
|
|
||||||
a := c.Check(v)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Basic Comparisons
|
|
||||||
|
|
||||||
There are two elements to the comparisons. First, a comparison string is a list
|
|
||||||
of comma separated and comparisons. These are then separated by || separated or
|
|
||||||
comparisons. For example, `">= 1.2, < 3.0.0 || >= 4.2.3"` is looking for a
|
|
||||||
comparison that's greater than or equal to 1.2 and less than 3.0.0 or is
|
|
||||||
greater than or equal to 4.2.3.
|
|
||||||
|
|
||||||
The basic comparisons are:
|
|
||||||
|
|
||||||
* `=`: equal (aliased to no operator)
|
|
||||||
* `!=`: not equal
|
|
||||||
* `>`: greater than
|
|
||||||
* `<`: less than
|
|
||||||
* `>=`: greater than or equal to
|
|
||||||
* `<=`: less than or equal to
|
|
||||||
|
|
||||||
_Note, according to the Semantic Version specification pre-releases may not be
|
|
||||||
API compliant with their release counterpart. It says,_
|
|
||||||
|
|
||||||
> _A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version._
|
|
||||||
|
|
||||||
_SemVer comparisons without a pre-release value will skip pre-release versions.
|
|
||||||
For example, `>1.2.3` will skip pre-releases when looking at a list of values
|
|
||||||
while `>1.2.3-alpha.1` will evaluate pre-releases._
|
|
||||||
|
|
||||||
## Hyphen Range Comparisons
|
|
||||||
|
|
||||||
There are multiple methods to handle ranges and the first is hyphens ranges.
|
|
||||||
These look like:
|
|
||||||
|
|
||||||
* `1.2 - 1.4.5` which is equivalent to `>= 1.2, <= 1.4.5`
|
|
||||||
* `2.3.4 - 4.5` which is equivalent to `>= 2.3.4, <= 4.5`
|
|
||||||
|
|
||||||
## Wildcards In Comparisons
|
|
||||||
|
|
||||||
The `x`, `X`, and `*` characters can be used as a wildcard character. This works
|
|
||||||
for all comparison operators. When used on the `=` operator it falls
|
|
||||||
back to the pack level comparison (see tilde below). For example,
|
|
||||||
|
|
||||||
* `1.2.x` is equivalent to `>= 1.2.0, < 1.3.0`
|
|
||||||
* `>= 1.2.x` is equivalent to `>= 1.2.0`
|
|
||||||
* `<= 2.x` is equivalent to `<= 3`
|
|
||||||
* `*` is equivalent to `>= 0.0.0`
|
|
||||||
|
|
||||||
## Tilde Range Comparisons (Patch)
|
|
||||||
|
|
||||||
The tilde (`~`) comparison operator is for patch level ranges when a minor
|
|
||||||
version is specified and major level changes when the minor number is missing.
|
|
||||||
For example,
|
|
||||||
|
|
||||||
* `~1.2.3` is equivalent to `>= 1.2.3, < 1.3.0`
|
|
||||||
* `~1` is equivalent to `>= 1, < 2`
|
|
||||||
* `~2.3` is equivalent to `>= 2.3, < 2.4`
|
|
||||||
* `~1.2.x` is equivalent to `>= 1.2.0, < 1.3.0`
|
|
||||||
* `~1.x` is equivalent to `>= 1, < 2`
|
|
||||||
|
|
||||||
## Caret Range Comparisons (Major)
|
|
||||||
|
|
||||||
The caret (`^`) comparison operator is for major level changes. This is useful
|
|
||||||
when comparisons of API versions as a major change is API breaking. For example,
|
|
||||||
|
|
||||||
* `^1.2.3` is equivalent to `>= 1.2.3, < 2.0.0`
|
|
||||||
* `^1.2.x` is equivalent to `>= 1.2.0, < 2.0.0`
|
|
||||||
* `^2.3` is equivalent to `>= 2.3, < 3`
|
|
||||||
* `^2.x` is equivalent to `>= 2.0.0, < 3`
|
|
||||||
|
|
||||||
# Validation
|
|
||||||
|
|
||||||
In addition to testing a version against a constraint, a version can be validated
|
|
||||||
against a constraint. When validation fails a slice of errors containing why a
|
|
||||||
version didn't meet the constraint is returned. For example,
|
|
||||||
|
|
||||||
```go
|
|
||||||
c, err := semver.NewConstraint("<= 1.2.3, >= 1.4")
|
|
||||||
if err != nil {
|
|
||||||
// Handle constraint not being parseable.
|
|
||||||
}
|
|
||||||
|
|
||||||
v, _ := semver.NewVersion("1.3")
|
|
||||||
if err != nil {
|
|
||||||
// Handle version not being parseable.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate a version against a constraint.
|
|
||||||
a, msgs := c.Validate(v)
|
|
||||||
// a is false
|
|
||||||
for _, m := range msgs {
|
|
||||||
fmt.Println(m)
|
|
||||||
|
|
||||||
// Loops over the errors which would read
|
|
||||||
// "1.3 is greater than 1.2.3"
|
|
||||||
// "1.3 is less than 1.4"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# Contribute
|
|
||||||
|
|
||||||
If you find an issue or want to contribute please file an [issue](https://github.com/Masterminds/semver/issues)
|
|
||||||
or [create a pull request](https://github.com/Masterminds/semver/pulls).
|
|
44
vendor/github.com/Masterminds/semver/appveyor.yml
generated
vendored
44
vendor/github.com/Masterminds/semver/appveyor.yml
generated
vendored
@@ -1,44 +0,0 @@
|
|||||||
version: build-{build}.{branch}
|
|
||||||
|
|
||||||
clone_folder: C:\gopath\src\github.com\Masterminds\semver
|
|
||||||
shallow_clone: true
|
|
||||||
|
|
||||||
environment:
|
|
||||||
GOPATH: C:\gopath
|
|
||||||
|
|
||||||
platform:
|
|
||||||
- x64
|
|
||||||
|
|
||||||
install:
|
|
||||||
- go version
|
|
||||||
- go env
|
|
||||||
- go get -u gopkg.in/alecthomas/gometalinter.v1
|
|
||||||
- set PATH=%PATH%;%GOPATH%\bin
|
|
||||||
- gometalinter.v1.exe --install
|
|
||||||
|
|
||||||
build_script:
|
|
||||||
- go install -v ./...
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- "gometalinter.v1 \
|
|
||||||
--disable-all \
|
|
||||||
--enable deadcode \
|
|
||||||
--severity deadcode:error \
|
|
||||||
--enable gofmt \
|
|
||||||
--enable gosimple \
|
|
||||||
--enable ineffassign \
|
|
||||||
--enable misspell \
|
|
||||||
--enable vet \
|
|
||||||
--tests \
|
|
||||||
--vendor \
|
|
||||||
--deadline 60s \
|
|
||||||
./... || exit_code=1"
|
|
||||||
- "gometalinter.v1 \
|
|
||||||
--disable-all \
|
|
||||||
--enable golint \
|
|
||||||
--vendor \
|
|
||||||
--deadline 60s \
|
|
||||||
./... || :"
|
|
||||||
- go test -v
|
|
||||||
|
|
||||||
deploy: off
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user