diff --git a/backend/go.mod b/backend/go.mod index 5c45d0a9..ab553eed 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -6,7 +6,7 @@ require ( github.com/Microsoft/go-winio v0.4.14 // indirect github.com/ansel1/merry v1.5.1 github.com/appleboy/go-fcm v0.1.5 - github.com/aws/aws-sdk-go v1.38.28 + github.com/aws/aws-sdk-go v1.38.35 github.com/containerd/containerd v1.4.3 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/disintegration/imaging v1.6.2 @@ -17,7 +17,6 @@ require ( github.com/go-chi/chi v4.1.2+incompatible github.com/go-chi/cors v1.2.0 github.com/gofrs/uuid v4.0.0+incompatible - github.com/golang/protobuf v1.5.2 github.com/gorilla/mux v1.7.3 // indirect github.com/gorilla/sessions v1.2.1 github.com/h2non/filetype v1.1.1 @@ -34,12 +33,13 @@ require ( github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd github.com/sirupsen/logrus v1.7.0 // indirect github.com/stretchr/testify v1.7.0 + github.com/tidwall/gjson v1.7.5 github.com/tidwall/sjson v1.1.6 - github.com/twitchtv/twirp v7.2.0+incompatible + github.com/twitchtv/twirp v8.0.0+incompatible github.com/vmware-labs/yaml-jsonpointer v0.1.1 - github.com/xhit/go-simple-mail/v2 v2.8.1 + github.com/xhit/go-simple-mail/v2 v2.9.0 github.com/ziutek/mymysql v1.5.4 // indirect - golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b + golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect google.golang.org/protobuf v1.26.0 diff --git a/backend/go.sum b/backend/go.sum index bb824bb0..dd80ef4a 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -17,8 +17,8 @@ github.com/appleboy/go-fcm v0.1.5 h1:fKbcZf/7vwGsvDkcop8a+kCHnK+tt4wXX0X7uEzwI6E github.com/appleboy/go-fcm v0.1.5/go.mod h1:MSxZ4LqGRsnywOjnlXJXMqbjZrG4vf+0oHitfC9HRH0= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.38.28 h1:2ZzgEupSluR18ClxUnHwXKyuADheZpMblXRAsHqF0tI= -github.com/aws/aws-sdk-go v1.38.28/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= +github.com/aws/aws-sdk-go v1.38.35 h1:7AlAO0FC+8nFjxiGKEmq0QLpiA8/XFr6eIxgRTwkdTg= +github.com/aws/aws-sdk-go v1.38.35/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= @@ -96,9 +96,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -267,8 +266,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8= github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= +github.com/tidwall/gjson v1.7.5 h1:zmAN/xmX7OtpAkv4Ovfso60r/BiCi5IErCDYGNJu+uc= +github.com/tidwall/gjson v1.7.5/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE= github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8= @@ -276,13 +276,13 @@ github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV github.com/tidwall/sjson v1.1.6 h1:8fDdlahON04OZBlTQCIatW8FstSFJz8oxidj5h0rmSQ= github.com/tidwall/sjson v1.1.6/go.mod h1:KN3FZ7odvXIHPbJdhNorK/M9lWweVUbXsXXhrJ/kGOA= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/twitchtv/twirp v7.2.0+incompatible h1:cXERdTtJqg8+OZdPCPGG2xWW8g+IKQ6zYjQTk9tWcCk= -github.com/twitchtv/twirp v7.2.0+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A= +github.com/twitchtv/twirp v8.0.0+incompatible h1:uYHA8+9cit/+LUfQjL6zo/0QDKTo4U2H/WAnJ6LfhBU= +github.com/twitchtv/twirp v8.0.0+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/vmware-labs/yaml-jsonpointer v0.1.1 h1:gO9fa7NgCEGUM/+MhpHlrmh3kNTMzFTmoeBmWSagLz0= github.com/vmware-labs/yaml-jsonpointer v0.1.1/go.mod h1:JDtZ8Hd3hkVzyCAoBXxOSfP9aVfUMAG9OSPfgQTvCQk= -github.com/xhit/go-simple-mail/v2 v2.8.1 h1:40ZWoTbU6eTq170ulrELSlCMCzKuce+JeKLwo6Qzk1E= -github.com/xhit/go-simple-mail/v2 v2.8.1/go.mod h1:kA1XbQfCI4JxQ9ccSN6VFyIEkkugOm7YiPkA5hKiQn4= +github.com/xhit/go-simple-mail/v2 v2.9.0 h1:vN4fb1Aw5BDtMeJuV/aTP82ufjdT8q0GmqiBjMKPN6I= +github.com/xhit/go-simple-mail/v2 v2.9.0/go.mod h1:kA1XbQfCI4JxQ9ccSN6VFyIEkkugOm7YiPkA5hKiQn4= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= @@ -299,8 +299,8 @@ golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf h1:B2n+Zi5QeYRDAEodEu72OS36gmTWjgpXr2+cWcBW90o= +golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= diff --git a/backend/messagehub/cmd/main.go b/backend/messagehub/cmd/main.go index 83566653..033225c1 100644 --- a/backend/messagehub/cmd/main.go +++ b/backend/messagehub/cmd/main.go @@ -5,6 +5,7 @@ import ( "crypto/rsa" "encoding/json" "flag" + "fmt" "log" "net/http" "os" @@ -21,6 +22,7 @@ import ( "github.com/mreider/koto/backend/messagehub/config" "github.com/mreider/koto/backend/messagehub/migrate" "github.com/mreider/koto/backend/messagehub/repo" + "github.com/mreider/koto/backend/messagehub/services" "github.com/mreider/koto/backend/token" ) @@ -83,7 +85,10 @@ func main() { s3Cleaner := common.NewS3Cleaner(db, s3Storage) go s3Cleaner.Clean(context.Background()) - go cleanOldGuestMessages(repos.Message) + messageCleaner := services.NewMessageCleaner(cfg.ExternalAddress, + fmt.Sprintf("%s/rpc.MessageHubInternalService/ExpirationDays", cfg.UserHubAddress), + tokenGenerator) + go messageCleaner.DeleteExpiredMessages(repos.Message) server := messagehub.NewServer(cfg, repos, tokenParser, s3Storage, tokenGenerator, string(publicKeyPEM), db) err = server.Run() @@ -146,19 +151,3 @@ func loadConfig(execDir string) (config.Config, error) { return cfg, nil } - -func cleanOldGuestMessages(messageRepo repo.MessageRepo) { - ticker := time.NewTicker(time.Hour * 1) - defer ticker.Stop() - - for range ticker.C { - func() { - defer func() { - if r := recover(); r != nil { - log.Println("can't delete old guest messages:", r) - } - }() - messageRepo.DeleteOldGuestMessages(time.Now().UTC().AddDate(0, 0, -30)) - }() - } -} diff --git a/backend/messagehub/repo/message_repo.go b/backend/messagehub/repo/message_repo.go index 9dfe814f..64d57f6a 100644 --- a/backend/messagehub/repo/message_repo.go +++ b/backend/messagehub/repo/message_repo.go @@ -3,6 +3,7 @@ package repo import ( "database/sql" "errors" + "log" "time" "github.com/ansel1/merry" @@ -82,7 +83,7 @@ type MessageRepo interface { DeleteReportedMessage(reportID string) bool BlockReportedUser(reportID string) bool ResolveMessageReport(reportID string) bool - DeleteOldGuestMessages(until time.Time) + DeleteExpiredMessages(until time.Time, onlyGuestMessages bool) MarkRead(userID string, messageIDs []string) Counts(currentUserID string, userIDs []string) Counts GroupCounts(currentUserID string, groupIDs []string) map[string]Counts @@ -645,81 +646,86 @@ func (r *messageRepo) ResolveMessageReport(reportID string) bool { return true } -func (r *messageRepo) DeleteOldGuestMessages(until time.Time) { +func (r *messageRepo) DeleteExpiredMessages(until time.Time, onlyGuestMessages bool) { until = until.UTC() err := common.RunInTransaction(r.db, func(tx *sqlx.Tx) error { _, err := tx.Exec(` - with m as (select id from messages where parent_id is null and is_guest = true and created_at < $1), + with m as (select id from messages where parent_id is null and ($1 = false or is_guest = true) and created_at < $2), c as (select id from messages where parent_id in (select id from m)), mc as (select id from m union select id from c) delete from message_likes where message_id in (select id from mc);`, - until) + onlyGuestMessages, until) if err != nil { return merry.Wrap(err) } _, err = tx.Exec(` - with m as (select id from messages where parent_id is null and is_guest = true and created_at < $1), + with m as (select id from messages where parent_id is null and ($1 = false or is_guest = true) and created_at < $2), c as (select id from messages where parent_id in (select id from m)), mc as (select id from m union select id from c) delete from message_visibility where message_id in (select id from mc);`, - until) + onlyGuestMessages, until) if err != nil { return merry.Wrap(err) } _, err = tx.Exec(` - with m as (select id from messages where parent_id is null and is_guest = true and created_at < $1), + with m as (select id from messages where parent_id is null and ($1 = false or is_guest = true) and created_at < $2), c as (select id from messages where parent_id in (select id from m)), mc as (select id from m union select id from c) delete from message_reports where message_id in (select id from mc);`, - until) + onlyGuestMessages, until) if err != nil { return merry.Wrap(err) } _, err = tx.Exec(` - with m as (select id from messages where parent_id is null and is_guest = true and created_at < $1), + with m as (select id from messages where parent_id is null and ($1 = false or is_guest = true) and created_at < $2), c as (select id from messages where parent_id in (select id from m)), mc as (select id from m union select id from c) delete from message_reads where message_id in (select id from mc);`, - until) + onlyGuestMessages, until) if err != nil { return merry.Wrap(err) } _, err = tx.Exec(` - with m as (select id from messages where parent_id is null and is_guest = true and created_at < $1), + with m as (select id from messages where parent_id is null and ($1 = false or is_guest = true) and created_at < $2), c as (select id from messages where parent_id in (select id from m)), mc as (select id from m union select id from c) insert into blob_pending_deletes(blob_id, deleted_at) - select attachment_id, $2::timestamptz + select attachment_id, $3::timestamptz from messages where id in (select id from mc) and attachment_id != '' union - select attachment_thumbnail_id, $2::timestamptz + select attachment_thumbnail_id, $3::timestamptz from messages where id in (select id from mc) and attachment_thumbnail_id != '';`, - until, common.CurrentTimestamp()) + onlyGuestMessages, until, common.CurrentTimestamp()) if err != nil { return merry.Wrap(err) } - _, err = tx.Exec(` - with m as (select id from messages where parent_id is null and is_guest = true and created_at < $1), + res, err := tx.Exec(` + with m as (select id from messages where parent_id is null and ($1 = false or is_guest = true) and created_at < $2), c as (select id from messages where parent_id in (select id from m)), mc as (select id from m union select id from c) delete from messages where id in (select id from mc);`, - until) + onlyGuestMessages, until) if err != nil { return merry.Wrap(err) } + rowsAffected, err := res.RowsAffected() + if err == nil { + log.Printf("Deleted %d expired messages", rowsAffected) + } + return nil }) if err != nil { diff --git a/backend/messagehub/rpc/admin.twirp.go b/backend/messagehub/rpc/admin.twirp.go index eb6cf206..2f7bab93 100644 --- a/backend/messagehub/rpc/admin.twirp.go +++ b/backend/messagehub/rpc/admin.twirp.go @@ -1,9 +1,9 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: admin.proto /* Package rpc is a generated twirp stub package. -This code was generated with github.com/twitchtv/twirp/protoc-gen-twirp v7.2.0. +This code was generated with github.com/twitchtv/twirp/protoc-gen-twirp v8.0.0. It is generated from these files: admin.proto @@ -16,22 +16,21 @@ It is generated from these files: */ package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" -// Imports only used by utility functions: +import bytes "bytes" import io "io" -import json "encoding/json" import path "path" import url "net/url" @@ -351,9 +350,15 @@ func (s *adminServiceServer) serveDestroyDataJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -399,15 +404,14 @@ func (s *adminServiceServer) serveDestroyDataJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -504,7 +508,7 @@ func (s *adminServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *adminServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" @@ -540,7 +544,7 @@ type TwirpServer interface { // ServiceDescriptor returns gzipped bytes describing the .proto file that // this service was generated from. Once unzipped, the bytes can be // unmarshalled as a - // github.com/golang/protobuf/protoc-gen-go/descriptor.FileDescriptorProto. + // google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto. // // The returned integer is the index of this particular service within that // FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a @@ -677,7 +681,7 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType } req.Header.Set("Accept", contentType) req.Header.Set("Content-Type", contentType) - req.Header.Set("Twirp-Version", "v7.2.0") + req.Header.Set("Twirp-Version", "v8.0.0") return req, nil } @@ -950,16 +954,16 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie // doJSONRequest makes a JSON request to the remote Twirp service. func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { - reqBody := bytes.NewBuffer(nil) - marshaler := &jsonpb.Marshaler{OrigName: true} - if err = marshaler.Marshal(reqBody, in); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true} + reqBytes, err := marshaler.Marshal(in) + if err != nil { return ctx, wrapInternal(err, "failed to marshal json request") } if err = ctx.Err(); err != nil { return ctx, wrapInternal(err, "aborted because context was done") } - req, err := newRequest(ctx, url, reqBody, "application/json") + req, err := newRequest(ctx, url, bytes.NewReader(reqBytes), "application/json") if err != nil { return ctx, wrapInternal(err, "could not build request") } @@ -989,8 +993,13 @@ func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHo return ctx, errorFromResponse(resp) } - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(resp.Body, out); err != nil { + d := json.NewDecoder(resp.Body) + rawRespBody := json.RawMessage{} + if err := d.Decode(&rawRespBody); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawRespBody, out); err != nil { return ctx, wrapInternal(err, "failed to unmarshal json response") } if err = ctx.Err(); err != nil { diff --git a/backend/messagehub/rpc/blob.twirp.go b/backend/messagehub/rpc/blob.twirp.go index 2dedf2fe..eaec40ba 100644 --- a/backend/messagehub/rpc/blob.twirp.go +++ b/backend/messagehub/rpc/blob.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: blob.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -332,9 +332,15 @@ func (s *blobServiceServer) serveUploadLinkJSON(ctx context.Context, resp http.R return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(BlobUploadLinkRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -380,15 +386,14 @@ func (s *blobServiceServer) serveUploadLinkJSON(ctx context.Context, resp http.R ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -485,7 +490,7 @@ func (s *blobServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *blobServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/messagehub/rpc/info.twirp.go b/backend/messagehub/rpc/info.twirp.go index 6cfaf801..da116e0c 100644 --- a/backend/messagehub/rpc/info.twirp.go +++ b/backend/messagehub/rpc/info.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: info.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -431,9 +431,15 @@ func (s *infoServiceServer) servePublicKeyJSON(ctx context.Context, resp http.Re return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -479,15 +485,14 @@ func (s *infoServiceServer) servePublicKeyJSON(ctx context.Context, resp http.Re ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -606,9 +611,15 @@ func (s *infoServiceServer) serveVersionJSON(ctx context.Context, resp http.Resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -654,15 +665,14 @@ func (s *infoServiceServer) serveVersionJSON(ctx context.Context, resp http.Resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -759,7 +769,7 @@ func (s *infoServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *infoServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/messagehub/rpc/message.twirp.go b/backend/messagehub/rpc/message.twirp.go index 7254222f..01919427 100644 --- a/backend/messagehub/rpc/message.twirp.go +++ b/backend/messagehub/rpc/message.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: message.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -2411,9 +2411,15 @@ func (s *messageServiceServer) serveMessagesJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageMessagesRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2459,15 +2465,14 @@ func (s *messageServiceServer) serveMessagesJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2586,9 +2591,15 @@ func (s *messageServiceServer) serveMessageJSON(ctx context.Context, resp http.R return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageMessageRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2634,15 +2645,14 @@ func (s *messageServiceServer) serveMessageJSON(ctx context.Context, resp http.R ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2761,9 +2771,15 @@ func (s *messageServiceServer) servePostJSON(ctx context.Context, resp http.Resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessagePostRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2809,15 +2825,14 @@ func (s *messageServiceServer) servePostJSON(ctx context.Context, resp http.Resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2936,9 +2951,15 @@ func (s *messageServiceServer) serveEditJSON(ctx context.Context, resp http.Resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageEditRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2984,15 +3005,14 @@ func (s *messageServiceServer) serveEditJSON(ctx context.Context, resp http.Resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3111,9 +3131,15 @@ func (s *messageServiceServer) serveDeleteJSON(ctx context.Context, resp http.Re return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageDeleteRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3159,15 +3185,14 @@ func (s *messageServiceServer) serveDeleteJSON(ctx context.Context, resp http.Re ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3286,9 +3311,15 @@ func (s *messageServiceServer) servePostCommentJSON(ctx context.Context, resp ht return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessagePostCommentRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3334,15 +3365,14 @@ func (s *messageServiceServer) servePostCommentJSON(ctx context.Context, resp ht ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3461,9 +3491,15 @@ func (s *messageServiceServer) serveEditCommentJSON(ctx context.Context, resp ht return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageEditCommentRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3509,15 +3545,14 @@ func (s *messageServiceServer) serveEditCommentJSON(ctx context.Context, resp ht ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3636,9 +3671,15 @@ func (s *messageServiceServer) serveDeleteCommentJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageDeleteCommentRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3684,15 +3725,14 @@ func (s *messageServiceServer) serveDeleteCommentJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3811,9 +3851,15 @@ func (s *messageServiceServer) serveLikeMessageJSON(ctx context.Context, resp ht return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageLikeMessageRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3859,15 +3905,14 @@ func (s *messageServiceServer) serveLikeMessageJSON(ctx context.Context, resp ht ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3986,9 +4031,15 @@ func (s *messageServiceServer) serveLikeCommentJSON(ctx context.Context, resp ht return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageLikeCommentRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4034,15 +4085,14 @@ func (s *messageServiceServer) serveLikeCommentJSON(ctx context.Context, resp ht ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4161,9 +4211,15 @@ func (s *messageServiceServer) serveMessageLikesJSON(ctx context.Context, resp h return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageMessageLikesRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4209,15 +4265,14 @@ func (s *messageServiceServer) serveMessageLikesJSON(ctx context.Context, resp h ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4336,9 +4391,15 @@ func (s *messageServiceServer) serveCommentLikesJSON(ctx context.Context, resp h return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageCommentLikesRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4384,15 +4445,14 @@ func (s *messageServiceServer) serveCommentLikesJSON(ctx context.Context, resp h ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4511,9 +4571,15 @@ func (s *messageServiceServer) serveSetMessageVisibilityJSON(ctx context.Context return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageSetMessageVisibilityRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4559,15 +4625,14 @@ func (s *messageServiceServer) serveSetMessageVisibilityJSON(ctx context.Context ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4686,9 +4751,15 @@ func (s *messageServiceServer) serveSetCommentVisibilityJSON(ctx context.Context return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageSetCommentVisibilityRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4734,15 +4805,14 @@ func (s *messageServiceServer) serveSetCommentVisibilityJSON(ctx context.Context ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4861,9 +4931,15 @@ func (s *messageServiceServer) serveReportMessageJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageReportMessageRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4909,15 +4985,14 @@ func (s *messageServiceServer) serveReportMessageJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5036,9 +5111,15 @@ func (s *messageServiceServer) serveMessageReportJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageMessageReportRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5084,15 +5165,14 @@ func (s *messageServiceServer) serveMessageReportJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5211,9 +5291,15 @@ func (s *messageServiceServer) serveMessageReportsJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5259,15 +5345,14 @@ func (s *messageServiceServer) serveMessageReportsJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5386,9 +5471,15 @@ func (s *messageServiceServer) serveDeleteReportedMessageJSON(ctx context.Contex return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageDeleteReportedMessageRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5434,15 +5525,14 @@ func (s *messageServiceServer) serveDeleteReportedMessageJSON(ctx context.Contex ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5561,9 +5651,15 @@ func (s *messageServiceServer) serveBlockReportedUserJSON(ctx context.Context, r return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageBlockReportedUserRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5609,15 +5705,14 @@ func (s *messageServiceServer) serveBlockReportedUserJSON(ctx context.Context, r ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5736,9 +5831,15 @@ func (s *messageServiceServer) serveResolveMessageReportJSON(ctx context.Context return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageResolveMessageReportRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5784,15 +5885,14 @@ func (s *messageServiceServer) serveResolveMessageReportJSON(ctx context.Context ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5911,9 +6011,15 @@ func (s *messageServiceServer) serveMarkReadJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageMarkReadRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5959,15 +6065,14 @@ func (s *messageServiceServer) serveMarkReadJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -6086,9 +6191,15 @@ func (s *messageServiceServer) serveCountersJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageCountersRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -6134,15 +6245,14 @@ func (s *messageServiceServer) serveCountersJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -6239,7 +6349,7 @@ func (s *messageServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *messageServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/messagehub/rpc/notification.twirp.go b/backend/messagehub/rpc/notification.twirp.go index a7fa6631..59f0c4c2 100644 --- a/backend/messagehub/rpc/notification.twirp.go +++ b/backend/messagehub/rpc/notification.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: notification.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -629,9 +629,15 @@ func (s *notificationServiceServer) serveCountJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -677,15 +683,14 @@ func (s *notificationServiceServer) serveCountJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -804,9 +809,15 @@ func (s *notificationServiceServer) serveNotificationsJSON(ctx context.Context, return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -852,15 +863,14 @@ func (s *notificationServiceServer) serveNotificationsJSON(ctx context.Context, ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -979,9 +989,15 @@ func (s *notificationServiceServer) serveCleanJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(NotificationCleanRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1027,15 +1043,14 @@ func (s *notificationServiceServer) serveCleanJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1154,9 +1169,15 @@ func (s *notificationServiceServer) serveMarkReadJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(NotificationMarkReadRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1202,15 +1223,14 @@ func (s *notificationServiceServer) serveMarkReadJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1307,7 +1327,7 @@ func (s *notificationServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *notificationServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/messagehub/rpc/user.twirp.go b/backend/messagehub/rpc/user.twirp.go index 7e97605f..7950a59d 100644 --- a/backend/messagehub/rpc/user.twirp.go +++ b/backend/messagehub/rpc/user.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: user.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -431,9 +431,15 @@ func (s *userServiceServer) serveBlockUserJSON(ctx context.Context, resp http.Re return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(UserBlockRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -479,15 +485,14 @@ func (s *userServiceServer) serveBlockUserJSON(ctx context.Context, resp http.Re ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -606,9 +611,15 @@ func (s *userServiceServer) serveDeleteMeJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -654,15 +665,14 @@ func (s *userServiceServer) serveDeleteMeJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -759,7 +769,7 @@ func (s *userServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *userServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/messagehub/services/message_cleaner.go b/backend/messagehub/services/message_cleaner.go new file mode 100644 index 00000000..107ee3e7 --- /dev/null +++ b/backend/messagehub/services/message_cleaner.go @@ -0,0 +1,122 @@ +package services + +import ( + "context" + "io" + "log" + "net/http" + "strings" + "time" + + "github.com/tidwall/gjson" + + "github.com/mreider/koto/backend/messagehub/repo" + "github.com/mreider/koto/backend/token" +) + +const ( + defaultGuestExpirationPeriodInDays = 30 +) + +func NewMessageCleaner(externalAddress, apiEndpoint string, tokenGenerator token.Generator) *MessageCleaner { + return &MessageCleaner{ + externalAddress: externalAddress, + apiEndpoint: apiEndpoint, + tokenGenerator: tokenGenerator, + userHubClient: &http.Client{ + Timeout: time.Second * 30, + }, + } +} + +type MessageCleaner struct { + externalAddress string + apiEndpoint string + tokenGenerator token.Generator + userHubClient *http.Client + + expirationDays int +} + +func (mc *MessageCleaner) DeleteExpiredMessages(messageRepo repo.MessageRepo) { + // Delay to start the service. + time.Sleep(time.Second * 10) + + mc.deleteExpiredMessages(messageRepo) + + ticker := time.NewTicker(time.Hour * 1) + defer ticker.Stop() + + for range ticker.C { + mc.deleteExpiredMessages(messageRepo) + } +} + +func (mc *MessageCleaner) deleteExpiredMessages(messageRepo repo.MessageRepo) { + defer func() { + if r := recover(); r != nil { + log.Println("can't delete expired messages:", r) + } + }() + + mc.updateExpirationDays() + expirationDays := mc.expirationDays + onlyGuestMessages := false + if mc.expirationDays == 0 { + expirationDays = defaultGuestExpirationPeriodInDays + onlyGuestMessages = true + } + + until := time.Now().UTC().AddDate(0, 0, -expirationDays) + messageRepo.DeleteExpiredMessages(until, onlyGuestMessages) +} + +func (mc *MessageCleaner) updateExpirationDays() { + authToken, err := mc.tokenGenerator.Generate(mc.externalAddress, "auth", time.Now().Add(time.Minute*1), nil) + if err != nil { + log.Println("can't generate auth token:", err) + return + } + + req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, mc.apiEndpoint, strings.NewReader("{}")) + if err != nil { + log.Println("can't create expiration_days request:", err) + return + } + req.Header.Set("Authorization", "Bearer "+authToken) + req.Header.Set("Content-Type", "application/json") + + resp, err := mc.userHubClient.Do(req) + if err != nil { + log.Println("can't post expiration_days request:", err) + return + } + defer func() { _ = resp.Body.Close() }() + + if resp.StatusCode != http.StatusOK { + respBody, _ := io.ReadAll(resp.Body) + log.Printf("expiration_days response - unexpected status: %s. %s", resp.Status, string(respBody)) + return + } + + respBody, err := io.ReadAll(resp.Body) + if err != nil { + log.Println("can't read expiration_days response:", err) + return + } + if !gjson.ValidBytes(respBody) { + log.Println("expiration_days response is not valid json") + return + } + expirationDays := gjson.GetBytes(respBody, "expiration_days") + if !expirationDays.Exists() || expirationDays.Type != gjson.Number { + log.Println("expiration_days response is not valid") + return + } + + newExpirationDays := int(expirationDays.Int()) + if newExpirationDays != mc.expirationDays { + log.Printf("'Expiration days' is updated from %d to %d", mc.expirationDays, newExpirationDays) + mc.expirationDays = newExpirationDays + } +} diff --git a/backend/messagehub/services/notification_sender.go b/backend/messagehub/services/notification_sender.go index e0eee50e..89d50ba1 100644 --- a/backend/messagehub/services/notification_sender.go +++ b/backend/messagehub/services/notification_sender.go @@ -107,7 +107,7 @@ func (n *notificationSender) sendNotifications(notifications []Notification) { req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, n.userHubEndpoint, bytes.NewReader(body)) if err != nil { - log.Println("can't generate notifications request:", err) + log.Println("can't create notifications request:", err) return } req.Header.Set("Authorization", "Bearer "+authToken) diff --git a/backend/userhub/rpc/auth.twirp.go b/backend/userhub/rpc/auth.twirp.go index b69ab08f..524ed6fe 100644 --- a/backend/userhub/rpc/auth.twirp.go +++ b/backend/userhub/rpc/auth.twirp.go @@ -1,9 +1,9 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: auth.proto /* Package rpc is a generated twirp stub package. -This code was generated with github.com/twitchtv/twirp/protoc-gen-twirp v7.2.0. +This code was generated with github.com/twitchtv/twirp/protoc-gen-twirp v8.0.0. It is generated from these files: auth.proto @@ -20,22 +20,21 @@ It is generated from these files: */ package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" -// Imports only used by utility functions: +import bytes "bytes" import io "io" -import json "encoding/json" import path "path" import url "net/url" @@ -1048,9 +1047,15 @@ func (s *authServiceServer) serveRegisterJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(AuthRegisterRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1096,15 +1101,14 @@ func (s *authServiceServer) serveRegisterJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1223,9 +1227,15 @@ func (s *authServiceServer) serveLoginJSON(ctx context.Context, resp http.Respon return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(AuthLoginRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1271,15 +1281,14 @@ func (s *authServiceServer) serveLoginJSON(ctx context.Context, resp http.Respon ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1398,9 +1407,15 @@ func (s *authServiceServer) serveConfirmJSON(ctx context.Context, resp http.Resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(AuthConfirmRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1446,15 +1461,14 @@ func (s *authServiceServer) serveConfirmJSON(ctx context.Context, resp http.Resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1573,9 +1587,15 @@ func (s *authServiceServer) serveSendConfirmLinkJSON(ctx context.Context, resp h return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1621,15 +1641,14 @@ func (s *authServiceServer) serveSendConfirmLinkJSON(ctx context.Context, resp h ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1748,9 +1767,15 @@ func (s *authServiceServer) serveSendResetPasswordLinkJSON(ctx context.Context, return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(AuthSendResetPasswordLinkRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1796,15 +1821,14 @@ func (s *authServiceServer) serveSendResetPasswordLinkJSON(ctx context.Context, ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1923,9 +1947,15 @@ func (s *authServiceServer) serveResetPasswordJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(AuthResetPasswordRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1971,15 +2001,14 @@ func (s *authServiceServer) serveResetPasswordJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2098,9 +2127,15 @@ func (s *authServiceServer) serveLogoutJSON(ctx context.Context, resp http.Respo return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2146,15 +2181,14 @@ func (s *authServiceServer) serveLogoutJSON(ctx context.Context, resp http.Respo ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2273,9 +2307,15 @@ func (s *authServiceServer) serveRecallNamesJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(AuthRecallNamesRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2321,15 +2361,14 @@ func (s *authServiceServer) serveRecallNamesJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2426,7 +2465,7 @@ func (s *authServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *authServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" @@ -2462,7 +2501,7 @@ type TwirpServer interface { // ServiceDescriptor returns gzipped bytes describing the .proto file that // this service was generated from. Once unzipped, the bytes can be // unmarshalled as a - // github.com/golang/protobuf/protoc-gen-go/descriptor.FileDescriptorProto. + // google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto. // // The returned integer is the index of this particular service within that // FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a @@ -2599,7 +2638,7 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType } req.Header.Set("Accept", contentType) req.Header.Set("Content-Type", contentType) - req.Header.Set("Twirp-Version", "v7.2.0") + req.Header.Set("Twirp-Version", "v8.0.0") return req, nil } @@ -2872,16 +2911,16 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie // doJSONRequest makes a JSON request to the remote Twirp service. func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { - reqBody := bytes.NewBuffer(nil) - marshaler := &jsonpb.Marshaler{OrigName: true} - if err = marshaler.Marshal(reqBody, in); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true} + reqBytes, err := marshaler.Marshal(in) + if err != nil { return ctx, wrapInternal(err, "failed to marshal json request") } if err = ctx.Err(); err != nil { return ctx, wrapInternal(err, "aborted because context was done") } - req, err := newRequest(ctx, url, reqBody, "application/json") + req, err := newRequest(ctx, url, bytes.NewReader(reqBytes), "application/json") if err != nil { return ctx, wrapInternal(err, "could not build request") } @@ -2911,8 +2950,13 @@ func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHo return ctx, errorFromResponse(resp) } - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(resp.Body, out); err != nil { + d := json.NewDecoder(resp.Body) + rawRespBody := json.RawMessage{} + if err := d.Decode(&rawRespBody); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawRespBody, out); err != nil { return ctx, wrapInternal(err, "failed to unmarshal json response") } if err = ctx.Err(); err != nil { diff --git a/backend/userhub/rpc/blob.twirp.go b/backend/userhub/rpc/blob.twirp.go index 2dedf2fe..eaec40ba 100644 --- a/backend/userhub/rpc/blob.twirp.go +++ b/backend/userhub/rpc/blob.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: blob.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -332,9 +332,15 @@ func (s *blobServiceServer) serveUploadLinkJSON(ctx context.Context, resp http.R return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(BlobUploadLinkRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -380,15 +386,14 @@ func (s *blobServiceServer) serveUploadLinkJSON(ctx context.Context, resp http.R ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -485,7 +490,7 @@ func (s *blobServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *blobServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/group.twirp.go b/backend/userhub/rpc/group.twirp.go index 4bdc8deb..ad67804e 100644 --- a/backend/userhub/rpc/group.twirp.go +++ b/backend/userhub/rpc/group.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: group.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -2216,9 +2216,15 @@ func (s *groupServiceServer) serveAddGroupJSON(ctx context.Context, resp http.Re return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupAddGroupRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2264,15 +2270,14 @@ func (s *groupServiceServer) serveAddGroupJSON(ctx context.Context, resp http.Re ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2391,9 +2396,15 @@ func (s *groupServiceServer) serveEditGroupJSON(ctx context.Context, resp http.R return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupEditGroupRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2439,15 +2450,14 @@ func (s *groupServiceServer) serveEditGroupJSON(ctx context.Context, resp http.R ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2566,9 +2576,15 @@ func (s *groupServiceServer) serveDeleteGroupJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupDeleteGroupRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2614,15 +2630,14 @@ func (s *groupServiceServer) serveDeleteGroupJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2741,9 +2756,15 @@ func (s *groupServiceServer) serveManagedGroupJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2789,15 +2810,14 @@ func (s *groupServiceServer) serveManagedGroupJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2916,9 +2936,15 @@ func (s *groupServiceServer) serveAddUserJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupAddUserRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2964,15 +2990,14 @@ func (s *groupServiceServer) serveAddUserJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3091,9 +3116,15 @@ func (s *groupServiceServer) serveRemoveUserJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupRemoveUserRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3139,15 +3170,14 @@ func (s *groupServiceServer) serveRemoveUserJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3266,9 +3296,15 @@ func (s *groupServiceServer) serveInvitesToConfirmJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3314,15 +3350,14 @@ func (s *groupServiceServer) serveInvitesToConfirmJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3441,9 +3476,15 @@ func (s *groupServiceServer) serveConfirmInviteJSON(ctx context.Context, resp ht return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupConfirmInviteRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3489,15 +3530,14 @@ func (s *groupServiceServer) serveConfirmInviteJSON(ctx context.Context, resp ht ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3616,9 +3656,15 @@ func (s *groupServiceServer) serveDenyInviteJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupDenyInviteRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3664,15 +3710,14 @@ func (s *groupServiceServer) serveDenyInviteJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3791,9 +3836,15 @@ func (s *groupServiceServer) servePublicGroupsJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3839,15 +3890,14 @@ func (s *groupServiceServer) servePublicGroupsJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3966,9 +4016,15 @@ func (s *groupServiceServer) serveGroupDetailsJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupGroupDetailsRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4014,15 +4070,14 @@ func (s *groupServiceServer) serveGroupDetailsJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4141,9 +4196,15 @@ func (s *groupServiceServer) serveRequestJoinJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupRequestJoinRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4189,15 +4250,14 @@ func (s *groupServiceServer) serveRequestJoinJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4316,9 +4376,15 @@ func (s *groupServiceServer) serveDeleteJoinRequestJSON(ctx context.Context, res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupDeleteJoinRequestRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4364,15 +4430,14 @@ func (s *groupServiceServer) serveDeleteJoinRequestJSON(ctx context.Context, res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4491,9 +4556,15 @@ func (s *groupServiceServer) serveLeaveGroupJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupLeaveGroupRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4539,15 +4610,14 @@ func (s *groupServiceServer) serveLeaveGroupJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4666,9 +4736,15 @@ func (s *groupServiceServer) serveInvitesFromMeJSON(ctx context.Context, resp ht return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4714,15 +4790,14 @@ func (s *groupServiceServer) serveInvitesFromMeJSON(ctx context.Context, resp ht ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -4841,9 +4916,15 @@ func (s *groupServiceServer) serveInvitesForMeJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -4889,15 +4970,14 @@ func (s *groupServiceServer) serveInvitesForMeJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5016,9 +5096,15 @@ func (s *groupServiceServer) serveCreateInviteJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupCreateInviteRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5064,15 +5150,14 @@ func (s *groupServiceServer) serveCreateInviteJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5191,9 +5276,15 @@ func (s *groupServiceServer) serveDeleteInviteJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupDeleteInviteRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5239,15 +5330,14 @@ func (s *groupServiceServer) serveDeleteInviteJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5366,9 +5456,15 @@ func (s *groupServiceServer) serveAcceptInviteJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupAcceptInviteRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5414,15 +5510,14 @@ func (s *groupServiceServer) serveAcceptInviteJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5541,9 +5636,15 @@ func (s *groupServiceServer) serveRejectInviteJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(GroupRejectInviteRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -5589,15 +5690,14 @@ func (s *groupServiceServer) serveRejectInviteJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -5694,7 +5794,7 @@ func (s *groupServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *groupServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/info.twirp.go b/backend/userhub/rpc/info.twirp.go index 85f481a2..d629c1c9 100644 --- a/backend/userhub/rpc/info.twirp.go +++ b/backend/userhub/rpc/info.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: info.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -431,9 +431,15 @@ func (s *infoServiceServer) servePublicKeyJSON(ctx context.Context, resp http.Re return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -479,15 +485,14 @@ func (s *infoServiceServer) servePublicKeyJSON(ctx context.Context, resp http.Re ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -606,9 +611,15 @@ func (s *infoServiceServer) serveVersionJSON(ctx context.Context, resp http.Resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -654,15 +665,14 @@ func (s *infoServiceServer) serveVersionJSON(ctx context.Context, resp http.Resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -759,7 +769,7 @@ func (s *infoServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *infoServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/invite.twirp.go b/backend/userhub/rpc/invite.twirp.go index c125eec8..17b305d9 100644 --- a/backend/userhub/rpc/invite.twirp.go +++ b/backend/userhub/rpc/invite.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: invite.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -728,9 +728,15 @@ func (s *inviteServiceServer) serveCreateJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(InviteCreateRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -776,15 +782,14 @@ func (s *inviteServiceServer) serveCreateJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -903,9 +908,15 @@ func (s *inviteServiceServer) serveAcceptJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(InviteAcceptRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -951,15 +962,14 @@ func (s *inviteServiceServer) serveAcceptJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1078,9 +1088,15 @@ func (s *inviteServiceServer) serveRejectJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(InviteRejectRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1126,15 +1142,14 @@ func (s *inviteServiceServer) serveRejectJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1253,9 +1268,15 @@ func (s *inviteServiceServer) serveFromMeJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1301,15 +1322,14 @@ func (s *inviteServiceServer) serveFromMeJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1428,9 +1448,15 @@ func (s *inviteServiceServer) serveForMeJSON(ctx context.Context, resp http.Resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1476,15 +1502,14 @@ func (s *inviteServiceServer) serveForMeJSON(ctx context.Context, resp http.Resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1581,7 +1606,7 @@ func (s *inviteServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *inviteServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/messagehub.twirp.go b/backend/userhub/rpc/messagehub.twirp.go index ec390381..3a7fa436 100644 --- a/backend/userhub/rpc/messagehub.twirp.go +++ b/backend/userhub/rpc/messagehub.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: messagehub.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -1322,9 +1322,15 @@ func (s *messageHubServiceServer) serveCreateJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubCreateRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1370,15 +1376,14 @@ func (s *messageHubServiceServer) serveCreateJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1497,9 +1502,15 @@ func (s *messageHubServiceServer) serveRegisterJSON(ctx context.Context, resp ht return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubRegisterRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1545,15 +1556,14 @@ func (s *messageHubServiceServer) serveRegisterJSON(ctx context.Context, resp ht ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1672,9 +1682,15 @@ func (s *messageHubServiceServer) serveHubsJSON(ctx context.Context, resp http.R return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1720,15 +1736,14 @@ func (s *messageHubServiceServer) serveHubsJSON(ctx context.Context, resp http.R ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1847,9 +1862,15 @@ func (s *messageHubServiceServer) serveVerifyJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubVerifyRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1895,15 +1916,14 @@ func (s *messageHubServiceServer) serveVerifyJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2022,9 +2042,15 @@ func (s *messageHubServiceServer) serveApproveJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubApproveRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2070,15 +2096,14 @@ func (s *messageHubServiceServer) serveApproveJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2197,9 +2222,15 @@ func (s *messageHubServiceServer) serveRemoveJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubRemoveRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2245,15 +2276,14 @@ func (s *messageHubServiceServer) serveRemoveJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2372,9 +2402,15 @@ func (s *messageHubServiceServer) serveSetPostLimitJSON(ctx context.Context, res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubSetPostLimitRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2420,15 +2456,14 @@ func (s *messageHubServiceServer) serveSetPostLimitJSON(ctx context.Context, res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2547,9 +2582,15 @@ func (s *messageHubServiceServer) serveSetAllowFriendGroupsJSON(ctx context.Cont return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubSetAllowFriendGroupsRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2595,15 +2636,14 @@ func (s *messageHubServiceServer) serveSetAllowFriendGroupsJSON(ctx context.Cont ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2722,9 +2762,15 @@ func (s *messageHubServiceServer) serveSetExpirationDaysJSON(ctx context.Context return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubSetExpirationDaysRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2770,15 +2816,14 @@ func (s *messageHubServiceServer) serveSetExpirationDaysJSON(ctx context.Context ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2897,9 +2942,15 @@ func (s *messageHubServiceServer) serveReportMessageJSON(ctx context.Context, re return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubReportMessageRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2945,15 +2996,14 @@ func (s *messageHubServiceServer) serveReportMessageJSON(ctx context.Context, re ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3072,9 +3122,15 @@ func (s *messageHubServiceServer) serveBlockUserJSON(ctx context.Context, resp h return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubBlockUserRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -3120,15 +3176,14 @@ func (s *messageHubServiceServer) serveBlockUserJSON(ctx context.Context, resp h ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -3225,7 +3280,7 @@ func (s *messageHubServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *messageHubServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/messagehub_internal.twirp.go b/backend/userhub/rpc/messagehub_internal.twirp.go index 513808be..c1531c1c 100644 --- a/backend/userhub/rpc/messagehub_internal.twirp.go +++ b/backend/userhub/rpc/messagehub_internal.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: messagehub_internal.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -431,9 +431,15 @@ func (s *messageHubInternalServiceServer) servePostNotificationsJSON(ctx context return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(MessageHubInternalPostNotificationsRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -479,15 +485,14 @@ func (s *messageHubInternalServiceServer) servePostNotificationsJSON(ctx context ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -606,9 +611,15 @@ func (s *messageHubInternalServiceServer) serveExpirationDaysJSON(ctx context.Co return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -654,15 +665,14 @@ func (s *messageHubInternalServiceServer) serveExpirationDaysJSON(ctx context.Co ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -759,7 +769,7 @@ func (s *messageHubInternalServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *messageHubInternalServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/notification.twirp.go b/backend/userhub/rpc/notification.twirp.go index d247c2db..b54a3198 100644 --- a/backend/userhub/rpc/notification.twirp.go +++ b/backend/userhub/rpc/notification.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: notification.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -629,9 +629,15 @@ func (s *notificationServiceServer) serveCountJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -677,15 +683,14 @@ func (s *notificationServiceServer) serveCountJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -804,9 +809,15 @@ func (s *notificationServiceServer) serveNotificationsJSON(ctx context.Context, return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -852,15 +863,14 @@ func (s *notificationServiceServer) serveNotificationsJSON(ctx context.Context, ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -979,9 +989,15 @@ func (s *notificationServiceServer) serveCleanJSON(ctx context.Context, resp htt return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(NotificationCleanRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1027,15 +1043,14 @@ func (s *notificationServiceServer) serveCleanJSON(ctx context.Context, resp htt ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1154,9 +1169,15 @@ func (s *notificationServiceServer) serveMarkReadJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(NotificationMarkReadRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1202,15 +1223,14 @@ func (s *notificationServiceServer) serveMarkReadJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1307,7 +1327,7 @@ func (s *notificationServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *notificationServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/token.twirp.go b/backend/userhub/rpc/token.twirp.go index 3e3bc49a..5c8afcad 100644 --- a/backend/userhub/rpc/token.twirp.go +++ b/backend/userhub/rpc/token.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: token.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -530,9 +530,15 @@ func (s *tokenServiceServer) serveAuthJSON(ctx context.Context, resp http.Respon return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -578,15 +584,14 @@ func (s *tokenServiceServer) serveAuthJSON(ctx context.Context, resp http.Respon ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -705,9 +710,15 @@ func (s *tokenServiceServer) servePostMessageJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(TokenPostMessageRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -753,15 +764,14 @@ func (s *tokenServiceServer) servePostMessageJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -880,9 +890,15 @@ func (s *tokenServiceServer) serveGetMessagesJSON(ctx context.Context, resp http return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -928,15 +944,14 @@ func (s *tokenServiceServer) serveGetMessagesJSON(ctx context.Context, resp http ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1033,7 +1048,7 @@ func (s *tokenServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *tokenServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./" diff --git a/backend/userhub/rpc/user.twirp.go b/backend/userhub/rpc/user.twirp.go index d990fb98..a68223d0 100644 --- a/backend/userhub/rpc/user.twirp.go +++ b/backend/userhub/rpc/user.twirp.go @@ -1,18 +1,18 @@ -// Code generated by protoc-gen-twirp v7.2.0, DO NOT EDIT. +// Code generated by protoc-gen-twirp v8.0.0, DO NOT EDIT. // source: user.proto package rpc -import bytes "bytes" -import strings "strings" import context "context" import fmt "fmt" -import ioutil "io/ioutil" import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" import strconv "strconv" +import strings "strings" -import jsonpb "github.com/golang/protobuf/jsonpb" -import proto "github.com/golang/protobuf/proto" +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" import twirp "github.com/twitchtv/twirp" import ctxsetters "github.com/twitchtv/twirp/ctxsetters" @@ -1124,9 +1124,15 @@ func (s *userServiceServer) serveFriendsJSON(ctx context.Context, resp http.Resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1172,15 +1178,14 @@ func (s *userServiceServer) serveFriendsJSON(ctx context.Context, resp http.Resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1299,9 +1304,15 @@ func (s *userServiceServer) serveFriendsOfFriendsJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1347,15 +1358,14 @@ func (s *userServiceServer) serveFriendsOfFriendsJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1474,9 +1484,15 @@ func (s *userServiceServer) serveMeJSON(ctx context.Context, resp http.ResponseW return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1522,15 +1538,14 @@ func (s *userServiceServer) serveMeJSON(ctx context.Context, resp http.ResponseW ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1649,9 +1664,15 @@ func (s *userServiceServer) serveEditProfileJSON(ctx context.Context, resp http. return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(UserEditProfileRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1697,15 +1718,14 @@ func (s *userServiceServer) serveEditProfileJSON(ctx context.Context, resp http. ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1824,9 +1844,15 @@ func (s *userServiceServer) serveUsersJSON(ctx context.Context, resp http.Respon return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(UserUsersRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -1872,15 +1898,14 @@ func (s *userServiceServer) serveUsersJSON(ctx context.Context, resp http.Respon ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -1999,9 +2024,15 @@ func (s *userServiceServer) serveUserJSON(ctx context.Context, resp http.Respons return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(UserUserRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2047,15 +2078,14 @@ func (s *userServiceServer) serveUserJSON(ctx context.Context, resp http.Respons ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2174,9 +2204,15 @@ func (s *userServiceServer) serveRegisterFCMTokenJSON(ctx context.Context, resp return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(UserRegisterFCMTokenRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2222,15 +2258,14 @@ func (s *userServiceServer) serveRegisterFCMTokenJSON(ctx context.Context, resp ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2349,9 +2384,15 @@ func (s *userServiceServer) serveBlockUserJSON(ctx context.Context, resp http.Re return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(UserBlockUserRequest) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2397,15 +2438,14 @@ func (s *userServiceServer) serveBlockUserJSON(ctx context.Context, resp http.Re ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2524,9 +2564,15 @@ func (s *userServiceServer) serveDeleteMeJSON(ctx context.Context, resp http.Res return } + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } reqContent := new(Empty) - unmarshaler := jsonpb.Unmarshaler{AllowUnknownFields: true} - if err = unmarshaler.Unmarshal(req.Body, reqContent); err != nil { + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) return } @@ -2572,15 +2618,14 @@ func (s *userServiceServer) serveDeleteMeJSON(ctx context.Context, resp http.Res ctx = callResponsePrepared(ctx, s.hooks) - var buf bytes.Buffer - marshaler := &jsonpb.Marshaler{OrigName: true, EmitDefaults: !s.jsonSkipDefaults} - if err = marshaler.Marshal(&buf, respContent); err != nil { + marshaler := &protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) return } ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) - respBytes := buf.Bytes() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) resp.WriteHeader(http.StatusOK) @@ -2677,7 +2722,7 @@ func (s *userServiceServer) ServiceDescriptor() ([]byte, int) { } func (s *userServiceServer) ProtocGenTwirpVersion() string { - return "v7.2.0" + return "v8.0.0" } // PathPrefix returns the base service path, in the form: "//./"