diff --git a/go.mod b/go.mod index 6ed25f9..82a25b1 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,11 @@ require ( github.com/Songmu/prompter v0.2.0 github.com/alioygur/godash v0.0.0-20160919141744-af6b3da41c5a github.com/emicklei/proto v1.6.13 - github.com/prometheus/common v0.4.0 github.com/sirupsen/logrus v1.4.2 github.com/spf13/afero v1.2.2 github.com/spf13/cobra v0.0.4 github.com/spf13/viper v1.4.0 golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 // indirect - golang.org/x/net v0.0.0-20190603091049-60506f45cf65 // indirect golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed // indirect golang.org/x/text v0.3.2 // indirect golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468 diff --git a/go.sum b/go.sum index 35e8a3a..4cbd5ba 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,5 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Songmu/prompter v0.2.0 h1:ukZciW4j83c9oY7PjS6KmETrDERkyooeyqeCK+eHBmw= @@ -21,6 +22,7 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= @@ -29,8 +31,10 @@ github.com/emicklei/proto v1.6.13/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -39,6 +43,7 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -57,8 +62,10 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -73,6 +80,7 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= @@ -106,6 +114,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= @@ -130,7 +139,6 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -159,12 +167,15 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468 h1:fTfk6GjmihJbK0mSUFgPPgYpsdmApQ86Mcd4GuKax9U= golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0 h1:G+97AoqBnmZIT91cLG/EkCoK9NSelj64P8bOHHNmGn0= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= diff --git a/test_dir/gk.json b/test_dir/gk.json deleted file mode 100755 index 62e070b..0000000 --- a/test_dir/gk.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "service":{ - "path":"{{toSnakeCase .ServiceName}}/pkg/service", - "file_name":"service.go", - "interface_name":"{{toUpperFirstCamelCase .ServiceName}}Service", - "struct_name":"stub{{toCamelCase .ServiceName}}Service" - }, - "middleware":{ - "name":"middleware.go" - }, - "endpoints":{ - "path":"{{toSnakeCase .ServiceName}}/pkg/endpoints", - "file_name":"endpoints.go" - }, - "transport":{ - "path":"{{toSnakeCase .ServiceName}}/pkg/{{.TransportType}}", - "file_name":"handler.go" - }, - "cmd":{ - "path":"cmd/{{toSnakeCase .ServiceName}}", - "file_name":"main.go" - }, - "default_transport":"http" -} \ No newline at end of file diff --git a/test_dir/test_grpc/pkg/endpoints/endpoints.go b/test_dir/test_grpc/pkg/endpoints/endpoints.go deleted file mode 100755 index 59c2fad..0000000 --- a/test_dir/test_grpc/pkg/endpoints/endpoints.go +++ /dev/null @@ -1,38 +0,0 @@ -package endpoints - -import ( - "context" - - "github.com/go-kit/kit/endpoint" - "github.com/yiv/gk/test_dir/test_grpc/pkg/service" -) - -// Endpoints collects all of the endpoints that compose an add service. It's -// meant to be used as a helper struct, to collect all of the endpoints into a -// single parameter. - -type Endpoints struct { - FooEndpoint endpoint.Endpoint -} -type FooRequest struct { - S string -} -type FooResponse struct { - Rs string - Err error -} - -func New(svc service.TestGrpcService) (ep Endpoints) { - ep.FooEndpoint = MakeFooEndpoint(svc) - return ep -} - -// MakeFooEndpoint returns an endpoint that invokes Sum on the service. -// Primarily useful in a server. -func MakeFooEndpoint(svc service.TestGrpcService) (ep endpoint.Endpoint) { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(FooRequest) - rs, err := svc.Foo(ctx, req.S) - return FooResponse{Rs: rs, Err: err}, nil - } -} diff --git a/test_dir/test_grpc/pkg/grpc/handler.go b/test_dir/test_grpc/pkg/grpc/handler.go deleted file mode 100755 index 83dff1a..0000000 --- a/test_dir/test_grpc/pkg/grpc/handler.go +++ /dev/null @@ -1,53 +0,0 @@ -package grpc - -import ( - "context" - "errors" - - grpctransport "github.com/go-kit/kit/transport/grpc" - "github.com/yiv/gk/test_dir/test_grpc/pkg/endpoints" - "github.com/yiv/gk/test_dir/test_grpc/pkg/grpc/pb" -) - -type grpcServer struct { - foo grpctransport.Handler -} - -// MakeGRPCServer makes a set of endpoints available as a gRPC server. -func MakeGRPCServer(endpoints endpoints.Endpoints) (req pb.TestGrpcServer) { - req = &grpcServer{ - foo: grpctransport.NewServer( - endpoints.FooEndpoint, - DecodeGRPCFooRequest, - EncodeGRPCFooResponse, - ), - } - return req -} - -// DecodeGRPCFooRequest is a transport/grpc.DecodeRequestFunc that converts a -// gRPC request to a user-domain request. Primarily useful in a server. -// TODO: Do not forget to implement the decoder, you can find an example here : -// https://github.com/go-kit/kit/blob/master/examples/addsvc/transport_grpc.go#L62-L65 -func DecodeGRPCFooRequest(_ context.Context, grpcReq interface{}) (req interface{}, err error) { - err = errors.New("'Foo' Decoder is not impelement") - return req, err -} - -// EncodeGRPCFooResponse is a transport/grpc.EncodeResponseFunc that converts a -// user-domain response to a gRPC reply. Primarily useful in a server. -// TODO: Do not forget to implement the encoder, you can find an example here : -// https://github.com/go-kit/kit/blob/master/examples/addsvc/transport_grpc.go#L62-L65 -func EncodeGRPCFooResponse(_ context.Context, grpcReply interface{}) (res interface{}, err error) { - err = errors.New("'Foo' Encoder is not impelement") - return res, err -} - -func (s *grpcServer) Foo(ctx context.Context, req *pb.FooRequest) (rep *pb.FooReply, err error) { - _, rp, err := s.foo.ServeGRPC(ctx, req) - if err != nil { - return nil, err - } - rep = rp.(*pb.FooReply) - return rep, err -} diff --git a/test_dir/test_grpc/pkg/grpc/pb/compile.sh b/test_dir/test_grpc/pkg/grpc/pb/compile.sh deleted file mode 100755 index 24e4b63..0000000 --- a/test_dir/test_grpc/pkg/grpc/pb/compile.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env sh - -# Install proto3 from source macOS only. -# brew install autoconf automake libtool -# git clone https://github.com/google/protobuf -# ./autogen.sh ; ./configure ; make ; make install -# -# Update protoc Go bindings via -# go get -u github.com/golang/protobuf/{proto,protoc-gen-go} -# -# See also -# https://github.com/grpc/grpc-go/tree/master/examples - -protoc test_grpc.proto --go_out=plugins=grpc:. \ No newline at end of file diff --git a/test_dir/test_grpc/pkg/grpc/pb/test_grpc.pb.go b/test_dir/test_grpc/pkg/grpc/pb/test_grpc.pb.go deleted file mode 100644 index d5b2180..0000000 --- a/test_dir/test_grpc/pkg/grpc/pb/test_grpc.pb.go +++ /dev/null @@ -1,141 +0,0 @@ -// Code generated by protoc-gen-go. -// source: test_grpc.proto -// DO NOT EDIT! - -/* -Package pb is a generated protocol buffer package. - -It is generated from these files: - test_grpc.proto - -It has these top-level messages: - FooRequest - FooReply -*/ -package pb - -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 FooRequest struct { -} - -func (m *FooRequest) Reset() { *m = FooRequest{} } -func (m *FooRequest) String() string { return proto.CompactTextString(m) } -func (*FooRequest) ProtoMessage() {} -func (*FooRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - -type FooReply struct { -} - -func (m *FooReply) Reset() { *m = FooReply{} } -func (m *FooReply) String() string { return proto.CompactTextString(m) } -func (*FooReply) ProtoMessage() {} -func (*FooReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - -func init() { - proto.RegisterType((*FooRequest)(nil), "pb.FooRequest") - proto.RegisterType((*FooReply)(nil), "pb.FooReply") -} - -// 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 TestGrpc service - -type TestGrpcClient interface { - Foo(ctx context.Context, in *FooRequest, opts ...grpc.CallOption) (*FooReply, error) -} - -type testGrpcClient struct { - cc *grpc.ClientConn -} - -func NewTestGrpcClient(cc *grpc.ClientConn) TestGrpcClient { - return &testGrpcClient{cc} -} - -func (c *testGrpcClient) Foo(ctx context.Context, in *FooRequest, opts ...grpc.CallOption) (*FooReply, error) { - out := new(FooReply) - err := grpc.Invoke(ctx, "/pb.TestGrpc/Foo", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for TestGrpc service - -type TestGrpcServer interface { - Foo(context.Context, *FooRequest) (*FooReply, error) -} - -func RegisterTestGrpcServer(s *grpc.Server, srv TestGrpcServer) { - s.RegisterService(&_TestGrpc_serviceDesc, srv) -} - -func _TestGrpc_Foo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(FooRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(TestGrpcServer).Foo(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/pb.TestGrpc/Foo", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TestGrpcServer).Foo(ctx, req.(*FooRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _TestGrpc_serviceDesc = grpc.ServiceDesc{ - ServiceName: "pb.TestGrpc", - HandlerType: (*TestGrpcServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Foo", - Handler: _TestGrpc_Foo_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "test_grpc.proto", -} - -func init() { proto.RegisterFile("test_grpc.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 109 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x49, 0x2d, 0x2e, - 0x89, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2a, 0x48, 0x52, - 0xe2, 0xe1, 0xe2, 0x72, 0xcb, 0xcf, 0x0f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x51, 0xe2, 0xe2, - 0xe2, 0x00, 0xf3, 0x0a, 0x72, 0x2a, 0x8d, 0x0c, 0xb9, 0x38, 0x42, 0x52, 0x8b, 0x4b, 0xdc, 0x8b, - 0x0a, 0x92, 0x85, 0x54, 0xb9, 0x98, 0xdd, 0xf2, 0xf3, 0x85, 0xf8, 0xf4, 0x0a, 0x92, 0xf4, 0x10, - 0xca, 0xa5, 0x78, 0xe0, 0xfc, 0x82, 0x9c, 0x4a, 0x25, 0x86, 0x24, 0x36, 0xb0, 0xb9, 0xc6, 0x80, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x27, 0xba, 0x62, 0xc9, 0x6a, 0x00, 0x00, 0x00, -} diff --git a/test_dir/test_grpc/pkg/grpc/pb/test_grpc.proto b/test_dir/test_grpc/pkg/grpc/pb/test_grpc.proto deleted file mode 100755 index 6721931..0000000 --- a/test_dir/test_grpc/pkg/grpc/pb/test_grpc.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; -package pb; -// The TestGrpc service definition. -service TestGrpc { - rpc Foo (FooRequest) returns (FooReply) {} -} -message FooRequest { -} -message FooReply { -} diff --git a/test_dir/test_grpc/pkg/service/service.go b/test_dir/test_grpc/pkg/service/service.go deleted file mode 100755 index b3a01de..0000000 --- a/test_dir/test_grpc/pkg/service/service.go +++ /dev/null @@ -1,23 +0,0 @@ -package service - -import "context" - -// Implement yor service methods methods. -// e.x: Foo(ctx context.Context,s string)(rs string, err error) -type TestGrpcService interface { - Foo(ctx context.Context, s string) (rs string, err error) -} - -type stubTestGrpcService struct{} - -// Get a new instance of the service. -// If you want to add service middleware this is the place to put them. -func New() (s *stubTestGrpcService) { - s = &stubTestGrpcService{} - return s -} - -// Implement the business logic of Foo -func (te *stubTestGrpcService) Foo(ctx context.Context, s string) (rs string, err error) { - return rs, err -} diff --git a/test_dir/test_http/pkg/endpoints/endpoints.go b/test_dir/test_http/pkg/endpoints/endpoints.go deleted file mode 100755 index b47bab8..0000000 --- a/test_dir/test_http/pkg/endpoints/endpoints.go +++ /dev/null @@ -1,38 +0,0 @@ -package endpoints - -import ( - "context" - - "github.com/go-kit/kit/endpoint" - "github.com/yiv/gk/test_dir/test_http/pkg/service" -) - -// Endpoints collects all of the endpoints that compose an add service. It's -// meant to be used as a helper struct, to collect all of the endpoints into a -// single parameter. - -type Endpoints struct { - FooEndpoint endpoint.Endpoint -} -type FooRequest struct { - S string -} -type FooResponse struct { - Rs string - Err error -} - -func New(svc service.TestHttpService) (ep Endpoints) { - ep.FooEndpoint = MakeFooEndpoint(svc) - return ep -} - -// MakeFooEndpoint returns an endpoint that invokes Sum on the service. -// Primarily useful in a server. -func MakeFooEndpoint(svc service.TestHttpService) (ep endpoint.Endpoint) { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(FooRequest) - rs, err := svc.Foo(ctx, req.S) - return FooResponse{Rs: rs, Err: err}, nil - } -} diff --git a/test_dir/test_http/pkg/http/handler.go b/test_dir/test_http/pkg/http/handler.go deleted file mode 100755 index 92179a6..0000000 --- a/test_dir/test_http/pkg/http/handler.go +++ /dev/null @@ -1,39 +0,0 @@ -package http - -import ( - "context" - "encoding/json" - "net/http" - - httptransport "github.com/go-kit/kit/transport/http" - "github.com/yiv/gk/test_dir/test_http/pkg/endpoints" -) - -// NewHTTPHandler returns a handler that makes a set of endpoints available on -// predefined paths. -func NewHTTPHandler(endpoints endpoints.Endpoints) http.Handler { - m := http.NewServeMux() - m.Handle("/foo", httptransport.NewServer( - endpoints.FooEndpoint, - DecodeFooRequest, - EncodeFooResponse, - )) - return m -} - -// DecodeFooRequest is a transport/http.DecodeRequestFunc that decodes a -// JSON-encoded sum request from the HTTP request body. Primarily useful in a server. -func DecodeFooRequest(_ context.Context, r *http.Request) (req interface{}, err error) { - req = endpoints.FooRequest{} - err = json.NewDecoder(r.Body).Decode(&r) - return req, err -} - -// EncodeFooResponse is a transport/http.EncodeResponseFunc that encodes -// the response as JSON to the response writer. Primarily useful in a server. -func EncodeFooResponse(_ context.Context, w http.ResponseWriter, response interface{}) (err error) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - err = json.NewEncoder(w).Encode(response) - json.NewEncoder(w).Encode(response) - return err -} diff --git a/test_dir/test_http/pkg/service/service.go b/test_dir/test_http/pkg/service/service.go deleted file mode 100755 index b3b3e23..0000000 --- a/test_dir/test_http/pkg/service/service.go +++ /dev/null @@ -1,23 +0,0 @@ -package service - -import "context" - -// Implement yor service methods methods. -// e.x: Foo(ctx context.Context,s string)(rs string, err error) -type TestHttpService interface { - Foo(ctx context.Context, s string) (rs string, err error) -} - -type stubTestHttpService struct{} - -// Get a new instance of the service. -// If you want to add service middleware this is the place to put them. -func New() (s *stubTestHttpService) { - s = &stubTestHttpService{} - return s -} - -// Implement the business logic of Foo -func (te *stubTestHttpService) Foo(ctx context.Context, s string) (rs string, err error) { - return rs, err -} diff --git a/test_dir/test_thrift/pkg/endpoints/endpoints.go b/test_dir/test_thrift/pkg/endpoints/endpoints.go deleted file mode 100755 index 653e953..0000000 --- a/test_dir/test_thrift/pkg/endpoints/endpoints.go +++ /dev/null @@ -1,38 +0,0 @@ -package endpoints - -import ( - "context" - - "github.com/go-kit/kit/endpoint" - "github.com/yiv/gk/test_dir/test_thrift/pkg/service" -) - -// Endpoints collects all of the endpoints that compose an add service. It's -// meant to be used as a helper struct, to collect all of the endpoints into a -// single parameter. - -type Endpoints struct { - FooEndpoint endpoint.Endpoint -} -type FooRequest struct { - S string -} -type FooResponse struct { - Rs string - Err error -} - -func New(svc service.TestThriftService) (ep Endpoints) { - ep.FooEndpoint = MakeFooEndpoint(svc) - return ep -} - -// MakeFooEndpoint returns an endpoint that invokes Sum on the service. -// Primarily useful in a server. -func MakeFooEndpoint(svc service.TestThriftService) (ep endpoint.Endpoint) { - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(FooRequest) - rs, err := svc.Foo(ctx, req.S) - return FooResponse{Rs: rs, Err: err}, nil - } -} diff --git a/test_dir/test_thrift/pkg/service/service.go b/test_dir/test_thrift/pkg/service/service.go deleted file mode 100755 index b0324d1..0000000 --- a/test_dir/test_thrift/pkg/service/service.go +++ /dev/null @@ -1,23 +0,0 @@ -package service - -import "context" - -// Implement yor service methods methods. -// e.x: Foo(ctx context.Context,s string)(rs string, err error) -type TestThriftService interface { - Foo(ctx context.Context, s string) (rs string, err error) -} - -type stubTestThriftService struct{} - -// Get a new instance of the service. -// If you want to add service middleware this is the place to put them. -func New() (s *stubTestThriftService) { - s = &stubTestThriftService{} - return s -} - -// Implement the business logic of Foo -func (te *stubTestThriftService) Foo(ctx context.Context, s string) (rs string, err error) { - return rs, err -} diff --git a/test_dir/test_thrift/pkg/thrift/compile.sh b/test_dir/test_thrift/pkg/thrift/compile.sh deleted file mode 100755 index b4fa7fc..0000000 --- a/test_dir/test_thrift/pkg/thrift/compile.sh +++ /dev/null @@ -1,8 +0,0 @@ -# Install thrift macOs. -# 1. brew install boost -# 2. brew install libevent -# 3. brew install thrift -# For linux see : https://thrift.apache.org/download -thrift -r --gen "go:package_prefix=github.com/yiv/gk/test_dir/test_thrift/pkg/thrift/gen-go/,thrift_import=github.com/apache/thrift/lib/go/thrift" test_thrift.thrift - - diff --git a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/GoUnusedProtection__.go b/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/GoUnusedProtection__.go deleted file mode 100644 index 61bba37..0000000 --- a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/GoUnusedProtection__.go +++ /dev/null @@ -1,6 +0,0 @@ -// Autogenerated by Thrift Compiler (0.10.0) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package test_thrift - -var GoUnusedProtection__ int diff --git a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift-consts.go b/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift-consts.go deleted file mode 100644 index 2fe15c2..0000000 --- a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift-consts.go +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated by Thrift Compiler (0.10.0) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package test_thrift - -import ( - "bytes" - "fmt" - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = bytes.Equal - -func init() { -} diff --git a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift.go b/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift.go deleted file mode 100644 index 87e0ec5..0000000 --- a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift.go +++ /dev/null @@ -1,532 +0,0 @@ -// Autogenerated by Thrift Compiler (0.10.0) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package test_thrift - -import ( - "bytes" - "fmt" - "github.com/apache/thrift/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = bytes.Equal - -type FooReply struct { -} - -func NewFooReply() *FooReply { - return &FooReply{} -} - -func (p *FooReply) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { - break - } - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *FooReply) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("FooReply"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) - } - if p != nil { - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) - } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) - } - return nil -} - -func (p *FooReply) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("FooReply(%+v)", *p) -} - -type FooRequest struct { -} - -func NewFooRequest() *FooRequest { - return &FooRequest{} -} - -func (p *FooRequest) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { - break - } - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *FooRequest) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("FooRequest"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) - } - if p != nil { - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) - } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) - } - return nil -} - -func (p *FooRequest) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("FooRequest(%+v)", *p) -} - -type TestThriftService interface { - // Parameters: - // - Req - Foo(req *FooRequest) (r *FooReply, err error) -} - -type TestThriftServiceClient struct { - Transport thrift.TTransport - ProtocolFactory thrift.TProtocolFactory - InputProtocol thrift.TProtocol - OutputProtocol thrift.TProtocol - SeqId int32 -} - -func NewTestThriftServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *TestThriftServiceClient { - return &TestThriftServiceClient{Transport: t, - ProtocolFactory: f, - InputProtocol: f.GetProtocol(t), - OutputProtocol: f.GetProtocol(t), - SeqId: 0, - } -} - -func NewTestThriftServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *TestThriftServiceClient { - return &TestThriftServiceClient{Transport: t, - ProtocolFactory: nil, - InputProtocol: iprot, - OutputProtocol: oprot, - SeqId: 0, - } -} - -// Parameters: -// - Req -func (p *TestThriftServiceClient) Foo(req *FooRequest) (r *FooReply, err error) { - if err = p.sendFoo(req); err != nil { - return - } - return p.recvFoo() -} - -func (p *TestThriftServiceClient) sendFoo(req *FooRequest) (err error) { - oprot := p.OutputProtocol - if oprot == nil { - oprot = p.ProtocolFactory.GetProtocol(p.Transport) - p.OutputProtocol = oprot - } - p.SeqId++ - if err = oprot.WriteMessageBegin("Foo", thrift.CALL, p.SeqId); err != nil { - return - } - args := TestThriftServiceFooArgs{ - Req: req, - } - if err = args.Write(oprot); err != nil { - return - } - if err = oprot.WriteMessageEnd(); err != nil { - return - } - return oprot.Flush() -} - -func (p *TestThriftServiceClient) recvFoo() (value *FooReply, err error) { - iprot := p.InputProtocol - if iprot == nil { - iprot = p.ProtocolFactory.GetProtocol(p.Transport) - p.InputProtocol = iprot - } - method, mTypeId, seqId, err := iprot.ReadMessageBegin() - if err != nil { - return - } - if method != "Foo" { - err = thrift.NewTApplicationException(thrift.WRONG_METHOD_NAME, "Foo failed: wrong method name") - return - } - if p.SeqId != seqId { - err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Foo failed: out of sequence response") - return - } - if mTypeId == thrift.EXCEPTION { - error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") - var error1 error - error1, err = error0.Read(iprot) - if err != nil { - return - } - if err = iprot.ReadMessageEnd(); err != nil { - return - } - err = error1 - return - } - if mTypeId != thrift.REPLY { - err = thrift.NewTApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "Foo failed: invalid message type") - return - } - result := TestThriftServiceFooResult{} - if err = result.Read(iprot); err != nil { - return - } - if err = iprot.ReadMessageEnd(); err != nil { - return - } - value = result.GetSuccess() - return -} - -type TestThriftServiceProcessor struct { - processorMap map[string]thrift.TProcessorFunction - handler TestThriftService -} - -func (p *TestThriftServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { - p.processorMap[key] = processor -} - -func (p *TestThriftServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { - processor, ok = p.processorMap[key] - return processor, ok -} - -func (p *TestThriftServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { - return p.processorMap -} - -func NewTestThriftServiceProcessor(handler TestThriftService) *TestThriftServiceProcessor { - - self2 := &TestThriftServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} - self2.processorMap["Foo"] = &testThriftServiceProcessorFoo{handler: handler} - return self2 -} - -func (p *TestThriftServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - name, _, seqId, err := iprot.ReadMessageBegin() - if err != nil { - return false, err - } - if processor, ok := p.GetProcessorFunction(name); ok { - return processor.Process(seqId, iprot, oprot) - } - iprot.Skip(thrift.STRUCT) - iprot.ReadMessageEnd() - x3 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) - oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) - x3.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush() - return false, x3 - -} - -type testThriftServiceProcessorFoo struct { - handler TestThriftService -} - -func (p *testThriftServiceProcessorFoo) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := TestThriftServiceFooArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("Foo", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush() - return false, err - } - - iprot.ReadMessageEnd() - result := TestThriftServiceFooResult{} - var retval *FooReply - var err2 error - if retval, err2 = p.handler.Foo(args.Req); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Foo: "+err2.Error()) - oprot.WriteMessageBegin("Foo", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush() - return true, err2 - } else { - result.Success = retval - } - if err2 = oprot.WriteMessageBegin("Foo", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -// HELPER FUNCTIONS AND STRUCTURES - -// Attributes: -// - Req -type TestThriftServiceFooArgs struct { - Req *FooRequest `thrift:"req,1" db:"req" json:"req"` -} - -func NewTestThriftServiceFooArgs() *TestThriftServiceFooArgs { - return &TestThriftServiceFooArgs{} -} - -var TestThriftServiceFooArgs_Req_DEFAULT *FooRequest - -func (p *TestThriftServiceFooArgs) GetReq() *FooRequest { - if !p.IsSetReq() { - return TestThriftServiceFooArgs_Req_DEFAULT - } - return p.Req -} -func (p *TestThriftServiceFooArgs) IsSetReq() bool { - return p.Req != nil -} - -func (p *TestThriftServiceFooArgs) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *TestThriftServiceFooArgs) ReadField1(iprot thrift.TProtocol) error { - p.Req = &FooRequest{} - if err := p.Req.Read(iprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Req), err) - } - return nil -} - -func (p *TestThriftServiceFooArgs) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Foo_args"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) - } - if p != nil { - if err := p.writeField1(oprot); err != nil { - return err - } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) - } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) - } - return nil -} - -func (p *TestThriftServiceFooArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:req: ", p), err) - } - if err := p.Req.Write(oprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Req), err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 1:req: ", p), err) - } - return err -} - -func (p *TestThriftServiceFooArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("TestThriftServiceFooArgs(%+v)", *p) -} - -// Attributes: -// - Success -type TestThriftServiceFooResult struct { - Success *FooReply `thrift:"success,0" db:"success" json:"success,omitempty"` -} - -func NewTestThriftServiceFooResult() *TestThriftServiceFooResult { - return &TestThriftServiceFooResult{} -} - -var TestThriftServiceFooResult_Success_DEFAULT *FooReply - -func (p *TestThriftServiceFooResult) GetSuccess() *FooReply { - if !p.IsSetSuccess() { - return TestThriftServiceFooResult_Success_DEFAULT - } - return p.Success -} -func (p *TestThriftServiceFooResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *TestThriftServiceFooResult) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) - } - - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 0: - if err := p.ReadField0(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) - } - return nil -} - -func (p *TestThriftServiceFooResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = &FooReply{} - if err := p.Success.Read(iprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) - } - return nil -} - -func (p *TestThriftServiceFooResult) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Foo_result"); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) - } - if p != nil { - if err := p.writeField0(oprot); err != nil { - return err - } - } - if err := oprot.WriteFieldStop(); err != nil { - return thrift.PrependError("write field stop error: ", err) - } - if err := oprot.WriteStructEnd(); err != nil { - return thrift.PrependError("write struct stop error: ", err) - } - return nil -} - -func (p *TestThriftServiceFooResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) - } - if err := p.Success.Write(oprot); err != nil { - return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) - } - } - return err -} - -func (p *TestThriftServiceFooResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("TestThriftServiceFooResult(%+v)", *p) -} diff --git a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift_service-remote/test_thrift_service-remote.go b/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift_service-remote/test_thrift_service-remote.go deleted file mode 100755 index 9e6171b..0000000 --- a/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift/test_thrift_service-remote/test_thrift_service-remote.go +++ /dev/null @@ -1,149 +0,0 @@ -// Autogenerated by Thrift Compiler (0.10.0) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package main - -import ( - "flag" - "fmt" - "github.com/apache/thrift/lib/go/thrift" - "github.com/yiv/gk/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift" - "math" - "net" - "net/url" - "os" - "strconv" - "strings" -) - -func Usage() { - fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") - flag.PrintDefaults() - fmt.Fprintln(os.Stderr, "\nFunctions:") - fmt.Fprintln(os.Stderr, " FooReply Foo(FooRequest req)") - fmt.Fprintln(os.Stderr) - os.Exit(0) -} - -func main() { - flag.Usage = Usage - var host string - var port int - var protocol string - var urlString string - var framed bool - var useHttp bool - var parsedUrl url.URL - var trans thrift.TTransport - _ = strconv.Atoi - _ = math.Abs - flag.Usage = Usage - flag.StringVar(&host, "h", "localhost", "Specify host and port") - flag.IntVar(&port, "p", 9090, "Specify port") - flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") - flag.StringVar(&urlString, "u", "", "Specify the url") - flag.BoolVar(&framed, "framed", false, "Use framed transport") - flag.BoolVar(&useHttp, "http", false, "Use http") - flag.Parse() - - if len(urlString) > 0 { - parsedUrl, err := url.Parse(urlString) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - host = parsedUrl.Host - useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" - } else if useHttp { - _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - } - - cmd := flag.Arg(0) - var err error - if useHttp { - trans, err = thrift.NewTHttpClient(parsedUrl.String()) - } else { - portStr := fmt.Sprint(port) - if strings.Contains(host, ":") { - host, portStr, err = net.SplitHostPort(host) - if err != nil { - fmt.Fprintln(os.Stderr, "error with host:", err) - os.Exit(1) - } - } - trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) - if err != nil { - fmt.Fprintln(os.Stderr, "error resolving address:", err) - os.Exit(1) - } - if framed { - trans = thrift.NewTFramedTransport(trans) - } - } - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating transport", err) - os.Exit(1) - } - defer trans.Close() - var protocolFactory thrift.TProtocolFactory - switch protocol { - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - break - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - break - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - break - case "binary", "": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - break - default: - fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) - Usage() - os.Exit(1) - } - client := test_thrift.NewTestThriftServiceClientFactory(trans, protocolFactory) - if err := trans.Open(); err != nil { - fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) - os.Exit(1) - } - - switch cmd { - case "Foo": - if flag.NArg()-1 != 1 { - fmt.Fprintln(os.Stderr, "Foo requires 1 args") - flag.Usage() - } - arg4 := flag.Arg(1) - mbTrans5 := thrift.NewTMemoryBufferLen(len(arg4)) - defer mbTrans5.Close() - _, err6 := mbTrans5.WriteString(arg4) - if err6 != nil { - Usage() - return - } - factory7 := thrift.NewTSimpleJSONProtocolFactory() - jsProt8 := factory7.GetProtocol(mbTrans5) - argvalue0 := test_thrift.NewFooRequest() - err9 := argvalue0.Read(jsProt8) - if err9 != nil { - Usage() - return - } - value0 := argvalue0 - fmt.Print(client.Foo(value0)) - fmt.Print("\n") - break - case "": - Usage() - break - default: - fmt.Fprintln(os.Stderr, "Invalid function ", cmd) - } -} diff --git a/test_dir/test_thrift/pkg/thrift/handler.go b/test_dir/test_thrift/pkg/thrift/handler.go deleted file mode 100755 index ca90576..0000000 --- a/test_dir/test_thrift/pkg/thrift/handler.go +++ /dev/null @@ -1,54 +0,0 @@ -package thrift - -import ( - "context" - "errors" - - "github.com/go-kit/kit/endpoint" - "github.com/yiv/gk/test_dir/test_thrift/pkg/endpoints" - thriftTestThrift "github.com/yiv/gk/test_dir/test_thrift/pkg/thrift/gen-go/test_thrift" -) - -type thriftServer struct { - ctx context.Context - foo endpoint.Endpoint -} - -// MakeThriftHandler makes a set of endpoints available as a thrift server. -func MakeThriftHandler(ctx context.Context, endpoints endpoints.Endpoints) (req thriftTestThrift.TestThriftService) { - req = &thriftServer{ - ctx: ctx, - foo: endpoints.FooEndpoint, - } - return req -} - -// DecodeThriftFooRequest is a func that converts a -// thrift request to a user-domain request. Primarily useful in a server. -// TODO: Do not forget to implement the decoder. -func DecodeThriftFooRequest(r *thriftTestThrift.FooRequest) (req endpoints.FooRequest, err error) { - err = errors.New("'Foo' Decoder is not impelement") - return req, err -} - -// EncodeThriftFooResponse is a func that converts a -// user-domain response to a thrift reply. Primarily useful in a server. -// TODO: Do not forget to implement the encoder. -func EncodeThriftFooResponse(reply interface{}) (rep thriftTestThrift.FooReply, err error) { - err = errors.New("'Foo' Encoder is not impelement") - return rep, err -} - -func (s *thriftServer) Foo(req *thriftTestThrift.FooRequest) (rep *thriftTestThrift.FooReply, err error) { - request, err := DecodeThriftFooRequest(req) - if err != nil { - return nil, err - } - response, err := s.foo(s.ctx, request) - if err != nil { - return nil, err - } - r, err := EncodeThriftFooResponse(response) - rep = &r - return rep, err -} diff --git a/test_dir/test_thrift/pkg/thrift/test_thrift.thrift b/test_dir/test_thrift/pkg/thrift/test_thrift.thrift deleted file mode 100755 index 2df5af7..0000000 --- a/test_dir/test_thrift/pkg/thrift/test_thrift.thrift +++ /dev/null @@ -1,9 +0,0 @@ -struct FooReply{ -} -struct FooRequest{ -} - -service TestThriftService { - FooReply Foo (1: FooRequest req) -} -