From 5a4dc952ee6feaf5102ed3baa42230699aa50498 Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Tue, 19 Feb 2019 13:36:02 +0100 Subject: [PATCH] Fixed linter errors. --- hash.go | 4 ++-- hashid.go | 16 ++++++++-------- id.go | 24 ++++++++++++------------ util.go | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/hash.go b/hash.go index 06c8a50..5b655bc 100644 --- a/hash.go +++ b/hash.go @@ -2,13 +2,13 @@ package hide var hash Hash -// Interface used to marshal/unmarshal hide.ID to/from JSON. +// Hash is used to marshal/unmarshal hide.ID to/from JSON. type Hash interface { Encode(ID) ([]byte, error) Decode([]byte) (ID, error) } -// Sets the hide.Hash used to marshal/unmarshal hide.ID to/from JSON. +// UseHash sets the hide.Hash used to marshal/unmarshal hide.ID to/from JSON. // hide.HashID is used by default. func UseHash(hasher Hash) { hash = hasher diff --git a/hashid.go b/hashid.go index acc13cc..14e7282 100644 --- a/hashid.go +++ b/hashid.go @@ -11,14 +11,14 @@ type HashID struct { MinLength int } -// Creates a new HashID with given salt and minimum hash length. +// NewHashID creates a new HashID with given salt and minimum hash length. func NewHashID(salt string, minlen int) *HashID { return &HashID{salt, minlen} } // Encode implements the hide.Hash interface. -func (this *HashID) Encode(id ID) ([]byte, error) { - hash, err := this.newHash() +func (hasher *HashID) Encode(id ID) ([]byte, error) { + hash, err := hasher.newHash() if err != nil { return nil, err @@ -34,12 +34,12 @@ func (this *HashID) Encode(id ID) ([]byte, error) { } // Decode implements the hide.Hash interface. -func (this *HashID) Decode(data []byte) (ID, error) { +func (hasher *HashID) Decode(data []byte) (ID, error) { if len(data) == 0 { return 0, nil } - hash, err := this.newHash() + hash, err := hasher.newHash() if err != nil { return 0, err @@ -59,10 +59,10 @@ func (this *HashID) Decode(data []byte) (ID, error) { } // Creates a new hashids.HashID object to encode/decode IDs. -func (this *HashID) newHash() (*hashids.HashID, error) { +func (hasher *HashID) newHash() (*hashids.HashID, error) { config := hashids.NewData() - config.Salt = this.Salt - config.MinLength = this.MinLength + config.Salt = hasher.Salt + config.MinLength = hasher.MinLength hash, err := hashids.NewWithData(config) if err != nil { diff --git a/id.go b/id.go index 80937ac..2ca9004 100644 --- a/id.go +++ b/id.go @@ -13,9 +13,9 @@ import ( type ID int64 // Scan implements the Scanner interface. -func (this *ID) Scan(value interface{}) error { +func (hideid *ID) Scan(value interface{}) error { if value == nil { - *this = 0 + *hideid = 0 return nil } @@ -25,26 +25,26 @@ func (this *ID) Scan(value interface{}) error { return errors.New("unexpected type") } - *this = ID(id) + *hideid = ID(id) return nil } // Value implements the driver Valuer interface. -func (this ID) Value() (driver.Value, error) { - if this == 0 { +func (hideid ID) Value() (driver.Value, error) { + if hideid == 0 { return nil, nil } - return int64(this), nil + return int64(hideid), nil } // MarshalJSON implements the encoding json interface. -func (this ID) MarshalJSON() ([]byte, error) { - if this == 0 { +func (hideid ID) MarshalJSON() ([]byte, error) { + if hideid == 0 { return json.Marshal(nil) } - result, err := hash.Encode(this) + result, err := hash.Encode(hideid) if err != nil { return nil, err @@ -54,10 +54,10 @@ func (this ID) MarshalJSON() ([]byte, error) { } // UnmarshalJSON implements the encoding json interface. -func (this *ID) UnmarshalJSON(data []byte) error { +func (hideid *ID) UnmarshalJSON(data []byte) error { // convert null to 0 if strings.TrimSpace(string(data)) == "null" { - *this = 0 + *hideid = 0 return nil } @@ -72,6 +72,6 @@ func (this *ID) UnmarshalJSON(data []byte) error { return err } - *this = ID(result) + *hideid = ID(result) return nil } diff --git a/util.go b/util.go index 6b3e4c5..b598d8f 100644 --- a/util.go +++ b/util.go @@ -1,11 +1,11 @@ package hide -// Returns a new ID from given hash by using the hasher or an error if it couldn't decode the hash. +// FromString returns a new ID from given hash by using the hasher or an error if it couldn't decode the hash. func FromString(id string) (ID, error) { return hash.Decode([]byte(id)) } -// Returns a new hash from given ID by using the hasher or an error if it couldn't encode the ID. +// ToString returns a new hash from given ID by using the hasher or an error if it couldn't encode the ID. // If ID is 0, "null" will be returned. func ToString(id ID) (string, error) { if id == 0 {