Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update templates to use new protobuf api #3

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions microweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ import (
"net/http"
{{- end }}

"github.com/golang/protobuf/jsonpb"
"google.golang.org/protobuf/encoding/protojson"
{{ if gt (len .Services) 0 -}}
"github.com/go-chi/render"
"github.com/go-chi/chi/v5"
Expand Down Expand Up @@ -287,13 +287,13 @@ func Register{{ .Name }}Web(r chi.Router, i {{ .Name }}Handler, middlewares ...f

{{ range .AllMessages }}

// {{ marshaler . }} describes the default jsonpb.Marshaler used by all
// {{ marshaler . }} describes the default protojson.Marshaler used by all
// instances of {{ name . }}. This struct is safe to replace or modify but
// should not be done so concurrently.
var {{ marshaler . }} = new(jsonpb.Marshaler)
var {{ marshaler . }} = new(protojson.Marshaler)

// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
// uses the more correct protojson package to correctly marshal the message.
func (m *{{ name . }}) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
Expand All @@ -310,13 +310,13 @@ func (m *{{ name . }}) MarshalJSON() ([]byte, error) {

var _ json.Marshaler = (*{{ name . }})(nil)

// {{ unmarshaler . }} describes the default jsonpb.Unmarshaler used by all
// {{ unmarshaler . }} describes the default protojson.Unmarshaler used by all
// instances of {{ name . }}. This struct is safe to replace or modify but
// should not be done so concurrently.
var {{ unmarshaler . }} = new(jsonpb.Unmarshaler)
var {{ unmarshaler . }} = new(protojson.Unmarshaler)

// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
// uses the more correct protojson package to correctly unmarshal the message.
func (m *{{ name . }}) UnmarshalJSON(b []byte) error {
return {{ unmarshaler . }}.Unmarshal(bytes.NewReader(b), m)
}
Expand Down