10000 [Maintenance] Allow GRPC Marshal Opts (#1841) · arangodb/kube-arangodb@297c556 · GitHub
[go: up one dir, main page]

Skip to content

Commit 297c556

Browse files
authored
[Maintenance] Allow GRPC Marshal Opts (#1841)
1 parent 025694f commit 297c556

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- (Feature) (Platform) Generate GRPC Gateway Code
77
- (Feature) (Platform) Identity Endpoint
88
- (Feature) (Platform) Authz V1 Types
9+
- (Maintenance) Allow GRPC Marshal Opts
910

1011
## [1.2.46](https://github.com/arangodb/kube-arangodb/tree/1.2.46) (2025-02-24)
1112
- (Bugfix) Clean Phase change properly during upgrade

pkg/deployment/resources/gateway/gateway_config_destination_static.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"encoding/json"
2525
"net/http"
2626

27+
"google.golang.org/protobuf/encoding/protojson"
28+
2729
"github.com/arangodb/kube-arangodb/pkg/util"
2830
)
2931

@@ -32,7 +34,7 @@ type ConfigDestinationStaticInterface interface {
3234
StaticResponse() ([]byte, uint32, error)
3335
}
3436

35-
type ConfigDestinationStaticMarshaller[T any] func(in T) ([]byte, error)
37+
type ConfigDestinationStaticMarshaller[T any] func(in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error)
3638

3739
type ConfigDestinationStatic[T any] struct {
3840
Code *uint32 `json:"insecure,omitempty"`

pkg/util/grpc/marshal.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ import (
2828
"github.com/arangodb/kube-arangodb/pkg/util"
2929
)
3030

31-
func Marshal[T proto.Message](in T) ([]byte, error) {
32-
data, err := protojson.MarshalOptions{
31+
func Marshal[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) {
32+
options := protojson.MarshalOptions{
3333
UseProtoNames: true,
34-
}.Marshal(in)
34+
}
35+
36+
util.ApplyMods(&options, opts...)
37+
38+
data, err := options.Marshal(in)
3539
if err != nil {
3640
return nil, err
3741
}
3842

3943
return data, err
4044
}
4145

42-
func MarshalYAML[T proto.Message](in T) ([]byte, error) {
43-
data, err := Marshal[T](in)
46+
func MarshalYAML[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) {
47+
data, err := Marshal[T](in, opts...)
4448
if err != nil {
4549
return nil, err
4650
}
@@ -49,13 +53,17 @@ func MarshalYAML[T proto.Message](in T) ([]byte, error) {
4953
return data, err
5054
}
5155

52-
func Unmarshal[T proto.Message](data []byte) (T, error) {
56+
func Unmarshal[T proto.Message](data []byte, opts ...util.Mod[protojson.UnmarshalOptions]) (T, error) {
5357
v, err := util.DeepType[T]()
5458
if err != nil {
5559
return util.Default[T](), err
5660
}
5761

58-
if err := (protojson.UnmarshalOptions{}).Unmarshal(data, v); err != nil {
62+
options := protojson.UnmarshalOptions{}
63+
64+
util.ApplyMods(&options, opts...)
65+
66+
if err := options.Unmarshal(data, v); err != nil {
5967
return util.Default[T](), err
6068
}
6169

0 commit comments

Comments
 (0)
0