Skip to content

Commit

Permalink
Marshal/unmarshal to JSON to deal with time.Duration field
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Feb 25, 2024
1 parent 12609d2 commit dced52e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,25 @@ func (a *API) GetGlobalConfig(_ context.Context, group *v1.Group) (*structpb.Str

// GetPluginConfig returns the plugin configuration of the GatewayD.
func (a *API) GetPluginConfig(context.Context, *emptypb.Empty) (*structpb.Struct, error) {
pluginConfig, err := structpb.NewStruct(a.Config.PluginKoanf.All())
jsonData, err := json.Marshal(a.Config.PluginKoanf.All())
if err != nil {
metrics.APIRequestsErrors.WithLabelValues(
"GET", "/v1/GatewayDPluginService/GetPluginConfig", codes.Internal.String(),
).Inc()
return nil, status.Errorf(codes.Internal, "failed to marshal plugin config: %v", err)
}

var pluginConfigMap map[string]any

err = json.Unmarshal(jsonData, &pluginConfigMap)
if err != nil {
metrics.APIRequestsErrors.WithLabelValues(
"GET", "/v1/GatewayDPluginService/GetPluginConfig", codes.Internal.String(),
).Inc()
return nil, status.Errorf(codes.Internal, "failed to unmarshal plugin config: %v", err)
}

pluginConfig, err := structpb.NewStruct(pluginConfigMap)
if err != nil {
metrics.APIRequestsErrors.WithLabelValues(
"GET", "/v1/GatewayDPluginService/GetPluginConfig", codes.Internal.String(),
Expand Down

0 comments on commit dced52e

Please sign in to comment.