Коммит
6553cb50e1
|
@ -541,12 +541,12 @@ func testGenerateResponseFile(templFP string, te *templateExecutor, prevGenMap m
|
|||
}
|
||||
|
||||
// format the code
|
||||
codeBytes, err = testFormat(codeBytes)
|
||||
formatted, err := testFormat(codeBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return codeBytes, err
|
||||
}
|
||||
|
||||
return codeBytes, nil
|
||||
return formatted, nil
|
||||
}
|
||||
|
||||
// testFormat takes a string representing golang code and attempts to return a
|
||||
|
@ -555,7 +555,7 @@ func testFormat(code []byte) ([]byte, error) {
|
|||
formatted, err := format.Source(code)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return code, err
|
||||
}
|
||||
|
||||
return formatted, nil
|
||||
|
|
|
@ -68,12 +68,6 @@ func EncodeHTTP{{$binding.Label}}Request(_ context.Context, r *http.Request, req
|
|||
_ = tmp
|
||||
{{- range $field := $binding.Fields }}
|
||||
{{- if eq $field.Location "query"}}
|
||||
{{/*
|
||||
{{- if eq $field.ProtobufLabel "LABEL_REPEATED"}}
|
||||
for _, v := range req.{{$field.CamelName}} {
|
||||
values.Add("{{$field.Name}}", fmt.Sprint(v))
|
||||
}
|
||||
*/}}
|
||||
{{if or (not $field.IsBaseType) $field.Repeated}}
|
||||
tmp, err = json.Marshal(req.{{$field.CamelName}})
|
||||
if err != nil {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
{{ with $templateExecutor := .}}
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -10,24 +9,17 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
//"github.com/lightstep/lightstep-tracer-go"
|
||||
//stdopentracing "github.com/opentracing/opentracing-go"
|
||||
//zipkin "github.com/openzipkin/zipkin-go-opentracing"
|
||||
//appdashot "github.com/sourcegraph/appdash/opentracing"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
//"sourcegraph.com/sourcegraph/appdash"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
//"github.com/go-kit/kit/log"
|
||||
|
||||
// This Service
|
||||
handler "{{$templateExecutor.ImportPath -}} /handlers/server"
|
||||
clientHandler "{{$templateExecutor.ImportPath -}} /handlers/client"
|
||||
grpcclient "{{$templateExecutor.ImportPath -}} /generated/client/grpc"
|
||||
httpclient "{{$templateExecutor.ImportPath -}} /generated/client/http"
|
||||
pb "{{$templateExecutor.PBImportPath -}}"
|
||||
handler "{{.ImportPath -}} /handlers/server"
|
||||
clientHandler "{{.ImportPath -}} /handlers/client"
|
||||
grpcclient "{{.ImportPath -}} /generated/client/grpc"
|
||||
httpclient "{{.ImportPath -}} /generated/client/http"
|
||||
pb "{{.PBImportPath -}}"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -35,73 +27,33 @@ var (
|
|||
_ = strings.Split
|
||||
_ = json.Compact
|
||||
_ = errors.Wrapf
|
||||
_ = pb.Register{{$templateExecutor.Service.GetName}}Server
|
||||
_ = pb.Register{{.Service.GetName}}Server
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
// The addcli presumes no service discovery system, and expects users to
|
||||
// provide the direct address of an addsvc. This presumption is reflected in
|
||||
// the addcli binary and the the client packages: the -transport.addr flags
|
||||
// and various client constructors both expect host:port strings. For an
|
||||
// example service with a client built on top of a service discovery system,
|
||||
// see profilesvc.
|
||||
// provide the direct address of an service. This presumption is reflected in
|
||||
// the cli binary and the the client packages: the -transport.addr flags
|
||||
// and various client constructors both expect host:port strings.
|
||||
|
||||
var (
|
||||
httpAddr = flag.String("http.addr", "", "HTTP address of addsvc")
|
||||
grpcAddr = flag.String("grpc.addr", "", "gRPC (HTTP) address of addsvc")
|
||||
//zipkinAddr = flag.String("zipkin.addr", "", "Enable Zipkin tracing via a Kafka Collector host:port")
|
||||
//appdashAddr = flag.String("appdash.addr", "", "Enable Appdash tracing via an Appdash server host:port")
|
||||
//lightstepToken = flag.String("lightstep.token", "", "Enable LightStep tracing via a LightStep access token")
|
||||
method = flag.String("method", "{{range $index, $i := $templateExecutor.Service.Methods}}{{if $index}}{{else}}{{ToLower $i.GetName}}{{end}}{{end}}", "{{range $index, $i := $templateExecutor.Service.Methods}}{{if $index}},{{end}}{{ToLower $i.GetName}}{{end}}")
|
||||
grpcAddr = flag.String("grpc.addr", ":5040", "gRPC (HTTP) address of addsvc")
|
||||
method = flag.String("method", "{{range $index, $i := .Service.Methods}}{{if $index}}{{else}}{{ToLower $i.GetName}}{{end}}{{end}}", "{{range $index, $i := .Service.Methods}}{{if $index}},{{end}}{{ToLower $i.GetName}}{{end}}")
|
||||
)
|
||||
|
||||
var (
|
||||
{{$templateExecutor.ClientArgs.AllFlags}}
|
||||
{{.ClientArgs.AllFlags}}
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
// This is a demonstration client, which supports multiple tracers.
|
||||
// Your clients will probably just use one tracer.
|
||||
//var tracer stdopentracing.Tracer
|
||||
//{
|
||||
//if *zipkinAddr != "" {
|
||||
//collector, err := zipkin.NewKafkaCollector(
|
||||
//strings.Split(*zipkinAddr, ","),
|
||||
//zipkin.KafkaLogger(log.NewNopLogger()),
|
||||
//)
|
||||
//if err != nil {
|
||||
//fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
//os.Exit(1)
|
||||
//}
|
||||
//tracer, err = zipkin.NewTracer(
|
||||
//zipkin.NewRecorder(collector, false, "localhost:8000", "addcli"),
|
||||
//)
|
||||
//if err != nil {
|
||||
//fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
//os.Exit(1)
|
||||
//}
|
||||
//} else if *appdashAddr != "" {
|
||||
//tracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr))
|
||||
//} else if *lightstepToken != "" {
|
||||
//tracer = lightstep.NewTracer(lightstep.Options{
|
||||
//AccessToken: *lightstepToken,
|
||||
//})
|
||||
//defer lightstep.FlushLightStepTracer(tracer)
|
||||
//} else {
|
||||
//tracer = stdopentracing.GlobalTracer() // no-op
|
||||
//}
|
||||
//}
|
||||
|
||||
// This is a demonstration client, which supports multiple transports.
|
||||
// Your clients will probably just define and stick with 1 transport.
|
||||
|
||||
var (
|
||||
service handler.Service
|
||||
err error
|
||||
)
|
||||
if *httpAddr != "" {
|
||||
//service, err = httpclient.New(*httpAddr, tracer, log.NewNopLogger())
|
||||
service, err = httpclient.New(*httpAddr)
|
||||
} else if *grpcAddr != "" {
|
||||
conn, err := grpc.Dial(*grpcAddr, grpc.WithInsecure(), grpc.WithTimeout(time.Second))
|
||||
|
@ -110,7 +62,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
defer conn.Close()
|
||||
service = grpcclient.New(conn/*, tracer, log.NewNopLogger()*/)
|
||||
service = grpcclient.New(conn)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "error: no remote address specified\n")
|
||||
os.Exit(1)
|
||||
|
@ -121,33 +73,33 @@ func main() {
|
|||
}
|
||||
|
||||
switch *method {
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
case "{{ToLower $i.GetName}}":
|
||||
{{with index $templateExecutor.ClientArgs.MethArgs $i.GetName}}
|
||||
var err error
|
||||
{{.MarshalFlags}}
|
||||
{{- end}}
|
||||
request, err := clientHandler.{{$i.GetName}}({{with index $templateExecutor.ClientArgs.MethArgs $i.GetName}}{{.CallArgs}}{{end}})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error calling clientHandler.{{$i.GetName}}: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
v, err := service.{{$i.GetName}}(context.Background(), request)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error calling service.{{$i.GetName}}: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("Client Requested with:")
|
||||
fmt.Println({{with index $templateExecutor.ClientArgs.MethArgs $i.GetName}}{{.CallArgs}}{{end}})
|
||||
fmt.Println("Server Responded with:")
|
||||
fmt.Println(v)
|
||||
{{end}}
|
||||
{{ with $tE := .}}
|
||||
{{range $i := $tE.Service.Methods}}
|
||||
case "{{ToLower $i.GetName}}":
|
||||
{{- with index $tE.ClientArgs.MethArgs $i.GetName -}}
|
||||
var err error
|
||||
{{.MarshalFlags}}
|
||||
{{- end}}
|
||||
request, err := clientHandler.{{$i.GetName}}({{with index $tE.ClientArgs.MethArgs $i.GetName}}{{.CallArgs}}{{end}})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error calling clientHandler.{{$i.GetName}}: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
v, err := service.{{$i.GetName}}(context.Background(), request)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error calling service.{{$i.GetName}}: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("Client Requested with:")
|
||||
fmt.Println({{with index $tE.ClientArgs.MethArgs $i.GetName}}{{.CallArgs}}{{end}})
|
||||
fmt.Println("Server Responded with:")
|
||||
fmt.Println(v)
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "error: invalid method %q\n", method)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
{{- end}}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
{{ with $templateExecutor := .}}
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -9,42 +8,28 @@ import (
|
|||
"net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
//"strings"
|
||||
"syscall"
|
||||
//"time"
|
||||
|
||||
// 3d Party
|
||||
//lightstep "github.com/lightstep/lightstep-tracer-go"
|
||||
//stdopentracing "github.com/opentracing/opentracing-go"
|
||||
//zipkin "github.com/openzipkin/zipkin-go-opentracing"
|
||||
//stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||
//appdashot "github.com/sourcegraph/appdash/opentracing"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
//"sourcegraph.com/sourcegraph/appdash"
|
||||
|
||||
// Go Kit
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
//"github.com/go-kit/kit/metrics"
|
||||
//"github.com/go-kit/kit/metrics/prometheus"
|
||||
//"github.com/go-kit/kit/tracing/opentracing"
|
||||
|
||||
// This Service
|
||||
handler "{{$templateExecutor.ImportPath -}} /handlers/server"
|
||||
svc "{{$templateExecutor.ImportPath -}} /generated"
|
||||
pb "{{$templateExecutor.PBImportPath -}}"
|
||||
handler "{{.ImportPath -}} /handlers/server"
|
||||
svc "{{.ImportPath -}} /generated"
|
||||
pb "{{.PBImportPath -}}"
|
||||
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
debugAddr = flag.String("debug.addr", ":8080", "Debug and metrics listen address")
|
||||
httpAddr = flag.String("http.addr", ":8081", "HTTP listen address")
|
||||
grpcAddr = flag.String("grpc.addr", ":8082", "gRPC (HTTP) listen address")
|
||||
//zipkinAddr = flag.String("zipkin.addr", "", "Enable Zipkin tracing via a Kafka server host:port")
|
||||
//appdashAddr = flag.String("appdash.addr", "", "Enable Appdash tracing via an Appdash server host:port")
|
||||
//lightstepToken = flag.String("lightstep.token", "", "Enable LightStep tracing via a LightStep access token")
|
||||
debugAddr = flag.String("debug.addr", ":5060", "Debug and metrics listen address")
|
||||
httpAddr = flag.String("http.addr", ":5050", "HTTP listen address")
|
||||
grpcAddr = flag.String("grpc.addr", ":5040", "gRPC (HTTP) listen address")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
|
@ -58,98 +43,25 @@ func main() {
|
|||
logger.Log("msg", "hello")
|
||||
defer logger.Log("msg", "goodbye")
|
||||
|
||||
/*
|
||||
// Metrics domain.
|
||||
var ints, chars metrics.Counter
|
||||
{
|
||||
// Business level metrics.
|
||||
ints = prometheus.NewCounter(stdprometheus.CounterOpts{
|
||||
Namespace: "svc",
|
||||
Name: "integers_summed",
|
||||
Help: "Total count of integers summed via the Sum method.",
|
||||
}, []string{})
|
||||
chars = prometheus.NewCounter(stdprometheus.CounterOpts{
|
||||
Namespace: "svc",
|
||||
Name: "characters_concatenated",
|
||||
Help: "Total count of characters concatenated via the Concat method.",
|
||||
}, []string{})
|
||||
}
|
||||
var duration metrics.TimeHistogram
|
||||
{
|
||||
// Transport level metrics.
|
||||
duration = metrics.NewTimeHistogram(time.Nanosecond, prometheus.NewSummary(stdprometheus.SummaryOpts{
|
||||
Namespace: "svc",
|
||||
Name: "request_duration_ns",
|
||||
Help: "Request duration in nanoseconds.",
|
||||
}, []string{"method", "success"}))
|
||||
}
|
||||
*/
|
||||
// Tracing domain.
|
||||
/*
|
||||
var tracer stdopentracing.Tracer
|
||||
{
|
||||
if *zipkinAddr != "" {
|
||||
logger := log.NewContext(logger).With("tracer", "Zipkin")
|
||||
logger.Log("addr", *zipkinAddr)
|
||||
collector, err := zipkin.NewKafkaCollector(
|
||||
strings.Split(*zipkinAddr, ","),
|
||||
zipkin.KafkaLogger(logger),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Log("err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tracer, err = zipkin.NewTracer(
|
||||
zipkin.NewRecorder(collector, false, "localhost:80", "svc"),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Log("err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else if *appdashAddr != "" {
|
||||
logger := log.NewContext(logger).With("tracer", "Appdash")
|
||||
logger.Log("addr", *appdashAddr)
|
||||
tracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr))
|
||||
} else if *lightstepToken != "" {
|
||||
logger := log.NewContext(logger).With("tracer", "LightStep")
|
||||
logger.Log() // probably don't want to print out the token :)
|
||||
tracer = lightstep.NewTracer(lightstep.Options{
|
||||
AccessToken: *lightstepToken,
|
||||
})
|
||||
defer lightstep.FlushLightStepTracer(tracer)
|
||||
} else {
|
||||
logger := log.NewContext(logger).With("tracer", "none")
|
||||
logger.Log()
|
||||
tracer = stdopentracing.GlobalTracer() // no-op
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Business domain.
|
||||
var service handler.Service
|
||||
{
|
||||
service = handler.NewService()
|
||||
//service = handler.ServiceLoggingMiddleware(logger)(service)
|
||||
//service = handler.ServiceInstrumentingMiddleware(ints, chars)(service)
|
||||
// add service logging and metrics here
|
||||
}
|
||||
|
||||
// Endpoint domain.
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods}}
|
||||
var {{ToLower $i.GetName}}Endpoint endpoint.Endpoint
|
||||
{
|
||||
//{{ToLower $i.GetName}}Duration := duration.With(metrics.Field{Key: "method", Value: "{{$i.GetName}}})"
|
||||
//{{ToLower $i.GetName}}Logger := log.NewContext(logger).With("method", "{{$i.GetName}})")
|
||||
|
||||
{{ToLower $i.GetName}}Endpoint = svc.Make{{$i.GetName}}Endpoint(service)
|
||||
//{{ToLower $i.GetName}}Endpoint = opentracing.TraceServer(tracer, "{{$i.GetName}})")({{ToLower $i.GetName}}Endpoint)
|
||||
//{{ToLower $i.GetName}}Endpoint = svc.EndpointInstrumentingMiddleware({{ToLower $i.GetName}}Duration)({{ToLower $i.GetName}}Endpoint)
|
||||
//{{ToLower $i.GetName}}Endpoint = svc.EndpointLoggingMiddleware({{ToLower $i.GetName}}Logger)({{ToLower $i.GetName}}Endpoint)
|
||||
// Add endpoint tracing, instrumentation and logging here
|
||||
}
|
||||
{{end}}
|
||||
endpoints := svc.Endpoints{
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods -}}
|
||||
{{$i.GetName}}Endpoint: {{ToLower $i.GetName}}Endpoint,
|
||||
{{- end}}
|
||||
{{end}}
|
||||
}
|
||||
|
||||
// Mechanical domain.
|
||||
|
@ -173,7 +85,6 @@ func main() {
|
|||
m.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
|
||||
m.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
|
||||
m.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
|
||||
//m.Handle("/metrics", stdprometheus.Handler())
|
||||
|
||||
logger.Log("addr", *debugAddr)
|
||||
errc <- http.ListenAndServe(*debugAddr, m)
|
||||
|
@ -182,7 +93,6 @@ func main() {
|
|||
// HTTP transport.
|
||||
go func() {
|
||||
logger := log.NewContext(logger).With("transport", "HTTP")
|
||||
//h := svc.MakeHTTPHandler(ctx, endpoints, tracer, logger)
|
||||
h := svc.MakeHTTPHandler(ctx, endpoints, logger)
|
||||
logger.Log("addr", *httpAddr)
|
||||
errc <- http.ListenAndServe(*httpAddr, h)
|
||||
|
@ -198,9 +108,9 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
srv := svc.MakeGRPCServer(ctx, endpoints/*, tracer, logger*/)
|
||||
srv := svc.MakeGRPCServer(ctx, endpoints)
|
||||
s := grpc.NewServer()
|
||||
pb.Register{{$templateExecutor.Service.GetName}}Server(s, srv)
|
||||
pb.Register{{.Service.GetName}}Server(s, srv)
|
||||
|
||||
logger.Log("addr", *grpcAddr)
|
||||
errc <- s.Serve(ln)
|
||||
|
@ -209,4 +119,3 @@ func main() {
|
|||
// Run!
|
||||
logger.Log("exit", <-errc)
|
||||
}
|
||||
{{- end}}
|
||||
|
|
|
@ -1,64 +1,45 @@
|
|||
{{ with $templateExecutor := .}}
|
||||
// Package grpc provides a gRPC client for the add service.
|
||||
// Package grpc provides a gRPC client for the {{.Service.GetName}} service.
|
||||
package grpc
|
||||
|
||||
import (
|
||||
//"time"
|
||||
|
||||
//jujuratelimit "github.com/juju/ratelimit"
|
||||
//stdopentracing "github.com/opentracing/opentracing-go"
|
||||
//"github.com/sony/gobreaker"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
//"github.com/go-kit/kit/circuitbreaker"
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
//"github.com/go-kit/kit/log"
|
||||
//"github.com/go-kit/kit/ratelimit"
|
||||
//"github.com/go-kit/kit/tracing/opentracing"
|
||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||
|
||||
// This Service
|
||||
handler "{{$templateExecutor.ImportPath -}} /handlers/server"
|
||||
svc "{{$templateExecutor.ImportPath -}} /generated"
|
||||
pb "{{$templateExecutor.PBImportPath -}}"
|
||||
handler "{{.ImportPath -}} /handlers/server"
|
||||
svc "{{.ImportPath -}} /generated"
|
||||
pb "{{.PBImportPath -}}"
|
||||
)
|
||||
|
||||
// New returns an AddService backed by a gRPC client connection. It is the
|
||||
// New returns an service backed by a gRPC client connection. It is the
|
||||
// responsibility of the caller to dial, and later close, the connection.
|
||||
func New(conn *grpc.ClientConn/*, tracer stdopentracing.Tracer, logger log.Logger*/) handler.Service {
|
||||
// We construct a single ratelimiter middleware, to limit the total outgoing
|
||||
// QPS from this client to all methods on the remote instance. We also
|
||||
// construct per-endpoint circuitbreaker middlewares to demonstrate how
|
||||
// that's done, although they could easily be combined into a single breaker
|
||||
// for the entire remote instance, too.
|
||||
func New(conn *grpc.ClientConn) handler.Service {
|
||||
//options := []grpctransport.ServerOption{
|
||||
//grpctransport.ServerBefore(),
|
||||
//}
|
||||
|
||||
//limiter := ratelimit.NewTokenBucketLimiter(jujuratelimit.NewBucketWithRate(100, 100))
|
||||
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
var {{ToLower $i.GetName}}Endpoint endpoint.Endpoint
|
||||
{
|
||||
{{ToLower $i.GetName}}Endpoint = grpctransport.NewClient(
|
||||
conn,
|
||||
"{{TrimPrefix $templateExecutor.Service.FullyQualifiedName "."}}",
|
||||
"{{$i.GetName}}",
|
||||
svc.EncodeGRPC{{$i.GetName}}Request,
|
||||
svc.DecodeGRPC{{$i.GetName}}Response,
|
||||
pb.{{GoName $i.ResponseType.GetName}}{},
|
||||
//grpctransport.ClientBefore(opentracing.FromGRPCRequest(tracer, "{{$i.GetName}}", logger)),
|
||||
).Endpoint()
|
||||
//{{ToLower $i.GetName}}Endpoint = opentracing.TraceClient(tracer, "{{$i.GetName}}")({{ToLower $i.GetName}}Endpoint)
|
||||
//{{ToLower $i.GetName}}Endpoint = limiter({{ToLower $i.GetName}}Endpoint)
|
||||
//{{ToLower $i.GetName}}Endpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{
|
||||
//Name: "{{$i.GetName}}",
|
||||
//Timeout: 30 * time.Second,
|
||||
//}))({{ToLower $i.GetName}}Endpoint)
|
||||
}
|
||||
{{end}}
|
||||
{{- with $tE := .}}
|
||||
{{- range $i := $tE.Service.Methods}}
|
||||
var {{ToLower $i.GetName}}Endpoint endpoint.Endpoint
|
||||
{
|
||||
{{ToLower $i.GetName}}Endpoint = grpctransport.NewClient(
|
||||
conn,
|
||||
"{{TrimPrefix $tE.Service.FullyQualifiedName "."}}",
|
||||
"{{$i.GetName}}",
|
||||
svc.EncodeGRPC{{$i.GetName}}Request,
|
||||
svc.DecodeGRPC{{$i.GetName}}Response,
|
||||
pb.{{GoName $i.ResponseType.GetName}}{},
|
||||
//options...,
|
||||
).Endpoint()
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
return svc.Endpoints{
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods -}}
|
||||
{{$i.GetName}}Endpoint: {{ToLower $i.GetName}}Endpoint,
|
||||
{{- end}}
|
||||
{{end}}
|
||||
}
|
||||
}
|
||||
{{- end}}
|
||||
|
|
|
@ -1,27 +1,17 @@
|
|||
{{ with $templateExecutor := .}}
|
||||
// Package http provides an HTTP client for the add service.
|
||||
// Package http provides an HTTP client for the {{.Service.GetName}} service.
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
//"time"
|
||||
|
||||
//jujuratelimit "github.com/juju/ratelimit"
|
||||
//stdopentracing "github.com/opentracing/opentracing-go"
|
||||
//"github.com/sony/gobreaker"
|
||||
|
||||
//"github.com/go-kit/kit/circuitbreaker"
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
//"github.com/go-kit/kit/log"
|
||||
//"github.com/go-kit/kit/ratelimit"
|
||||
//"github.com/go-kit/kit/tracing/opentracing"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
|
||||
// This Service
|
||||
handler "{{$templateExecutor.ImportPath -}} /handlers/server"
|
||||
svc "{{$templateExecutor.ImportPath -}} /generated"
|
||||
handler "{{.ImportPath -}} /handlers/server"
|
||||
svc "{{.ImportPath -}} /generated"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -29,12 +19,14 @@ var (
|
|||
_ = httptransport.NewClient
|
||||
)
|
||||
|
||||
// New returns an AddService backed by an HTTP server living at the remote
|
||||
// New returns a service backed by an HTTP server living at the remote
|
||||
// instance. We expect instance to come from a service discovery system, so
|
||||
// likely of the form "host:port".
|
||||
|
||||
//func New(instance string, tracer stdopentracing.Tracer, logger log.Logger) (addsvc.Service, error) {
|
||||
func New(instance string) (handler.Service, error) {
|
||||
//options := []httptransport.ServerOption{
|
||||
//httptransport.ServerBefore(),
|
||||
//}
|
||||
|
||||
if !strings.HasPrefix(instance, "http") {
|
||||
instance = "http://" + instance
|
||||
}
|
||||
|
@ -44,44 +36,27 @@ func New(instance string) (handler.Service, error) {
|
|||
}
|
||||
_ = u
|
||||
|
||||
// We construct a single ratelimiter middleware, to limit the total outgoing
|
||||
// QPS from this client to all methods on the remote instance. We also
|
||||
// construct per-endpoint circuitbreaker middlewares to demonstrate how
|
||||
// that's done, although they could easily be combined into a single breaker
|
||||
// for the entire remote instance, too.
|
||||
|
||||
//limiter := ratelimit.NewTokenBucketLimiter(jujuratelimit.NewBucketWithRate(100, 100))
|
||||
|
||||
{{range $method := $templateExecutor.HTTPHelper.Methods}}
|
||||
{{range $binding := $method.Bindings}}
|
||||
var {{$binding.Label}}Endpoint endpoint.Endpoint
|
||||
{
|
||||
{{$binding.Label}}Endpoint = httptransport.NewClient(
|
||||
"{{$binding.Verb}}",
|
||||
copyURL(u, "{{ToLower $binding.BasePath}}"),
|
||||
svc.EncodeHTTP{{$binding.Label}}Request,
|
||||
svc.DecodeHTTP{{$method.Name}}Response,
|
||||
//httptransport.ClientBefore(opentracing.FromHTTPRequest(tracer, "Sum", logger)),
|
||||
).Endpoint()
|
||||
/*
|
||||
sumEndpoint = opentracing.TraceClient(tracer, "Sum")(sumEndpoint)
|
||||
sumEndpoint = limiter(sumEndpoint)
|
||||
sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{
|
||||
Name: "Sum",
|
||||
Timeout: 30 * time.Second,
|
||||
}))(sumEndpoint)
|
||||
*/
|
||||
}
|
||||
|
||||
{{- end}}
|
||||
{{range $method := .HTTPHelper.Methods}}
|
||||
{{range $binding := $method.Bindings}}
|
||||
var {{$binding.Label}}Endpoint endpoint.Endpoint
|
||||
{
|
||||
{{$binding.Label}}Endpoint = httptransport.NewClient(
|
||||
"{{$binding.Verb}}",
|
||||
copyURL(u, "{{ToLower $binding.BasePath}}"),
|
||||
svc.EncodeHTTP{{$binding.Label}}Request,
|
||||
svc.DecodeHTTP{{$method.Name}}Response,
|
||||
//options...,
|
||||
).Endpoint()
|
||||
}
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
|
||||
return svc.Endpoints{
|
||||
{{range $method := $templateExecutor.HTTPHelper.Methods}}
|
||||
{{range $binding := $method.Bindings -}}
|
||||
{{$method.Name}}Endpoint: {{$binding.Label}}Endpoint,
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
{{range $method := .HTTPHelper.Methods -}}
|
||||
{{range $binding := $method.Bindings -}}
|
||||
{{$method.Name}}Endpoint: {{$binding.Label}}Endpoint,
|
||||
{{end}}
|
||||
{{- end}}
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -91,4 +66,3 @@ func copyURL(base *url.URL, path string) *url.URL {
|
|||
return &next
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
|
|
@ -6,14 +6,9 @@ package svc
|
|||
// formats. It also includes endpoint middlewares.
|
||||
|
||||
import (
|
||||
//_ "fmt"
|
||||
//_ "time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
//_ "github.com/go-kit/kit/log"
|
||||
//_ "github.com/go-kit/kit/metrics"
|
||||
|
||||
handler "{{.ImportPath -}} /handlers/server"
|
||||
pb "{{.PBImportPath -}}"
|
||||
|
@ -63,41 +58,3 @@ func Make{{$i.GetName}}Endpoint(s handler.Service) endpoint.Endpoint {
|
|||
}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
|
||||
// MIDDLE WARE
|
||||
|
||||
|
||||
// EndpointInstrumentingMiddleware returns an endpoint middleware that records
|
||||
// the duration of each invocation to the passed histogram. The middleware adds
|
||||
// a single field: "success", which is "true" if no error is returned, and
|
||||
// "false" otherwise.
|
||||
//func EndpointInstrumentingMiddleware(duration metrics.TimeHistogram) endpoint.Middleware {
|
||||
//return func(next endpoint.Endpoint) endpoint.Endpoint {
|
||||
//return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
||||
|
||||
//defer func(begin time.Time) {
|
||||
//f := metrics.Field{Key: "success", Value: fmt.Sprint(err == nil)}
|
||||
//duration.With(f).Observe(time.Since(begin))
|
||||
//}(time.Now())
|
||||
//return next(ctx, request)
|
||||
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
||||
// EndpointLoggingMiddleware returns an endpoint middleware that logs the
|
||||
// duration of each invocation, and the resulting error, if any.
|
||||
//func EndpointLoggingMiddleware(logger log.Logger) endpoint.Middleware {
|
||||
//return func(next endpoint.Endpoint) endpoint.Endpoint {
|
||||
//return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
||||
|
||||
//defer func(begin time.Time) {
|
||||
//logger.Log("error", err, "took", time.Since(begin))
|
||||
//}(time.Now())
|
||||
//return next(ctx, request)
|
||||
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
package svc
|
||||
|
||||
// This file contains the Service definition, and a basic service
|
||||
// implementation. It also includes service middlewares.
|
||||
|
||||
import (
|
||||
//_ "errors"
|
||||
//_ "time"
|
||||
|
||||
//_ "golang.org/x/net/context"
|
||||
|
||||
//_ "github.com/go-kit/kit/log"
|
||||
//_ "github.com/go-kit/kit/metrics"
|
||||
|
||||
//pb "{{.PBImportPath -}} "
|
||||
)
|
||||
|
||||
// Middleware describes a service (as opposed to endpoint) middleware.
|
||||
//type Middleware func(Service) Service
|
||||
|
||||
// ServiceLoggingMiddleware returns a service middleware that logs the
|
||||
// parameters and result of each method invocation.
|
||||
//func ServiceLoggingMiddleware(logger log.Logger) Middleware {
|
||||
//return func(next Service) Service {
|
||||
//return serviceLoggingMiddleware{
|
||||
//logger: logger,
|
||||
//next: next,
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
||||
//type serviceLoggingMiddleware struct {
|
||||
//logger log.Logger
|
||||
//next Service
|
||||
//}
|
||||
|
||||
//func (mw serviceLoggingMiddleware) Sum(ctx context.Context, a, b int) (v int, err error) {
|
||||
//defer func(begin time.Time) {
|
||||
//mw.logger.Log(
|
||||
//"method", "Sum",
|
||||
//"a", a, "b", b, "result", v, "error", err,
|
||||
//"took", time.Since(begin),
|
||||
//)
|
||||
//}(time.Now())
|
||||
//return mw.next.Sum(ctx, a, b)
|
||||
//}
|
||||
|
||||
//func (mw serviceLoggingMiddleware) Concat(ctx context.Context, a, b string) (v string, err error) {
|
||||
//defer func(begin time.Time) {
|
||||
//mw.logger.Log(
|
||||
//"method", "Concat",
|
||||
//"a", a, "b", b, "result", v, "error", err,
|
||||
//"took", time.Since(begin),
|
||||
//)
|
||||
//}(time.Now())
|
||||
//return mw.next.Concat(ctx, a, b)
|
||||
//}
|
||||
|
||||
// ServiceInstrumentingMiddleware returns a service middleware that instruments
|
||||
// the number of integers summed and characters concatenated over the lifetime of
|
||||
// the service.
|
||||
//func ServiceInstrumentingMiddleware(ints, chars metrics.Counter) Middleware {
|
||||
//return func(next Service) Service {
|
||||
//return serviceInstrumentingMiddleware{
|
||||
//ints: ints,
|
||||
//chars: chars,
|
||||
//next: next,
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
||||
//type serviceInstrumentingMiddleware struct {
|
||||
//ints metrics.Counter
|
||||
//chars metrics.Counter
|
||||
//next Service
|
||||
//}
|
||||
|
||||
//func (mw serviceInstrumentingMiddleware) Sum(ctx context.Context, a, b int) (int, error) {
|
||||
//v, err := mw.next.Sum(ctx, a, b)
|
||||
//mw.ints.Add(uint64(v))
|
||||
//return v, err
|
||||
//}
|
||||
|
||||
//func (mw serviceInstrumentingMiddleware) Concat(ctx context.Context, a, b string) (string, error) {
|
||||
//v, err := mw.next.Concat(ctx, a, b)
|
||||
//mw.chars.Add(uint64(len(v)))
|
||||
//return v, err
|
||||
//}
|
||||
|
||||
// These annoying helper functions are required to translate Go error types to
|
||||
// and from strings, which is the type we use in our IDLs to represent errors.
|
||||
// There is special casing to treat empty strings as nil errors.
|
||||
|
||||
//func str2err(s string) error {
|
||||
//if s == "" {
|
||||
//return nil
|
||||
//}
|
||||
//return errors.New(s)
|
||||
//}
|
||||
|
||||
//func err2str(err error) string {
|
||||
//if err == nil {
|
||||
//return ""
|
||||
//}
|
||||
//return err.Error()
|
||||
//}
|
|
@ -1,49 +1,46 @@
|
|||
{{ with $templateExecutor := .}}
|
||||
package svc
|
||||
|
||||
// This file provides server-side bindings for the gRPC transport.
|
||||
// It utilizes the transport/grpc.Server.
|
||||
|
||||
import (
|
||||
//stdopentracing "github.com/opentracing/opentracing-go"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
//"github.com/go-kit/kit/log"
|
||||
//"github.com/go-kit/kit/tracing/opentracing"
|
||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||
|
||||
// This Service
|
||||
pb "{{$templateExecutor.PBImportPath -}}"
|
||||
pb "{{.PBImportPath -}}"
|
||||
)
|
||||
|
||||
|
||||
// MakeGRPCServer makes a set of endpoints available as a gRPC AddServer.
|
||||
func MakeGRPCServer(ctx context.Context, endpoints Endpoints/*, tracer stdopentracing.Tracer, logger log.Logger*/) pb.{{GoName $templateExecutor.Service.GetName}}Server {
|
||||
// MakeGRPCServer makes a set of endpoints available as a gRPC {{GoName .Service.GetName}}Server.
|
||||
func MakeGRPCServer(ctx context.Context, endpoints Endpoints) pb.{{GoName .Service.GetName}}Server {
|
||||
//options := []grpctransport.ServerOption{
|
||||
//grpctransport.ServerErrorLogger(logger),
|
||||
// grpctransport.ServiceBefore()
|
||||
//}
|
||||
return &grpcServer{
|
||||
// {{ ToLower $templateExecutor.Service.GetName }}
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
// {{ ToLower .Service.GetName }}
|
||||
{{range $i := .Service.Methods}}
|
||||
{{ToLower $i.GetName}}: grpctransport.NewServer(
|
||||
ctx,
|
||||
endpoints.{{$i.GetName}}Endpoint,
|
||||
DecodeGRPC{{$i.GetName}}Request,
|
||||
EncodeGRPC{{$i.GetName}}Response,
|
||||
//append(options,grpctransport.ServerBefore(opentracing.FromGRPCRequest(tracer, "{{$i.GetName}}", logger)))...,
|
||||
//options...,
|
||||
),
|
||||
{{- end}}
|
||||
}
|
||||
}
|
||||
|
||||
// grpcServer implements the {{GoName .Service.GetName}}Server interface
|
||||
type grpcServer struct {
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods}}
|
||||
{{ToLower $i.GetName}} grpctransport.Handler
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
// Methods
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
// Methods for grpcServer to implement {{GoName .Service.GetName}}Server interface
|
||||
{{range $i := .Service.Methods}}
|
||||
func (s *grpcServer) {{GoName $i.GetName}}(ctx context.Context, req *pb.{{GoName $i.RequestType.GetName}}) (*pb.{{GoName $i.ResponseType.GetName}}, error) {
|
||||
_, rep, err := s.{{ToLower $i.GetName}}.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
|
@ -54,7 +51,7 @@ func (s *grpcServer) {{GoName $i.GetName}}(ctx context.Context, req *pb.{{GoName
|
|||
{{end}}
|
||||
|
||||
// Server Decode
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods}}
|
||||
// DecodeGRPC{{$i.GetName}}Request is a transport/grpc.DecodeRequestFunc that converts a
|
||||
// gRPC {{ToLower $i.GetName}} request to a user-domain {{ToLower $i.GetName}} request. Primarily useful in a server.
|
||||
func DecodeGRPC{{$i.GetName}}Request(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
|
@ -65,7 +62,7 @@ func DecodeGRPC{{$i.GetName}}Request(_ context.Context, grpcReq interface{}) (in
|
|||
|
||||
|
||||
// Client Decode
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods}}
|
||||
// DecodeGRPC{{$i.GetName}}Response is a transport/grpc.DecodeResponseFunc that converts a
|
||||
// gRPC {{ToLower $i.GetName}} reply to a user-domain {{ToLower $i.GetName}} response. Primarily useful in a client.
|
||||
func DecodeGRPC{{$i.GetName}}Response(_ context.Context, grpcReply interface{}) (interface{}, error) {
|
||||
|
@ -75,7 +72,7 @@ func DecodeGRPC{{$i.GetName}}Response(_ context.Context, grpcReply interface{})
|
|||
{{end}}
|
||||
|
||||
// Server Encode
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods}}
|
||||
// EncodeGRPC{{$i.GetName}}Response is a transport/grpc.EncodeResponseFunc that converts a
|
||||
// user-domain {{ToLower $i.GetName}} response to a gRPC {{ToLower $i.GetName}} reply. Primarily useful in a server.
|
||||
func EncodeGRPC{{$i.GetName}}Response(_ context.Context, response interface{}) (interface{}, error) {
|
||||
|
@ -86,7 +83,7 @@ func EncodeGRPC{{$i.GetName}}Response(_ context.Context, response interface{}) (
|
|||
|
||||
|
||||
// Client Encode
|
||||
{{range $i := $templateExecutor.Service.Methods}}
|
||||
{{range $i := .Service.Methods}}
|
||||
// EncodeGRPC{{$i.GetName}}Request is a transport/grpc.EncodeRequestFunc that converts a
|
||||
// user-domain {{ToLower $i.GetName}} request to a gRPC {{ToLower $i.GetName}} request. Primarily useful in a client.
|
||||
func EncodeGRPC{{$i.GetName}}Request(_ context.Context, request interface{}) (interface{}, error) {
|
||||
|
@ -95,4 +92,3 @@ func EncodeGRPC{{$i.GetName}}Request(_ context.Context, request interface{}) (in
|
|||
}
|
||||
{{end}}
|
||||
|
||||
{{- end}}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
{{ with $templateExecutor := .}}
|
||||
package svc
|
||||
|
||||
// This file provides server-side bindings for the HTTP transport.
|
||||
|
@ -15,17 +14,14 @@ import (
|
|||
"strings"
|
||||
"io"
|
||||
|
||||
//stdopentracing "github.com/opentracing/opentracing-go"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/pkg/errors"
|
||||
//"github.com/go-kit/kit/endpoint"
|
||||
//"github.com/go-kit/kit/tracing/opentracing"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
|
||||
// This service
|
||||
pb "{{$templateExecutor.PBImportPath -}}"
|
||||
pb "{{.PBImportPath -}}"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -34,27 +30,27 @@ var (
|
|||
_ = strconv.Atoi
|
||||
_ = httptransport.NewServer
|
||||
_ = ioutil.NopCloser
|
||||
_ = pb.Register{{$templateExecutor.Service.GetName}}Server
|
||||
_ = pb.Register{{.Service.GetName}}Server
|
||||
_ = io.Copy
|
||||
)
|
||||
|
||||
// MakeHTTPHandler returns a handler that makes a set of endpoints available
|
||||
// on predefined paths.
|
||||
func MakeHTTPHandler(ctx context.Context, endpoints Endpoints, logger log.Logger) http.Handler {
|
||||
//func MakeHTTPHandler(ctx context.Context, endpoints Endpoints, /*tracer stdopentracing.Tracer,*/ logger log.Logger) http.Handler {
|
||||
/*options := []httptransport.ServerOption{
|
||||
httptransport.ServerErrorEncoder(errorEncoder),
|
||||
httptransport.ServerErrorLogger(logger),
|
||||
}*/
|
||||
m := http.NewServeMux()
|
||||
|
||||
{{range $method := $templateExecutor.HTTPHelper.Methods}}
|
||||
{{range $method := .HTTPHelper.Methods}}
|
||||
{{range $binding := $method.Bindings}}
|
||||
m.Handle("{{ToLower $binding.BasePath}}", httptransport.NewServer(
|
||||
ctx,
|
||||
endpoints.{{$method.Name}}Endpoint,
|
||||
HttpDecodeLogger(DecodeHTTP{{$binding.Label}}Request, logger),
|
||||
EncodeHTTPGenericResponse,
|
||||
//options...,
|
||||
))
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
|
@ -76,20 +72,6 @@ func errorEncoder(_ context.Context, err error, w http.ResponseWriter) {
|
|||
code := http.StatusInternalServerError
|
||||
msg := err.Error()
|
||||
|
||||
/*if e, ok := err.(httptransport.Error); ok {
|
||||
msg = e.Err.Error()
|
||||
switch e.Domain {
|
||||
case httptransport.DomainDecode:
|
||||
code = http.StatusBadRequest
|
||||
|
||||
case httptransport.DomainDo:
|
||||
switch e.Err {
|
||||
case ErrTwoZeroes, ErrMaxSizeExceeded, ErrIntOverflow:
|
||||
code = http.StatusBadRequest
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
w.WriteHeader(code)
|
||||
json.NewEncoder(w).Encode(errorWrapper{Error: msg})
|
||||
}
|
||||
|
@ -107,7 +89,7 @@ type errorWrapper struct {
|
|||
}
|
||||
|
||||
// Server Decode
|
||||
{{range $method := $templateExecutor.HTTPHelper.Methods}}
|
||||
{{range $method := .HTTPHelper.Methods}}
|
||||
{{range $binding := $method.Bindings}}
|
||||
|
||||
{{$binding.GenServerDecode}}
|
||||
|
@ -116,7 +98,7 @@ type errorWrapper struct {
|
|||
{{end}}
|
||||
|
||||
// Client Decode
|
||||
{{range $method := $templateExecutor.HTTPHelper.Methods}}
|
||||
{{range $method := .HTTPHelper.Methods}}
|
||||
// DecodeHTTP{{$method.Name}} is a transport/http.DecodeResponseFunc that decodes
|
||||
// a JSON-encoded {{GoName $method.ResponseType}} response from the HTTP response body.
|
||||
// If the response has a non-200 status code, we will interpret that as an
|
||||
|
@ -133,7 +115,7 @@ func DecodeHTTP{{$method.Name}}Response(_ context.Context, r *http.Response) (in
|
|||
{{end}}
|
||||
|
||||
// Client Encode
|
||||
{{range $method := $templateExecutor.HTTPHelper.Methods}}
|
||||
{{range $method := .HTTPHelper.Methods}}
|
||||
{{range $binding := $method.Bindings}}
|
||||
|
||||
{{$binding.GenClientEncode}}
|
||||
|
@ -147,7 +129,6 @@ func EncodeHTTPGenericResponse(_ context.Context, w http.ResponseWriter, respons
|
|||
return json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
{{$templateExecutor.HTTPHelper.PathParamsBuilder}}
|
||||
// Helper functions
|
||||
|
||||
|
||||
{{- end}}
|
||||
{{.HTTPHelper.PathParamsBuilder}}
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -98,7 +98,7 @@ func third_partyGoogleapisGoogleApiAnnotationsPbGotemplate() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/annotations.pb.gotemplate", size: 2514, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/annotations.pb.gotemplate", size: 2514, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func third_partyGoogleapisGoogleApiAnnotationsProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/annotations.proto", size: 927, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/annotations.proto", size: 927, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func third_partyGoogleapisGoogleApiHttpPbGotemplate() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/http.pb.gotemplate", size: 18398, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/http.pb.gotemplate", size: 18398, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ func third_partyGoogleapisGoogleApiHttpProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/http.proto", size: 9887, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/api/http.proto", size: 9887, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ func third_partyGoogleapisGoogleProtobufAnyProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/any.proto", size: 5281, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/any.proto", size: 5281, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func third_partyGoogleapisGoogleProtobufApiProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/api.proto", size: 7122, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/api.proto", size: 7122, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func third_partyGoogleapisGoogleProtobufCompilerPluginProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/compiler/plugin.proto", size: 7655, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/compiler/plugin.proto", size: 7655, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ func third_partyGoogleapisGoogleProtobufDescriptorProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/descriptor.proto", size: 34199, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/descriptor.proto", size: 34199, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ func third_partyGoogleapisGoogleProtobufDurationProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/duration.proto", size: 4057, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/duration.proto", size: 4057, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ func third_partyGoogleapisGoogleProtobufEmptyProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/empty.proto", size: 2467, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/empty.proto", size: 2467, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ func third_partyGoogleapisGoogleProtobufField_maskProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/field_mask.proto", size: 7893, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/field_mask.proto", size: 7893, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ func third_partyGoogleapisGoogleProtobufSource_contextProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/source_context.proto", size: 2308, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/source_context.proto", size: 2308, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ func third_partyGoogleapisGoogleProtobufStructProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/struct.proto", size: 3794, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/struct.proto", size: 3794, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -358,7 +358,7 @@ func third_partyGoogleapisGoogleProtobufTimestampProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/timestamp.proto", size: 4684, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/timestamp.proto", size: 4684, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ func third_partyGoogleapisGoogleProtobufTypeProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/type.proto", size: 5801, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/type.proto", size: 5801, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ func third_partyGoogleapisGoogleProtobufWrappersProto() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/wrappers.proto", size: 3790, mode: os.FileMode(436), modTime: time.Unix(1475942376, 0)}
|
||||
info := bindataFileInfo{name: "third_party/googleapis/google/protobuf/wrappers.proto", size: 3790, mode: os.FileMode(436), modTime: time.Unix(1475601228, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -455,22 +455,22 @@ func AssetNames() []string {
|
|||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"third_party/googleapis/google/api/annotations.pb.gotemplate": third_partyGoogleapisGoogleApiAnnotationsPbGotemplate,
|
||||
"third_party/googleapis/google/api/annotations.proto": third_partyGoogleapisGoogleApiAnnotationsProto,
|
||||
"third_party/googleapis/google/api/http.pb.gotemplate": third_partyGoogleapisGoogleApiHttpPbGotemplate,
|
||||
"third_party/googleapis/google/api/http.proto": third_partyGoogleapisGoogleApiHttpProto,
|
||||
"third_party/googleapis/google/protobuf/any.proto": third_partyGoogleapisGoogleProtobufAnyProto,
|
||||
"third_party/googleapis/google/protobuf/api.proto": third_partyGoogleapisGoogleProtobufApiProto,
|
||||
"third_party/googleapis/google/api/annotations.pb.gotemplate": third_partyGoogleapisGoogleApiAnnotationsPbGotemplate,
|
||||
"third_party/googleapis/google/api/annotations.proto": third_partyGoogleapisGoogleApiAnnotationsProto,
|
||||
"third_party/googleapis/google/api/http.pb.gotemplate": third_partyGoogleapisGoogleApiHttpPbGotemplate,
|
||||
"third_party/googleapis/google/api/http.proto": third_partyGoogleapisGoogleApiHttpProto,
|
||||
"third_party/googleapis/google/protobuf/any.proto": third_partyGoogleapisGoogleProtobufAnyProto,
|
||||
"third_party/googleapis/google/protobuf/api.proto": third_partyGoogleapisGoogleProtobufApiProto,
|
||||
"third_party/googleapis/google/protobuf/compiler/plugin.proto": third_partyGoogleapisGoogleProtobufCompilerPluginProto,
|
||||
"third_party/googleapis/google/protobuf/descriptor.proto": third_partyGoogleapisGoogleProtobufDescriptorProto,
|
||||
"third_party/googleapis/google/protobuf/duration.proto": third_partyGoogleapisGoogleProtobufDurationProto,
|
||||
"third_party/googleapis/google/protobuf/empty.proto": third_partyGoogleapisGoogleProtobufEmptyProto,
|
||||
"third_party/googleapis/google/protobuf/field_mask.proto": third_partyGoogleapisGoogleProtobufField_maskProto,
|
||||
"third_party/googleapis/google/protobuf/source_context.proto": third_partyGoogleapisGoogleProtobufSource_contextProto,
|
||||
"third_party/googleapis/google/protobuf/struct.proto": third_partyGoogleapisGoogleProtobufStructProto,
|
||||
"third_party/googleapis/google/protobuf/timestamp.proto": third_partyGoogleapisGoogleProtobufTimestampProto,
|
||||
"third_party/googleapis/google/protobuf/type.proto": third_partyGoogleapisGoogleProtobufTypeProto,
|
||||
"third_party/googleapis/google/protobuf/wrappers.proto": third_partyGoogleapisGoogleProtobufWrappersProto,
|
||||
"third_party/googleapis/google/protobuf/descriptor.proto": third_partyGoogleapisGoogleProtobufDescriptorProto,
|
||||
"third_party/googleapis/google/protobuf/duration.proto": third_partyGoogleapisGoogleProtobufDurationProto,
|
||||
"third_party/googleapis/google/protobuf/empty.proto": third_partyGoogleapisGoogleProtobufEmptyProto,
|
||||
"third_party/googleapis/google/protobuf/field_mask.proto": third_partyGoogleapisGoogleProtobufField_maskProto,
|
||||
"third_party/googleapis/google/protobuf/source_context.proto": third_partyGoogleapisGoogleProtobufSource_contextProto,
|
||||
"third_party/googleapis/google/protobuf/struct.proto": third_partyGoogleapisGoogleProtobufStructProto,
|
||||
"third_party/googleapis/google/protobuf/timestamp.proto": third_partyGoogleapisGoogleProtobufTimestampProto,
|
||||
"third_party/googleapis/google/protobuf/type.proto": third_partyGoogleapisGoogleProtobufTypeProto,
|
||||
"third_party/googleapis/google/protobuf/wrappers.proto": third_partyGoogleapisGoogleProtobufWrappersProto,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
|
@ -512,16 +512,15 @@ type bintree struct {
|
|||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"third_party": &bintree{nil, map[string]*bintree{
|
||||
"googleapis": &bintree{nil, map[string]*bintree{
|
||||
"google": &bintree{nil, map[string]*bintree{
|
||||
"api": &bintree{nil, map[string]*bintree{
|
||||
"annotations.pb.gotemplate": &bintree{third_partyGoogleapisGoogleApiAnnotationsPbGotemplate, map[string]*bintree{}},
|
||||
"annotations.proto": &bintree{third_partyGoogleapisGoogleApiAnnotationsProto, map[string]*bintree{}},
|
||||
"http.pb.gotemplate": &bintree{third_partyGoogleapisGoogleApiHttpPbGotemplate, map[string]*bintree{}},
|
||||
"http.proto": &bintree{third_partyGoogleapisGoogleApiHttpProto, map[string]*bintree{}},
|
||||
"annotations.proto": &bintree{third_partyGoogleapisGoogleApiAnnotationsProto, map[string]*bintree{}},
|
||||
"http.pb.gotemplate": &bintree{third_partyGoogleapisGoogleApiHttpPbGotemplate, map[string]*bintree{}},
|
||||
"http.proto": &bintree{third_partyGoogleapisGoogleApiHttpProto, map[string]*bintree{}},
|
||||
}},
|
||||
"protobuf": &bintree{nil, map[string]*bintree{
|
||||
"any.proto": &bintree{third_partyGoogleapisGoogleProtobufAnyProto, map[string]*bintree{}},
|
||||
|
@ -529,15 +528,15 @@ var _bintree = &bintree{nil, map[string]*bintree{
|
|||
"compiler": &bintree{nil, map[string]*bintree{
|
||||
"plugin.proto": &bintree{third_partyGoogleapisGoogleProtobufCompilerPluginProto, map[string]*bintree{}},
|
||||
}},
|
||||
"descriptor.proto": &bintree{third_partyGoogleapisGoogleProtobufDescriptorProto, map[string]*bintree{}},
|
||||
"duration.proto": &bintree{third_partyGoogleapisGoogleProtobufDurationProto, map[string]*bintree{}},
|
||||
"empty.proto": &bintree{third_partyGoogleapisGoogleProtobufEmptyProto, map[string]*bintree{}},
|
||||
"field_mask.proto": &bintree{third_partyGoogleapisGoogleProtobufField_maskProto, map[string]*bintree{}},
|
||||
"descriptor.proto": &bintree{third_partyGoogleapisGoogleProtobufDescriptorProto, map[string]*bintree{}},
|
||||
"duration.proto": &bintree{third_partyGoogleapisGoogleProtobufDurationProto, map[string]*bintree{}},
|
||||
"empty.proto": &bintree{third_partyGoogleapisGoogleProtobufEmptyProto, map[string]*bintree{}},
|
||||
"field_mask.proto": &bintree{third_partyGoogleapisGoogleProtobufField_maskProto, map[string]*bintree{}},
|
||||
"source_context.proto": &bintree{third_partyGoogleapisGoogleProtobufSource_contextProto, map[string]*bintree{}},
|
||||
"struct.proto": &bintree{third_partyGoogleapisGoogleProtobufStructProto, map[string]*bintree{}},
|
||||
"timestamp.proto": &bintree{third_partyGoogleapisGoogleProtobufTimestampProto, map[string]*bintree{}},
|
||||
"type.proto": &bintree{third_partyGoogleapisGoogleProtobufTypeProto, map[string]*bintree{}},
|
||||
"wrappers.proto": &bintree{third_partyGoogleapisGoogleProtobufWrappersProto, map[string]*bintree{}},
|
||||
"struct.proto": &bintree{third_partyGoogleapisGoogleProtobufStructProto, map[string]*bintree{}},
|
||||
"timestamp.proto": &bintree{third_partyGoogleapisGoogleProtobufTimestampProto, map[string]*bintree{}},
|
||||
"type.proto": &bintree{third_partyGoogleapisGoogleProtobufTypeProto, map[string]*bintree{}},
|
||||
"wrappers.proto": &bintree{third_partyGoogleapisGoogleProtobufWrappersProto, map[string]*bintree{}},
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
|
@ -590,3 +589,4 @@ func _filePath(dir, name string) string {
|
|||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче