Created
July 14, 2019 10:38
-
-
Save lotusirous/1f616d38442930297df80fb6a2110fad to your computer and use it in GitHub Desktop.
snippet for working with go-kit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Create go-kit Endpoint": { | |
| "prefix": "kendpoint", | |
| "body": [ | |
| "// ${1:MakeServiceEndpoint} constructs a Sum endpoint wrapping the service.", | |
| "func ${1:MakeServiceEndpoint}(s ${2:Service}) endpoint.Endpoint {", | |
| " return func(ctx context.Context, request interface{}) (response interface{}, err error) {", | |
| "$0", | |
| " return ${3:ResponseStruct}, nil", | |
| " }", | |
| "}" | |
| ], | |
| "description": "Create a go-kit endpoint" | |
| }, | |
| "Create go-kit HTTP handler": { | |
| "prefix": "khandler", | |
| "body": [ | |
| "// ${1:MakeHTTPHandler} returns a handler for the booking service.", | |
| "func ${1:MakeHTTPHandler} (svc ${2:Service}, logger kitlog.Logger, middleware endpoint.Middleware) http.Handler {", | |
| " r := mux.NewRouter()", | |
| " r.Handle(\"/your/url\", kithttp.NewServer(", | |
| " middleware(make${3:DomainObject}Endpoint(bs)),", | |
| " decode${3:DomainObject}Request,", | |
| " encodeResponse,", | |
| " opts...,", | |
| " )).Methods(\"${4:Method}\")", | |
| " return r", | |
| "}" | |
| ], | |
| "description": "Create go-kit HTTP handler" | |
| }, | |
| "Create go-kit middleware": { | |
| "prefix": "kmw", | |
| "body": [ | |
| "// ${1:name}Middleware ", | |
| "func ${1:name}Middleware(${2:args}) endpoint.Middleware {", | |
| " return func(next endpoint.Endpoint) endpoint.Endpoint {", | |
| " return func(ctx context.Context, request interface{}) (response interface{}, err error) {", | |
| " // ${0:code}", | |
| " return next(ctx, request)", | |
| " }", | |
| " }", | |
| "}", | |
| ], | |
| "description": "Create go-kit HTTP handler" | |
| }, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment