Skip to content

Commit

Permalink
pass request context to OnRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Oct 1, 2024
1 parent be32331 commit 512dc61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions _examples/golang-basics/example.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions _examples/golang-imports/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type WebRPCServer interface {
type {{$serviceName}} struct {
{{$typePrefix}}{{$service.Name}}
OnError func(r *http.Request, rpcErr *WebRPCError)
OnRequest func(w http.ResponseWriter, r *http.Request) error
OnRequest func(ctx context.Context, w http.ResponseWriter, r *http.Request) error
}

func New{{firstLetterToUpper $service.Name}}Server(svc {{$typePrefix}}{{.Name}}) *{{$serviceName}} {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (s *{{$serviceName}}) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch contentType {
case "application/json":
if s.OnRequest != nil {
if err := s.OnRequest(w, r); err != nil {
if err := s.OnRequest(ctx, w, r); err != nil {
rpcErr, ok := err.(WebRPCError)
if !ok {
rpcErr = ErrWebrpcEndpoint.WithCause(err)
Expand Down

0 comments on commit 512dc61

Please sign in to comment.