Codebase list golang-github-go-kit-kit / b9362c6
Remove context in stringsvc examples 1 & 2 (#764) * remove context from stringsvc1 * remove context from stringsvc2 0x627832 authored 5 years ago Peter Bourgon committed 5 years ago
2 changed file(s) with 10 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
1313
1414 // StringService provides operations on strings.
1515 type StringService interface {
16 Uppercase(context.Context, string) (string, error)
17 Count(context.Context, string) int
16 Uppercase(string) (string, error)
17 Count(string) int
1818 }
1919
2020 // stringService is a concrete implementation of StringService
2121 type stringService struct{}
2222
23 func (stringService) Uppercase(_ context.Context, s string) (string, error) {
23 func (stringService) Uppercase(s string) (string, error) {
2424 if s == "" {
2525 return "", ErrEmpty
2626 }
2727 return strings.ToUpper(s), nil
2828 }
2929
30 func (stringService) Count(_ context.Context, s string) int {
30 func (stringService) Count(s string) int {
3131 return len(s)
3232 }
3333
5454
5555 // Endpoints are a primary abstraction in go-kit. An endpoint represents a single RPC (method in our service interface)
5656 func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint {
57 return func(ctx context.Context, request interface{}) (interface{}, error) {
57 return func(_ context.Context, request interface{}) (interface{}, error) {
5858 req := request.(uppercaseRequest)
59 v, err := svc.Uppercase(ctx, req.S)
59 v, err := svc.Uppercase(req.S)
6060 if err != nil {
6161 return uppercaseResponse{v, err.Error()}, nil
6262 }
6565 }
6666
6767 func makeCountEndpoint(svc StringService) endpoint.Endpoint {
68 return func(ctx context.Context, request interface{}) (interface{}, error) {
68 return func(_ context.Context, request interface{}) (interface{}, error) {
6969 req := request.(countRequest)
70 v := svc.Count(ctx, req.S)
70 v := svc.Count(req.S)
7171 return countResponse{v}, nil
7272 }
7373 }
88 )
99
1010 func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint {
11 return func(ctx context.Context, request interface{}) (interface{}, error) {
11 return func(_ context.Context, request interface{}) (interface{}, error) {
1212 req := request.(uppercaseRequest)
1313 v, err := svc.Uppercase(req.S)
1414 if err != nil {
1919 }
2020
2121 func makeCountEndpoint(svc StringService) endpoint.Endpoint {
22 return func(ctx context.Context, request interface{}) (interface{}, error) {
22 return func(_ context.Context, request interface{}) (interface{}, error) {
2323 req := request.(countRequest)
2424 v := svc.Count(req.S)
2525 return countResponse{v}, nil