Skip to content

Commit

Permalink
call onDeprecate hook when method is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Sep 25, 2024
1 parent 694c53c commit 430da64
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type WebRPCServer interface {
type {{$serviceName}} struct {
{{$typePrefix}}{{$service.Name}}
OnError func(r *http.Request, rpcErr *WebRPCError)
OnDeprecate func(endpoint string, newEndpoint string)
}

func New{{firstLetterToUpper $service.Name}}Server(svc {{$typePrefix}}{{.Name}}) *{{$serviceName}} {
Expand All @@ -46,6 +47,10 @@ func (s *{{$serviceName}}) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
{{- range $_, $method := $service.Methods}}
case "/rpc/{{$name}}/{{$method.Name}}":
{{- $deprecated := $method.Annotations.Deprecated -}}
{{- if $deprecated -}}
s.OnDeprecate("{{ $method.Name }}", "{{ index $deprecated.Args 0 }}")
{{- end}}
handler = s.serve{{$method.Name | firstLetterToUpper}}JSON{{if $method.StreamOutput}}Stream{{end}}
{{- end}}
default:
Expand Down

0 comments on commit 430da64

Please sign in to comment.