Skip to content

Commit 5a4dc95

Browse files
committed
Fixed linter errors.
1 parent baa51bb commit 5a4dc95

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

hash.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package hide
22

33
var hash Hash
44

5-
// Interface used to marshal/unmarshal hide.ID to/from JSON.
5+
// Hash is used to marshal/unmarshal hide.ID to/from JSON.
66
type Hash interface {
77
Encode(ID) ([]byte, error)
88
Decode([]byte) (ID, error)
99
}
1010

11-
// Sets the hide.Hash used to marshal/unmarshal hide.ID to/from JSON.
11+
// UseHash sets the hide.Hash used to marshal/unmarshal hide.ID to/from JSON.
1212
// hide.HashID is used by default.
1313
func UseHash(hasher Hash) {
1414
hash = hasher

hashid.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ type HashID struct {
1111
MinLength int
1212
}
1313

14-
// Creates a new HashID with given salt and minimum hash length.
14+
// NewHashID creates a new HashID with given salt and minimum hash length.
1515
func NewHashID(salt string, minlen int) *HashID {
1616
return &HashID{salt, minlen}
1717
}
1818

1919
// Encode implements the hide.Hash interface.
20-
func (this *HashID) Encode(id ID) ([]byte, error) {
21-
hash, err := this.newHash()
20+
func (hasher *HashID) Encode(id ID) ([]byte, error) {
21+
hash, err := hasher.newHash()
2222

2323
if err != nil {
2424
return nil, err
@@ -34,12 +34,12 @@ func (this *HashID) Encode(id ID) ([]byte, error) {
3434
}
3535

3636
// Decode implements the hide.Hash interface.
37-
func (this *HashID) Decode(data []byte) (ID, error) {
37+
func (hasher *HashID) Decode(data []byte) (ID, error) {
3838
if len(data) == 0 {
3939
return 0, nil
4040
}
4141

42-
hash, err := this.newHash()
42+
hash, err := hasher.newHash()
4343

4444
if err != nil {
4545
return 0, err
@@ -59,10 +59,10 @@ func (this *HashID) Decode(data []byte) (ID, error) {
5959
}
6060

6161
// Creates a new hashids.HashID object to encode/decode IDs.
62-
func (this *HashID) newHash() (*hashids.HashID, error) {
62+
func (hasher *HashID) newHash() (*hashids.HashID, error) {
6363
config := hashids.NewData()
64-
config.Salt = this.Salt
65-
config.MinLength = this.MinLength
64+
config.Salt = hasher.Salt
65+
config.MinLength = hasher.MinLength
6666
hash, err := hashids.NewWithData(config)
6767

6868
if err != nil {

id.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
type ID int64
1414

1515
// Scan implements the Scanner interface.
16-
func (this *ID) Scan(value interface{}) error {
16+
func (hideid *ID) Scan(value interface{}) error {
1717
if value == nil {
18-
*this = 0
18+
*hideid = 0
1919
return nil
2020
}
2121

@@ -25,26 +25,26 @@ func (this *ID) Scan(value interface{}) error {
2525
return errors.New("unexpected type")
2626
}
2727

28-
*this = ID(id)
28+
*hideid = ID(id)
2929
return nil
3030
}
3131

3232
// Value implements the driver Valuer interface.
33-
func (this ID) Value() (driver.Value, error) {
34-
if this == 0 {
33+
func (hideid ID) Value() (driver.Value, error) {
34+
if hideid == 0 {
3535
return nil, nil
3636
}
3737

38-
return int64(this), nil
38+
return int64(hideid), nil
3939
}
4040

4141
// MarshalJSON implements the encoding json interface.
42-
func (this ID) MarshalJSON() ([]byte, error) {
43-
if this == 0 {
42+
func (hideid ID) MarshalJSON() ([]byte, error) {
43+
if hideid == 0 {
4444
return json.Marshal(nil)
4545
}
4646

47-
result, err := hash.Encode(this)
47+
result, err := hash.Encode(hideid)
4848

4949
if err != nil {
5050
return nil, err
@@ -54,10 +54,10 @@ func (this ID) MarshalJSON() ([]byte, error) {
5454
}
5555

5656
// UnmarshalJSON implements the encoding json interface.
57-
func (this *ID) UnmarshalJSON(data []byte) error {
57+
func (hideid *ID) UnmarshalJSON(data []byte) error {
5858
// convert null to 0
5959
if strings.TrimSpace(string(data)) == "null" {
60-
*this = 0
60+
*hideid = 0
6161
return nil
6262
}
6363

@@ -72,6 +72,6 @@ func (this *ID) UnmarshalJSON(data []byte) error {
7272
return err
7373
}
7474

75-
*this = ID(result)
75+
*hideid = ID(result)
7676
return nil
7777
}

util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package hide
22

3-
// Returns a new ID from given hash by using the hasher or an error if it couldn't decode the hash.
3+
// FromString returns a new ID from given hash by using the hasher or an error if it couldn't decode the hash.
44
func FromString(id string) (ID, error) {
55
return hash.Decode([]byte(id))
66
}
77

8-
// Returns a new hash from given ID by using the hasher or an error if it couldn't encode the ID.
8+
// ToString returns a new hash from given ID by using the hasher or an error if it couldn't encode the ID.
99
// If ID is 0, "null" will be returned.
1010
func ToString(id ID) (string, error) {
1111
if id == 0 {

0 commit comments

Comments
 (0)