Fix extra quotes in unmarshaling of the NamespacedName object

This commit is contained in:
Oleksii Kliukin 2018-06-13 22:38:28 +02:00
parent 144c08695b
commit 4bf9cb9fd9
1 changed files with 9 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package spec
import ( import (
"database/sql" "database/sql"
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -15,7 +16,6 @@ import (
"k8s.io/client-go/pkg/apis/apps/v1beta1" "k8s.io/client-go/pkg/apis/apps/v1beta1"
policyv1beta1 "k8s.io/client-go/pkg/apis/policy/v1beta1" policyv1beta1 "k8s.io/client-go/pkg/apis/policy/v1beta1"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"encoding/json"
) )
// EventType contains type of the events for the TPRs and Pods received from Kubernetes // EventType contains type of the events for the TPRs and Pods received from Kubernetes
@ -190,7 +190,11 @@ func (n *NamespacedName) Decode(value string) error {
func (n *NamespacedName) UnmarshalJSON(data []byte) error { func (n *NamespacedName) UnmarshalJSON(data []byte) error {
result := NamespacedName{} result := NamespacedName{}
if err := result.Decode(string(data)); err != nil { var tmp string
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
if err := result.Decode(tmp); err != nil {
return err return err
} }
*n = result *n = result
@ -252,7 +256,7 @@ type Duration time.Duration
func (d *Duration) UnmarshalJSON(b []byte) error { func (d *Duration) UnmarshalJSON(b []byte) error {
var ( var (
v interface{} v interface{}
err error err error
) )
if err = json.Unmarshal(b, &v); err != nil { if err = json.Unmarshal(b, &v); err != nil {
@ -260,7 +264,7 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
} }
switch val := v.(type) { switch val := v.(type) {
case string: case string:
t, err := time.ParseDuration(val); t, err := time.ParseDuration(val)
if err != nil { if err != nil {
return err return err
} }
@ -274,4 +278,4 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
return fmt.Errorf("could not recognize type %T as a valid type to unmarshal to Duration", val) return fmt.Errorf("could not recognize type %T as a valid type to unmarshal to Duration", val)
} }
return nil return nil
} }