Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-kit/kit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: openmesh/kit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 182 files changed
  • 2 contributors

Commits on Nov 11, 2023

  1. Make endpoint.Endpoint generic

    Jack Caldwell committed Nov 11, 2023
    Copy the full SHA
    a1ddbde View commit details
  2. Merge pull request #1 from openmesh/generics

    Make endpoint.Endpoint generic
    Jack Caldwell authored Nov 11, 2023
    Copy the full SHA
    7c06aff View commit details
  3. Reset go.mod

    Jack Caldwell committed Nov 11, 2023
    Copy the full SHA
    1166382 View commit details
  4. Merge pull request #2 from openmesh/generics

    Reset go.mod
    Jack Caldwell authored Nov 11, 2023
    Copy the full SHA
    b6e8144 View commit details
  5. Fix issue with grpc.Server.ServeGRPC

    Jack Caldwell committed Nov 11, 2023
    Copy the full SHA
    0935ab0 View commit details
  6. Merge pull request #3 from openmesh/generics

    Fix issue with grpc.Server.ServeGRPC
    Jack Caldwell authored Nov 11, 2023
    Copy the full SHA
    4b4f521 View commit details
Showing with 1,341 additions and 1,629 deletions.
  1. +3 −3 .github/ISSUE_TEMPLATE/config.yml
  2. +5 −5 .github/workflows/ci.yml
  3. +2 −3 CONTRIBUTING.md
  4. +15 −15 README.md
  5. +2 −2 auth/basic/README.md
  6. +10 −10 auth/basic/middleware.go
  7. +2 −2 auth/basic/middleware_test.go
  8. +8 −8 auth/casbin/middleware.go
  9. +3 −3 auth/casbin/middleware_test.go
  10. +9 −9 auth/jwt/README.md
  11. +15 −15 auth/jwt/middleware.go
  12. +18 −18 auth/jwt/middleware_test.go
  13. +2 −2 auth/jwt/transport.go
  14. +6 −5 circuitbreaker/gobreaker.go
  15. +2 −2 circuitbreaker/gobreaker_test.go
  16. +5 −5 circuitbreaker/handy_breaker.go
  17. +2 −2 circuitbreaker/handy_breaker_test.go
  18. +6 −6 circuitbreaker/hystrix.go
  19. +2 −2 circuitbreaker/hystrix_test.go
  20. +3 −3 circuitbreaker/util_test.go
  21. +4 −4 endpoint/endpoint.go
  22. +3 −3 endpoint/endpoint_example_test.go
  23. +1 −1 examples/README.md
  24. +61 −52 go.mod
  25. +143 −452 go.sum
  26. +12 −12 log/README.md
  27. +1 −1 log/deprecated_levels/levels.go
  28. +2 −2 log/deprecated_levels/levels_test.go
  29. +30 −30 log/doc.go
  30. +1 −1 log/example_test.go
  31. +9 −9 log/level/doc.go
  32. +2 −2 log/level/example_test.go
  33. +1 −1 log/level/level.go
  34. +2 −2 log/logrus/logrus_logger.go
  35. +1 −1 log/logrus/logrus_logger_test.go
  36. +3 −3 log/sync.go
  37. +5 −6 log/syslog/example_test.go
  38. +1 −1 log/syslog/syslog.go
  39. +2 −2 log/term/example_test.go
  40. +1 −1 log/zap/zap_sugar_logger.go
  41. +4 −3 log/zap/zap_sugar_logger_test.go
  42. +16 −16 metrics/README.md
  43. +3 −3 metrics/cloudwatch/cloudwatch.go
  44. +2 −2 metrics/cloudwatch/cloudwatch_test.go
  45. +3 −3 metrics/cloudwatch2/cloudwatch2.go
  46. +1 −1 metrics/discard/discard.go
  47. +5 −5 metrics/dogstatsd/dogstatsd.go
  48. +1 −1 metrics/dogstatsd/dogstatsd_test.go
  49. +2 −2 metrics/expvar/expvar.go
  50. +1 −1 metrics/expvar/expvar_test.go
  51. +2 −2 metrics/generic/generic.go
  52. +2 −2 metrics/generic/generic_test.go
  53. +3 −3 metrics/graphite/graphite.go
  54. +1 −1 metrics/graphite/graphite_test.go
  55. +3 −3 metrics/influx/influx.go
  56. +1 −1 metrics/influx/influx_test.go
  57. +6 −6 metrics/influxstatsd/influxstatsd.go
  58. +1 −1 metrics/influxstatsd/influxstatsd_test.go
  59. +1 −1 metrics/internal/convert/convert.go
  60. +2 −2 metrics/internal/convert/convert_test.go
  61. +1 −1 metrics/multi/multi.go
  62. +1 −1 metrics/multi/multi_test.go
  63. +1 −1 metrics/pcp/pcp.go
  64. +1 −1 metrics/pcp/pcp_test.go
  65. +2 −2 metrics/prometheus/prometheus.go
  66. +1 −1 metrics/prometheus/prometheus_test.go
  67. +2 −2 metrics/provider/discard.go
  68. +2 −2 metrics/provider/dogstatsd.go
  69. +2 −2 metrics/provider/expvar.go
  70. +2 −2 metrics/provider/graphite.go
  71. +2 −2 metrics/provider/influx.go
  72. +2 −2 metrics/provider/prometheus.go
  73. +16 −17 metrics/provider/provider.go
  74. +2 −2 metrics/provider/statsd.go
  75. +4 −4 metrics/statsd/statsd.go
  76. +1 −1 metrics/statsd/statsd_test.go
  77. +1 −1 metrics/teststat/buffers.go
  78. +1 −1 metrics/teststat/populate.go
  79. +1 −1 metrics/teststat/teststat.go
  80. +2 −2 metrics/timer_test.go
  81. +9 −9 ratelimit/token_bucket.go
  82. +5 −5 ratelimit/token_bucket_test.go
  83. +5 −3 sd/benchmark_test.go
  84. +2 −2 sd/consul/client_test.go
  85. +3 −3 sd/consul/instancer.go
  86. +1 −1 sd/consul/instancer_test.go
  87. +3 −3 sd/consul/integration_test.go
  88. +2 −2 sd/dnssrv/instancer.go
  89. +1 −1 sd/dnssrv/instancer_test.go
  90. +16 −16 sd/endpoint_cache.go
  91. +16 −12 sd/endpoint_cache_test.go
  92. +14 −12 sd/endpointer.go
  93. +5 −5 sd/endpointer_test.go
  94. +8 −6 sd/etcd/example_test.go
  95. +2 −2 sd/etcd/instancer.go
  96. +1 −1 sd/etcd/instancer_test.go
  97. +2 −2 sd/etcd/integration_test.go
  98. +7 −5 sd/etcdv3/example_test.go
  99. +2 −2 sd/etcdv3/instancer.go
  100. +1 −1 sd/etcdv3/instancer_test.go
  101. +2 −2 sd/etcdv3/integration_test.go
  102. +2 −2 sd/eureka/instancer.go
  103. +1 −1 sd/eureka/instancer_test.go
  104. +1 −1 sd/eureka/registrar.go
  105. +1 −1 sd/eureka/util_test.go
  106. +2 −2 sd/factory.go
  107. +1 −1 sd/internal/instance/cache.go
  108. +9 −8 sd/internal/instance/cache_test.go
  109. +3 −3 sd/lb/balancer.go
  110. +7 −7 sd/lb/random.go
  111. +5 −5 sd/lb/random_test.go
  112. +7 −7 sd/lb/retry.go
  113. +24 −24 sd/lb/retry_test.go
  114. +7 −7 sd/lb/round_robin.go
  115. +6 −6 sd/lb/round_robin_test.go
  116. +2 −2 sd/zk/instancer.go
  117. +1 −1 sd/zk/instancer_test.go
  118. +6 −6 sd/zk/util_test.go
  119. +2 −8 tracing/README.md
  120. +6 −6 tracing/opencensus/endpoint.go
  121. +11 −11 tracing/opencensus/endpoint_test.go
  122. +9 −9 tracing/opencensus/grpc.go
  123. +5 −5 tracing/opencensus/grpc_test.go
  124. +10 −10 tracing/opencensus/http.go
  125. +5 −5 tracing/opencensus/http_test.go
  126. +7 −7 tracing/opencensus/jsonrpc.go
  127. +7 −7 tracing/opencensus/jsonrpc_test.go
  128. +10 −10 tracing/opentracing/endpoint.go
  129. +17 −17 tracing/opentracing/endpoint_test.go
  130. +1 −1 tracing/opentracing/grpc_test.go
  131. +1 −1 tracing/opentracing/http.go
  132. +1 −1 tracing/opentracing/http_test.go
  133. +4 −2 tracing/zipkin/README.md
  134. +4 −4 tracing/zipkin/endpoint.go
  135. +3 −3 tracing/zipkin/endpoint_test.go
  136. +11 −11 tracing/zipkin/grpc.go
  137. +5 −5 tracing/zipkin/grpc_test.go
  138. +11 −11 tracing/zipkin/http.go
  139. +7 −7 tracing/zipkin/http_test.go
  140. +4 −4 transport/amqp/encode_decode.go
  141. +32 −32 transport/amqp/publisher.go
  142. +6 −6 transport/amqp/publisher_test.go
  143. +27 −27 transport/amqp/subscriber.go
  144. +10 −10 transport/amqp/subscriber_test.go
  145. +2 −2 transport/awslambda/encode_decode.go
  146. +27 −27 transport/awslambda/handler.go
  147. +18 −18 transport/awslambda/handler_test.go
  148. +1 −1 transport/error_handler_test.go
  149. +10 −10 transport/grpc/README.md
  150. +3 −3 transport/grpc/_grpc_test/client.go
  151. +1 −1 transport/grpc/_grpc_test/pb/generate.go
  152. +1 −1 transport/grpc/_grpc_test/request_response.go
  153. +3 −3 transport/grpc/_grpc_test/server.go
  154. +22 −22 transport/grpc/client.go
  155. +2 −2 transport/grpc/client_test.go
  156. +4 −4 transport/grpc/encode_decode.go
  157. +27 −29 transport/grpc/server.go
  158. +25 −25 transport/http/client.go
  159. +6 −6 transport/http/client_test.go
  160. +5 −5 transport/http/encode_decode.go
  161. +1 −1 transport/http/example_test.go
  162. +61 −55 transport/http/jsonrpc/README.md
  163. +41 −41 transport/http/jsonrpc/client.go
  164. +16 −16 transport/http/jsonrpc/client_test.go
  165. +10 −10 transport/http/jsonrpc/encode_decode.go
  166. +1 −1 transport/http/jsonrpc/request_response_types_test.go
  167. +1 −1 transport/http/jsonrpc/server.go
  168. +11 −11 transport/http/jsonrpc/server_test.go
  169. +1 −1 transport/http/proto/client.go
  170. +1 −1 transport/http/proto/generate.go
  171. +1 −1 transport/http/proto/server.go
  172. +1 −1 transport/http/request_response_funcs_test.go
  173. +30 −30 transport/http/server.go
  174. +10 −10 transport/http/server_test.go
  175. +3 −3 transport/httprp/server_test.go
  176. +4 −5 transport/nats/encode_decode.go
  177. +24 −23 transport/nats/publisher.go
  178. +4 −4 transport/nats/publisher_test.go
  179. +27 −27 transport/nats/subscriber.go
  180. +11 −11 transport/nats/subscriber_test.go
  181. +2 −2 transport/netrpc/README.md
  182. +3 −3 transport/thrift/README.md
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/go-kit/kit/discussions/new?category=q-a
url: https://github.com/openmesh/kit/discussions/new?category=q-a
about: Questions and discussions with the Go kit community

