Pull request: home: imp err handling, marshalling

Merge in DNS/adguard-home from imp-code to master

Squashed commit of the following:

commit 9433fb9b0154a1cfaf804edbfa8531efbbcbf68a
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri May 14 19:24:32 2021 +0300

    home: imp err handling, marshalling
This commit is contained in:
Ainar Garipov
2021-05-14 19:41:45 +03:00
parent 9d788a2983
commit a031cae447
6 changed files with 56 additions and 63 deletions

View File

@@ -43,8 +43,8 @@ func (l *Lease) IsStatic() (ok bool) {
return l != nil && l.Expiry.Unix() == leaseExpireStatic
}
// MarshalJSON implements the json.Marshaler interface for *Lease.
func (l *Lease) MarshalJSON() ([]byte, error) {
// MarshalJSON implements the json.Marshaler interface for Lease.
func (l Lease) MarshalJSON() ([]byte, error) {
var expiryStr string
if !l.IsStatic() {
// The front-end is waiting for RFC 3999 format of the time
@@ -59,11 +59,11 @@ func (l *Lease) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
HWAddr string `json:"mac"`
Expiry string `json:"expires,omitempty"`
*lease
lease
}{
HWAddr: l.HWAddr.String(),
Expiry: expiryStr,
lease: (*lease)(l),
lease: lease(l),
})
}
@@ -71,8 +71,8 @@ func (l *Lease) MarshalJSON() ([]byte, error) {
func (l *Lease) UnmarshalJSON(data []byte) (err error) {
type lease Lease
aux := struct {
HWAddr string `json:"mac"`
*lease
HWAddr string `json:"mac"`
}{
lease: (*lease)(l),
}