From 472ccd6d15731b0530a9c63cf4ba91567407f3ef Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Tue, 19 Feb 2019 13:44:40 +0100 Subject: [PATCH] Fixed linter errors. --- bool.go | 36 +++++++++++++++++++----------------- doc.go | 2 +- float64.go | 36 +++++++++++++++++++----------------- int64.go | 36 +++++++++++++++++++----------------- string.go | 36 +++++++++++++++++++----------------- 5 files changed, 77 insertions(+), 69 deletions(-) diff --git a/bool.go b/bool.go index fc5be3b..81052be 100644 --- a/bool.go +++ b/bool.go @@ -5,26 +5,28 @@ import ( "encoding/json" ) -// Nullable boolean type based on sql.NullBool, that supports parsing to/from JSON. +// Bool is a nullable boolean type based on sql.NullBool, that supports parsing to/from JSON. type Bool struct { sql.NullBool } -// Returns a new nullable Bool object. +// NewBool returns a new nullable Bool object. // This is equivalent to `null.Bool{sql.NullBool{Bool: b, Valid: valid}}`. func NewBool(b, valid bool) Bool { return Bool{sql.NullBool{Bool: b, Valid: valid}} } -func (this Bool) MarshalJSON() ([]byte, error) { - if this.Valid { - return json.Marshal(this.Bool) +// MarshalJSON implements the encoding json interface. +func (b Bool) MarshalJSON() ([]byte, error) { + if b.Valid { + return json.Marshal(b.Bool) } return json.Marshal(nil) } -func (this *Bool) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the encoding json interface. +func (b *Bool) UnmarshalJSON(data []byte) error { var value *bool if err := json.Unmarshal(data, &value); err != nil { @@ -32,23 +34,23 @@ func (this *Bool) UnmarshalJSON(data []byte) error { } if value != nil { - this.Valid = true - this.Bool = *value + b.Valid = true + b.Bool = *value } else { - this.Valid = false + b.Valid = false } return nil } -// Sets the value and valid to true. -func (this *Bool) SetValid(b bool) { - this.Bool = b - this.Valid = true +// SetValid sets the value and valid to true. +func (b *Bool) SetValid(value bool) { + b.Bool = value + b.Valid = true } -// Sets the value to default and valid to false. -func (this *Bool) SetNil() { - this.Bool = false - this.Valid = false +// SetNil sets the value to default and valid to false. +func (b *Bool) SetNil() { + b.Bool = false + b.Valid = false } diff --git a/doc.go b/doc.go index 151378a..1877959 100644 --- a/doc.go +++ b/doc.go @@ -1,2 +1,2 @@ -// Package "null" provides nullable types (based on database/sql) that can be parsed to and from JSON. +// Package null provides nullable types (based on database/sql) that can be parsed to and from JSON. package null diff --git a/float64.go b/float64.go index 70d2157..a498b82 100644 --- a/float64.go +++ b/float64.go @@ -5,26 +5,28 @@ import ( "encoding/json" ) -// Nullable float64 type based on sql.NullFloat64, that supports parsing to/from JSON. +// Float64 is a nullable float64 type based on sql.NullFloat64, that supports parsing to/from JSON. type Float64 struct { sql.NullFloat64 } -// Returns a new nullable Float64 object. +// NewFloat64 returns a new nullable Float64 object. // This is equivalent to `null.Float64{sql.NullFloat64{Float64: f, Valid: valid}}`. func NewFloat64(f float64, valid bool) Float64 { return Float64{sql.NullFloat64{Float64: f, Valid: valid}} } -func (this Float64) MarshalJSON() ([]byte, error) { - if this.Valid { - return json.Marshal(this.Float64) +// MarshalJSON implements the encoding json interface. +func (f Float64) MarshalJSON() ([]byte, error) { + if f.Valid { + return json.Marshal(f.Float64) } return json.Marshal(nil) } -func (this *Float64) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the encoding json interface. +func (f *Float64) UnmarshalJSON(data []byte) error { var value *float64 if err := json.Unmarshal(data, &value); err != nil { @@ -32,23 +34,23 @@ func (this *Float64) UnmarshalJSON(data []byte) error { } if value != nil { - this.Valid = true - this.Float64 = *value + f.Valid = true + f.Float64 = *value } else { - this.Valid = false + f.Valid = false } return nil } -// Sets the value and valid to true. -func (this *Float64) SetValid(f float64) { - this.Float64 = f - this.Valid = true +// SetValid sets the value and valid to true. +func (f *Float64) SetValid(value float64) { + f.Float64 = value + f.Valid = true } -// Sets the value to default and valid to false. -func (this *Float64) SetNil() { - this.Float64 = 0 - this.Valid = false +// SetNil sets the value to default and valid to false. +func (f *Float64) SetNil() { + f.Float64 = 0 + f.Valid = false } diff --git a/int64.go b/int64.go index f8e13fe..b267942 100644 --- a/int64.go +++ b/int64.go @@ -5,26 +5,28 @@ import ( "encoding/json" ) -// Nullable int64 type based on sql.NullInt64, that supports parsing to/from JSON. +// Int64 is a nullable int64 type based on sql.NullInt64, that supports parsing to/from JSON. type Int64 struct { sql.NullInt64 } -// Returns a new nullable Int64 object. +// NewInt64 returns a new nullable Int64 object. // This is equivalent to `null.Int64{sql.NullInt64{Int64: i, Valid: valid}}`. func NewInt64(i int64, valid bool) Int64 { return Int64{sql.NullInt64{Int64: i, Valid: valid}} } -func (this Int64) MarshalJSON() ([]byte, error) { - if this.Valid { - return json.Marshal(this.Int64) +// MarshalJSON implements the encoding json interface. +func (i Int64) MarshalJSON() ([]byte, error) { + if i.Valid { + return json.Marshal(i.Int64) } return json.Marshal(nil) } -func (this *Int64) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the encoding json interface. +func (i *Int64) UnmarshalJSON(data []byte) error { var value *int64 if err := json.Unmarshal(data, &value); err != nil { @@ -32,23 +34,23 @@ func (this *Int64) UnmarshalJSON(data []byte) error { } if value != nil { - this.Valid = true - this.Int64 = *value + i.Valid = true + i.Int64 = *value } else { - this.Valid = false + i.Valid = false } return nil } -// Sets the value and valid to true. -func (this *Int64) SetValid(i int64) { - this.Int64 = i - this.Valid = true +// SetValid sets the value and valid to true. +func (i *Int64) SetValid(value int64) { + i.Int64 = value + i.Valid = true } -// Sets the value to default and valid to false. -func (this *Int64) SetNil() { - this.Int64 = 0 - this.Valid = false +// SetNil sets the value to default and valid to false. +func (i *Int64) SetNil() { + i.Int64 = 0 + i.Valid = false } diff --git a/string.go b/string.go index 05117d8..762dade 100644 --- a/string.go +++ b/string.go @@ -5,26 +5,28 @@ import ( "encoding/json" ) -// Nullable string type based on sql.NullString, that supports parsing to/from JSON. +// String is a nullable string type based on sql.NullString, that supports parsing to/from JSON. type String struct { sql.NullString } -// Returns a new nullable String object. +// NewString returns a new nullable String object. // This is equivalent to `null.String{sql.NullString{String: s, Valid: valid}}`. func NewString(s string, valid bool) String { return String{sql.NullString{String: s, Valid: valid}} } -func (this String) MarshalJSON() ([]byte, error) { - if this.Valid { - return json.Marshal(this.String) +// MarshalJSON implements the encoding json interface. +func (s String) MarshalJSON() ([]byte, error) { + if s.Valid { + return json.Marshal(s.String) } return json.Marshal(nil) } -func (this *String) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the encoding json interface. +func (s *String) UnmarshalJSON(data []byte) error { var value *string if err := json.Unmarshal(data, &value); err != nil { @@ -32,23 +34,23 @@ func (this *String) UnmarshalJSON(data []byte) error { } if value != nil { - this.Valid = true - this.String = *value + s.Valid = true + s.String = *value } else { - this.Valid = false + s.Valid = false } return nil } -// Sets the value and valid to true. -func (this *String) SetValid(s string) { - this.String = s - this.Valid = true +// SetValid sets the value and valid to true. +func (s *String) SetValid(value string) { + s.String = value + s.Valid = true } -// Sets the value to default and valid to false. -func (this *String) SetNil() { - this.String = "" - this.Valid = false +// SetNil sets the value to default and valid to false. +func (s *String) SetNil() { + s.String = "" + s.Valid = false }