- name: Website
url: https://gokit.io/
about: Project overview, examples, frequently asked questions, etc.

- name: Reference
url: https://pkg.go.dev/github.com/go-kit/kit
url: https://pkg.go.dev/github.com/openmesh/kit
about: Go kit package documentation

- name: Slack channel
url: https://gophers.slack.com/messages/go-kit
url: https://gophers.slack.com/messages/openmesh
about: Real-time discussions and Q&A
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -61,8 +61,8 @@ jobs:
EUREKA_ADDR: http://localhost:${{ job.services.eureka.ports[8761] }}/eureka
run: go test -v -race -coverprofile=coverage.coverprofile -covermode=atomic -tags integration ./...

- name: Upload coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.coverprofile
# - name: Upload coverage
# uses: codecov/codecov-action@v1
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: coverage.coverprofile
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@ Before submitting major changes, here are a few guidelines to follow:
1. After receiving feedback, [squash your commits][squash] and add a [great commit message][message].
1. Have fun!

[issues]: https://github.com/go-kit/kit/issues
[prs]: https://github.com/go-kit/kit/pulls
[issues]: https://github.com/openmesh/kit/issues
[prs]: https://github.com/openmesh/kit/pulls
[squash]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
[message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html

30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Go kit

![GitHub Workflow Status](https://github.com/go-kit/kit/workflows/CI/badge.svg)
[![GoDev](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/go-kit/kit?tab=doc)
[![codecov](https://codecov.io/gh/go-kit/kit/branch/master/graph/badge.svg)](https://codecov.io/gh/go-kit/kit)
[![Go Report Card](https://goreportcard.com/badge/go-kit/kit)](https://goreportcard.com/report/go-kit/kit)
[![Sourcegraph](https://sourcegraph.com/github.com/go-kit/kit/-/badge.svg)](https://sourcegraph.com/github.com/go-kit/kit?badge)
![GitHub Workflow Status](https://github.com/openmesh/kit/workflows/CI/badge.svg)
[![GoDev](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/openmesh/kit?tab=doc)
[![codecov](https://codecov.io/gh/openmesh/kit/branch/master/graph/badge.svg)](https://codecov.io/gh/openmesh/kit)
[![Go Report Card](https://goreportcard.com/badge/openmesh/kit)](https://goreportcard.com/report/openmesh/kit)
[![Sourcegraph](https://sourcegraph.com/github.com/openmesh/kit/-/badge.svg)](https://sourcegraph.com/github.com/openmesh/kit?badge)

**Go kit** is a **programming toolkit** for building microservices
(or elegant monoliths) in Go. We solve common problems in distributed
systems and application architecture so you can focus on delivering
business value.

- Website: [gokit.io](https://gokit.io)
- Mailing list: [go-kit](https://groups.google.com/forum/#!forum/go-kit)
- Slack: [gophers.slack.com](https://gophers.slack.com) **#go-kit** ([invite](https://gophersinvite.herokuapp.com/))
- Mailing list: [openmesh](https://groups.google.com/forum/#!forum/openmesh)
- Slack: [gophers.slack.com](https://gophers.slack.com) **#openmesh** ([invite](https://gophersinvite.herokuapp.com/))

## Sponsors

@@ -34,15 +34,15 @@ comprehensive, robust, and trustable way of building microservices for
organizations of any size.

For more details, see
[the website](https://gokit.io),
[the motivating blog post](http://peter.bourgon.org/go-kit/) and
[the video of the talk](https://www.youtube.com/watch?v=iFR_7AKkJFU).
[the website](https://gokit.io),
[the motivating blog post](http://peter.bourgon.org/openmesh/) and
[the video of the talk](https://www.youtube.com/watch?v=iFR_7AKkJFU).
See also the
[Go kit talk at GopherCon 2015](https://www.youtube.com/watch?v=1AjaZi4QuGo).
[Go kit talk at GopherCon 2015](https://www.youtube.com/watch?v=1AjaZi4QuGo).

## Goals

- Operate in a heterogeneous SOA — expect to interact with mostly non-Go-kit services
- Operate in a heterogeneous SOA — expect to interact with mostly non-openmesh services
- RPC as the primary messaging pattern
- Pluggable serialization and transport — not just JSON over HTTP
- Operate within existing infrastructures — no mandates for specific tools or technologies
@@ -56,7 +56,7 @@ See also the
## Contributing

Please see [CONTRIBUTING.md](/CONTRIBUTING.md).
Thank you, [contributors](https://github.com/go-kit/kit/graphs/contributors)!
Thank you, [contributors](https://github.com/openmesh/kit/graphs/contributors)!

## Dependency management

@@ -74,7 +74,7 @@ different starting assumptions.
- [kujtimiihoxha/kit](https://github.com/kujtimiihoxha/kit) (unmaintained)
- [nytimes/marvin](https://github.com/nytimes/marvin)
- [sagikazarmark/mga](https://github.com/sagikazarmark/mga)
- [sagikazarmark/protoc-gen-go-kit](https://github.com/sagikazarmark/protoc-gen-go-kit)
- [sagikazarmark/protoc-gen-openmesh](https://github.com/sagikazarmark/protoc-gen-openmesh)
- [metaverse/truss](https://github.com/metaverse/truss)

## Related projects
@@ -117,7 +117,7 @@ Projects with a ★ have had particular influence on Go kit's design (or vice-ve
- [Goji](https://github.com/zenazn/goji)
- [Martini](https://github.com/go-martini/martini)
- [Beego](https://beego.vip/)
- [Revel](https://revel.github.io/) (considered [harmful](https://github.com/go-kit/kit/issues/350))
- [Revel](https://revel.github.io/) (considered [harmful](https://github.com/openmesh/kit/issues/350))
- [GoBuffalo](https://gobuffalo.io/)

## Additional reading
4 changes: 2 additions & 2 deletions auth/basic/README.md
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ More details about this type of authentication can be found in [Mozilla article]
## Usage

```go
import httptransport "github.com/go-kit/kit/transport/http"
import httptransport "github.com/openmesh/kit/transport/http"

httptransport.NewServer(
AuthMiddleware(cfg.auth.user, cfg.auth.password, "Example Realm")(makeUppercaseEndpoint()),
@@ -17,4 +17,4 @@ httptransport.NewServer(
)
```

For AuthMiddleware to be able to pick up the Authentication header from an HTTP request we need to pass it through the context with something like ```httptransport.ServerBefore(httptransport.PopulateRequestContext)```.
For AuthMiddleware to be able to pick up the Authentication header from an HTTP request we need to pass it through the context with something like `httptransport.ServerBefore(httptransport.PopulateRequestContext)`.
20 changes: 10 additions & 10 deletions auth/basic/middleware.go
Original file line number Diff line number Diff line change
@@ -10,16 +10,16 @@ import (
"net/http"
"strings"

"github.com/go-kit/kit/endpoint"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/openmesh/kit/endpoint"
httptransport "github.com/openmesh/kit/transport/http"
)

// AuthError represents an authorization error.
type AuthError struct {
Realm string
}

// StatusCode is an implementation of the StatusCoder interface in go-kit/http.
// StatusCode is an implementation of the StatusCoder interface in openmeshsh/http.
func (AuthError) StatusCode() int {
return http.StatusUnauthorized
}
@@ -29,7 +29,7 @@ func (AuthError) Error() string {
return http.StatusText(http.StatusUnauthorized)
}

// Headers is an implementation of the Headerer interface in go-kit/http.
// Headers is an implementation of the Headerer interface in openmesh/http.
func (e AuthError) Headers() http.Header {
return http.Header{
"Content-Type": []string{"text/plain; charset=utf-8"},
@@ -64,28 +64,28 @@ func toHashSlice(s []byte) []byte {
}

// AuthMiddleware returns a Basic Authentication middleware for a particular user and password.
func AuthMiddleware(requiredUser, requiredPassword, realm string) endpoint.Middleware {
func AuthMiddleware[Request, Response any](requiredUser, requiredPassword, realm string) endpoint.Middleware[Request, Response] {
requiredUserBytes := toHashSlice([]byte(requiredUser))
requiredPasswordBytes := toHashSlice([]byte(requiredPassword))

return func(next endpoint.Endpoint) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
return func(next endpoint.Endpoint[Request, Response]) endpoint.Endpoint[Request, Response] {
return func(ctx context.Context, request Request) (Response, error) {
auth, ok := ctx.Value(httptransport.ContextKeyRequestAuthorization).(string)
if !ok {
return nil, AuthError{realm}
return *new(Response), AuthError{realm}
}

givenUser, givenPassword, ok := parseBasicAuth(auth)
if !ok {
return nil, AuthError{realm}
return *new(Response), AuthError{realm}
}

givenUserBytes := toHashSlice(givenUser)
givenPasswordBytes := toHashSlice(givenPassword)

if subtle.ConstantTimeCompare(givenUserBytes, requiredUserBytes) == 0 ||
subtle.ConstantTimeCompare(givenPasswordBytes, requiredPasswordBytes) == 0 {
return nil, AuthError{realm}
return *new(Response), AuthError{realm}
}

return next(ctx, request)
4 changes: 2 additions & 2 deletions auth/basic/middleware_test.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"fmt"
"testing"

httptransport "github.com/go-kit/kit/transport/http"
httptransport "github.com/openmesh/kit/transport/http"
)

func TestWithBasicAuth(t *testing.T) {
@@ -34,7 +34,7 @@ func TestWithBasicAuth(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
ctx := context.WithValue(context.TODO(), httptransport.ContextKeyRequestAuthorization, tt.authHeader)

result, err := AuthMiddleware(requiredUser, requiredPassword, realm)(passedValidation)(ctx, nil)
result, err := AuthMiddleware[interface{}, interface{}](requiredUser, requiredPassword, realm)(passedValidation)(ctx, nil)
if result != tt.want.result || err != tt.want.err {
t.Errorf("WithBasicAuth() = result: %v, err: %v, want result: %v, want error: %v", result, err, tt.want.result, tt.want.err)
}
16 changes: 8 additions & 8 deletions auth/casbin/middleware.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"errors"

stdcasbin "github.com/casbin/casbin/v2"
"github.com/go-kit/kit/endpoint"
"github.com/openmesh/kit/endpoint"
)

type contextKey string
@@ -44,25 +44,25 @@ var (
// action on the given object. If a valid access control model and policy
// is given, then the generated casbin Enforcer is stored in the context
// with CasbinEnforcer as the key.
func NewEnforcer(
func NewEnforcer[Request, Response any](
subject string, object interface{}, action string,
) endpoint.Middleware {
return func(next endpoint.Endpoint) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
) endpoint.Middleware[Request, Response] {
return func(next endpoint.Endpoint[Request, Response]) endpoint.Endpoint[Request, Response] {
return func(ctx context.Context, request Request) (response Response, err error) {
casbinModel := ctx.Value(CasbinModelContextKey)
casbinPolicy := ctx.Value(CasbinPolicyContextKey)
enforcer, err := stdcasbin.NewEnforcer(casbinModel, casbinPolicy)
if err != nil {
return nil, err
return *new(Response), err
}

ctx = context.WithValue(ctx, CasbinEnforcerContextKey, enforcer)
ok, err := enforcer.Enforce(subject, object, action)
if err != nil {
return nil, err
return *new(Response), err
}
if !ok {
return nil, ErrUnauthorized
return *new(Response), ErrUnauthorized
}

return next(ctx, request)
6 changes: 3 additions & 3 deletions auth/casbin/middleware_test.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ func TestStructBaseContext(t *testing.T) {
ctx = context.WithValue(ctx, CasbinPolicyContextKey, a)

// positive case
middleware := NewEnforcer("alice", "/alice_data/resource1", "GET")(e)
middleware := NewEnforcer[interface{}, interface{}]("alice", "/alice_data/resource1", "GET")(e)
ctx1, err := middleware(ctx, struct{}{})
if err != nil {
t.Fatalf("Enforcer returned error: %s", err)
@@ -35,7 +35,7 @@ func TestStructBaseContext(t *testing.T) {
}

// negative case
middleware = NewEnforcer("alice", "/alice_data/resource2", "POST")(e)
middleware = NewEnforcer[interface{}, interface{}]("alice", "/alice_data/resource2", "POST")(e)
_, err = middleware(ctx, struct{}{})
if err == nil {
t.Fatalf("Enforcer should return error")
@@ -48,7 +48,7 @@ func TestFileBaseContext(t *testing.T) {
ctx = context.WithValue(ctx, CasbinPolicyContextKey, "testdata/basic_policy.csv")

// positive case
middleware := NewEnforcer("alice", "data1", "read")(e)
middleware := NewEnforcer[interface{}, interface{}]("alice", "data1", "read")(e)
_, err := middleware(ctx, struct{}{})
if err != nil {
t.Fatalf("Enforcer returned error: %s", err)
18 changes: 9 additions & 9 deletions auth/jwt/README.md
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ will be added to the context via the `jwt.JWTClaimsContextKey`.
import (
stdjwt "github.com/golang-jwt/jwt/v4"

"github.com/go-kit/kit/auth/jwt"
"github.com/go-kit/kit/endpoint"
"github.com/openmesh/kit/auth/jwt"
"github.com/openmesh/kit/endpoint"
)

func main() {
@@ -36,8 +36,8 @@ the token string and add it to the context via the `jwt.JWTContextKey`.
import (
stdjwt "github.com/golang-jwt/jwt/v4"

"github.com/go-kit/kit/auth/jwt"
"github.com/go-kit/kit/endpoint"
"github.com/openmesh/kit/auth/jwt"
"github.com/openmesh/kit/endpoint"
)

func main() {
@@ -67,9 +67,9 @@ Example of use in a client:
import (
stdjwt "github.com/golang-jwt/jwt/v4"

grpctransport "github.com/go-kit/kit/transport/grpc"
"github.com/go-kit/kit/auth/jwt"
"github.com/go-kit/kit/endpoint"
grpctransport "github.com/openmesh/kit/transport/grpc"
"github.com/openmesh/kit/auth/jwt"
"github.com/openmesh/kit/endpoint"
)

func main() {
@@ -94,9 +94,9 @@ Example of use in a server:
import (
"context"

"github.com/go-kit/kit/auth/jwt"
"github.com/openmesh/kit/auth/jwt"
"github.com/go-kit/log"
grpctransport "github.com/go-kit/kit/transport/grpc"
grpctransport "github.com/openmesh/kit/transport/grpc"
)

func MakeGRPCServer(ctx context.Context, endpoints Endpoints, logger log.Logger) pb.ExampleServer {
Loading