github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/framework/qdrmanagement/entities/linkroute.go (about) 1 package entities 2 3 import ( 4 "encoding/json" 5 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities/common" 6 "strconv" 7 "strings" 8 ) 9 10 type LinkRoute struct { 11 EntityCommon 12 Prefix string `json:"prefix"` 13 Pattern string `json:"pattern"` 14 AddExternalPrefix string `json:"addExternalPrefix"` 15 DelExternalPrefix string `json:"delExternalPrefix"` 16 ContainerId string `json:"containerId"` 17 Connection string `json:"connection"` 18 Distribution LinkDistributionType `json:"distribution,string"` 19 Direction common.DirectionType `json:"direction,string"` 20 OperStatus LinkRouteOperStatusType `json:"operStatus,string"` 21 } 22 23 func (LinkRoute) GetEntityId() string { 24 return "router.config.linkRoute" 25 } 26 27 type LinkDistributionType int 28 29 const ( 30 LinkDistributionBalanced LinkDistributionType = iota 31 ) 32 33 // Unmarshal JSON return the appropriate LinkDistributionType for parsed string 34 func (d *LinkDistributionType) UnmarshalJSON(b []byte) error { 35 var s string 36 37 if len(b) == 0 { 38 return nil 39 } 40 41 if b[0] != '"' { 42 b = []byte(strconv.Quote(string(b))) 43 } 44 if err := json.Unmarshal(b, &s); err != nil { 45 return err 46 } 47 switch strings.ToLower(s) { 48 case "linkBalanced": 49 *d = LinkDistributionBalanced 50 } 51 return nil 52 53 } 54 55 // MarshalJSON returns the string represenation of LinkDistributionType 56 func (d LinkDistributionType) MarshalJSON() ([]byte, error) { 57 var s string 58 switch d { 59 case LinkDistributionBalanced: 60 s = "linkBalanced" 61 } 62 return json.Marshal(s) 63 } 64 65 type LinkRouteOperStatusType int 66 67 const ( 68 LinkRouteOperStatusInactive LinkRouteOperStatusType = iota 69 LinkRouteOperStatusActive 70 ) 71 72 // Unmarshal JSON return the appropriate LinkRouteOperStatusType for parsed string 73 func (d *LinkRouteOperStatusType) UnmarshalJSON(b []byte) error { 74 var s string 75 76 if len(b) == 0 { 77 return nil 78 } 79 80 if b[0] != '"' { 81 b = []byte(strconv.Quote(string(b))) 82 } 83 if err := json.Unmarshal(b, &s); err != nil { 84 return err 85 } 86 switch strings.ToLower(s) { 87 case "inactive": 88 *d = LinkRouteOperStatusInactive 89 case "active": 90 *d = LinkRouteOperStatusActive 91 } 92 return nil 93 94 } 95 96 // MarshalJSON returns the string represenation of LinkRouteOperStatusType 97 func (d LinkRouteOperStatusType) MarshalJSON() ([]byte, error) { 98 var s string 99 switch d { 100 case LinkRouteOperStatusInactive: 101 s = "inactive" 102 case LinkRouteOperStatusActive: 103 s = "active" 104 } 105 return json.Marshal(s) 106 }