@@ -230,7 +230,7 @@ func (c *Client) DNSNameservers(ctx context.Context) ([]string, error) {
230230
231231type (
232232 ACL struct {
233- ACLs []ACLEntry `json:"acls" hujson:"ACLs,omitempty"`
233+ ACLs []ACLEntry `json:"acls,omitempty " hujson:"ACLs,omitempty"`
234234 AutoApprovers * ACLAutoApprovers `json:"autoapprovers,omitempty" hujson:"AutoApprovers,omitempty"`
235235 Groups map [string ][]string `json:"groups,omitempty" hujson:"Groups,omitempty"`
236236 Hosts map [string ]string `json:"hosts,omitempty" hujson:"Hosts,omitempty"`
@@ -245,25 +245,25 @@ type (
245245 }
246246
247247 ACLAutoApprovers struct {
248- Routes map [string ][]string `json:"routes" hujson:"Routes"`
249- ExitNode []string `json:"exitNode" hujson:"ExitNode"`
248+ Routes map [string ][]string `json:"routes,omitempty " hujson:"Routes,omitempty "`
249+ ExitNode []string `json:"exitNode,omitempty " hujson:"ExitNode,omitempty "`
250250 }
251251
252252 ACLEntry struct {
253- Action string `json:"action" hujson:"Action"`
254- Ports []string `json:"ports" hujson:"Ports"`
255- Users []string `json:"users" hujson:"Users"`
256- Source []string `json:"src" hujson:"Src"`
257- Destination []string `json:"dst" hujson:"Dst"`
258- Protocol string `json:"proto" hujson:"Proto"`
253+ Action string `json:"action,omitempty " hujson:"Action,omitempty "`
254+ Ports []string `json:"ports,omitempty " hujson:"Ports,omitempty "`
255+ Users []string `json:"users,omitempty " hujson:"Users,omitempty "`
256+ Source []string `json:"src,omitempty " hujson:"Src,omitempty "`
257+ Destination []string `json:"dst,omitempty " hujson:"Dst,omitempty "`
258+ Protocol string `json:"proto,omitempty " hujson:"Proto,omitempty "`
259259 }
260260
261261 ACLTest struct {
262- User string `json:"user" hujson:"User"`
263- Allow []string `json:"allow" hujson:"Allow"`
264- Deny []string `json:"deny" hujson:"Deny"`
265- Source string `json:"src" hujson:"Src"`
266- Accept []string `json:"accept" hujson:"Accept"`
262+ User string `json:"user,omitempty " hujson:"User,omitempty "`
263+ Allow []string `json:"allow,omitempty " hujson:"Allow,omitempty "`
264+ Deny []string `json:"deny,omitempty " hujson:"Deny,omitempty "`
265+ Source string `json:"src,omitempty " hujson:"Src,omitempty "`
266+ Accept []string `json:"accept,omitempty " hujson:"Accept,omitempty "`
267267 }
268268
269269 ACLDERPMap struct {
@@ -294,11 +294,11 @@ type (
294294 }
295295
296296 ACLSSH struct {
297- Action string `json:"action" hujson:"Action"`
298- Users []string `json:"users" hujson:"Users"`
299- Source []string `json:"src" hujson:"Src"`
300- Destination []string `json:"dst" hujson:"Dst"`
301- CheckPeriod Duration `json:"checkPeriod" hujson:"CheckPeriod"`
297+ Action string `json:"action,omitempty " hujson:"Action,omitempty "`
298+ Users []string `json:"users,omitempty " hujson:"Users,omitempty "`
299+ Source []string `json:"src,omitempty " hujson:"Src,omitempty "`
300+ Destination []string `json:"dst,omitempty " hujson:"Dst,omitempty "`
301+ CheckPeriod Duration `json:"checkPeriod,omitempty " hujson:"CheckPeriod,omitempty "`
302302 }
303303
304304 NodeAttrGrant struct {
@@ -694,31 +694,25 @@ func ErrorData(err error) []APIErrorData {
694694
695695// The Duration type wraps a time.Duration, allowing it to be JSON marshalled as a string like "20h" rather than
696696// a numeric value.
697- type Duration struct {
698- time.Duration
699- }
697+ type Duration time.Duration
700698
701- // MarshalJSON is an implementation of json.Marshal.
702- func (d Duration ) MarshalJSON () ([]byte , error ) {
703- return json .Marshal (d .Duration .String ())
699+ func (d Duration ) String () string {
700+ return time .Duration (d ).String ()
704701}
705702
706- // UnmarshalJSON unmarshals the content of data as a time.Duration, a blank string will keep the duration at its zero value.
707- func (d * Duration ) UnmarshalJSON (data []byte ) error {
708- if string (data ) == `""` {
709- return nil
710- }
703+ func (d Duration ) MarshalText () ([]byte , error ) {
704+ return []byte (d .String ()), nil
705+ }
711706
712- var str string
713- if err := json .Unmarshal (data , & str ); err != nil {
714- return err
707+ func (d * Duration ) UnmarshalText (b []byte ) error {
708+ text := string (b )
709+ if text == "" {
710+ text = "0s"
715711 }
716-
717- dur , err := time .ParseDuration (str )
712+ pd , err := time .ParseDuration (text )
718713 if err != nil {
719714 return err
720715 }
721-
722- d .Duration = dur
716+ * d = Duration (pd )
723717 return nil
724718}
0 commit comments