Skip to content

Commit

Permalink
style: linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Sep 8, 2024
1 parent e10acff commit 242f2a9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
41 changes: 36 additions & 5 deletions types/envelope/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func ParseMessage(message []byte) Envelope {
if err := v.UnmarshalJSON(message); err != nil {
return nil
}

return v
}

Expand Down Expand Up @@ -80,6 +81,7 @@ func (_ EventEnvelope) Label() string { return "EVENT" }

func (c EventEnvelope) String() string {
v, _ := json.Marshal(c)

return string(v)
}

Expand All @@ -88,11 +90,14 @@ func (v *EventEnvelope) UnmarshalJSON(data []byte) error {
arr := r.Array()
switch len(arr) {
case 2:

return easyjson.Unmarshal([]byte(arr[1].Raw), &v.Event)
case 3:
v.SubscriptionID = &arr[1].Str

return easyjson.Unmarshal([]byte(arr[2].Raw), &v.Event)
default:

return fmt.Errorf("failed to decode EVENT envelope")
}
}
Expand All @@ -105,6 +110,7 @@ func (v EventEnvelope) MarshalJSON() ([]byte, error) {
}
v.Event.MarshalEasyJSON(&w)
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -117,6 +123,7 @@ func (_ ReqEnvelope) Label() string { return "REQ" }

func (c ReqEnvelope) String() string {
v, _ := json.Marshal(c)

return string(v)
}

Expand Down Expand Up @@ -148,6 +155,7 @@ func (v ReqEnvelope) MarshalJSON() ([]byte, error) {
filter.MarshalEasyJSON(&w)
}
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -160,16 +168,17 @@ type CountEnvelope struct {
func (_ CountEnvelope) Label() string { return "COUNT" }
func (c CountEnvelope) String() string {
v, _ := json.Marshal(c)

return string(v)
}

func (v *CountEnvelope) UnmarshalJSON(data []byte) error {
func (c *CountEnvelope) UnmarshalJSON(data []byte) error {
r := gjson.ParseBytes(data)
arr := r.Array()
if len(arr) < 3 {
return fmt.Errorf("failed to decode COUNT envelope: missing filters")
}
v.SubscriptionID = arr[1].Str
c.SubscriptionID = arr[1].Str

if len(arr) < 3 {
return fmt.Errorf("COUNT array must have at least 3 items")
Expand All @@ -179,16 +188,17 @@ func (v *CountEnvelope) UnmarshalJSON(data []byte) error {
Count *int64 `json:"count"`
}
if err := json.Unmarshal([]byte(arr[2].Raw), &countResult); err == nil && countResult.Count != nil {
v.Count = countResult.Count
c.Count = countResult.Count

return nil
}

v.Filters = make([]filter.Filter, len(arr)-2)
c.Filters = make([]filter.Filter, len(arr)-2)
f := 0
for i := 2; i < len(arr); i++ {
item := []byte(arr[i].Raw)

if err := easyjson.Unmarshal(item, &v.Filters[f]); err != nil {
if err := easyjson.Unmarshal(item, &c.Filters[f]); err != nil {
return fmt.Errorf("%w -- on filter %d", err, f)
}

Expand All @@ -213,6 +223,7 @@ func (v CountEnvelope) MarshalJSON() ([]byte, error) {
}
}
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -221,6 +232,7 @@ type NoticeEnvelope string
func (_ NoticeEnvelope) Label() string { return "NOTICE" }
func (n NoticeEnvelope) String() string {
v, _ := json.Marshal(n)

return string(v)
}

Expand All @@ -231,6 +243,7 @@ func (v *NoticeEnvelope) UnmarshalJSON(data []byte) error {
return fmt.Errorf("failed to decode NOTICE envelope")
}
*v = NoticeEnvelope(arr[1].Str)

return nil
}

Expand All @@ -239,6 +252,7 @@ func (v NoticeEnvelope) MarshalJSON() ([]byte, error) {
w.RawString(`["NOTICE",`)
w.Raw(json.Marshal(string(v)))
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -247,6 +261,7 @@ type EOSEEnvelope string
func (_ EOSEEnvelope) Label() string { return "EOSE" }
func (e EOSEEnvelope) String() string {
v, _ := json.Marshal(e)

return string(v)
}

Expand All @@ -257,6 +272,7 @@ func (v *EOSEEnvelope) UnmarshalJSON(data []byte) error {
return fmt.Errorf("failed to decode EOSE envelope")
}
*v = EOSEEnvelope(arr[1].Str)

return nil
}

Expand All @@ -265,6 +281,7 @@ func (v EOSEEnvelope) MarshalJSON() ([]byte, error) {
w.RawString(`["EOSE",`)
w.Raw(json.Marshal(string(v)))
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -273,6 +290,7 @@ type CloseEnvelope string
func (_ CloseEnvelope) Label() string { return "CLOSE" }
func (c CloseEnvelope) String() string {
v, _ := json.Marshal(c)

return string(v)
}

Expand All @@ -282,8 +300,10 @@ func (v *CloseEnvelope) UnmarshalJSON(data []byte) error {
switch len(arr) {
case 2:
*v = CloseEnvelope(arr[1].Str)

return nil
default:

return fmt.Errorf("failed to decode CLOSE envelope")
}
}
Expand All @@ -293,6 +313,7 @@ func (v CloseEnvelope) MarshalJSON() ([]byte, error) {
w.RawString(`["CLOSE",`)
w.Raw(json.Marshal(string(v)))
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -304,6 +325,7 @@ type ClosedEnvelope struct {
func (_ ClosedEnvelope) Label() string { return "CLOSED" }
func (c ClosedEnvelope) String() string {
v, _ := json.Marshal(c)

return string(v)
}

Expand All @@ -313,8 +335,10 @@ func (v *ClosedEnvelope) UnmarshalJSON(data []byte) error {
switch len(arr) {
case 3:
*v = ClosedEnvelope{arr[1].Str, arr[2].Str}

return nil
default:

return fmt.Errorf("failed to decode CLOSED envelope")
}
}
Expand All @@ -326,6 +350,7 @@ func (v ClosedEnvelope) MarshalJSON() ([]byte, error) {
w.RawString(`,`)
w.Raw(json.Marshal(v.Reason))
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -338,6 +363,7 @@ type OKEnvelope struct {
func (_ OKEnvelope) Label() string { return "OK" }
func (o OKEnvelope) String() string {
v, _ := json.Marshal(o)

return string(v)
}

Expand Down Expand Up @@ -366,6 +392,7 @@ func (v OKEnvelope) MarshalJSON() ([]byte, error) {
w.RawString(`,`)
w.Raw(json.Marshal(v.Reason))
w.RawString(`]`)

return w.BuildBytes()
}

Expand All @@ -377,6 +404,7 @@ type AuthEnvelope struct {
func (_ AuthEnvelope) Label() string { return "AUTH" }

Check failure on line 404 in types/envelope/envelope.go

View workflow job for this annotation

GitHub Actions / lint

hugeParam: _ is heavy (112 bytes); consider passing it by pointer (gocritic)
func (a AuthEnvelope) String() string {
v, _ := json.Marshal(a)

return string(v)
}

Expand All @@ -391,6 +419,7 @@ func (v *AuthEnvelope) UnmarshalJSON(data []byte) error {
} else {
v.Challenge = &arr[1].Str
}

return nil
}

Expand All @@ -402,6 +431,8 @@ func (v AuthEnvelope) MarshalJSON() ([]byte, error) {
} else {
v.Event.MarshalEasyJSON(&w)
}

w.RawString(`]`)

return w.BuildBytes()
}
6 changes: 4 additions & 2 deletions types/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (e *Event) Match(f filter.Filter) bool {
for _, v := range vals {
if v == t[1] {
containsValue = true

break
}
}
Expand All @@ -86,8 +87,8 @@ func Decode(b []byte) (*Event, error) {
}

// Encode encodes an Event to a byte array.
func (e *Event) Encode() ([]byte, error) {
b, err := easyjson.Marshal(e)
func (evt *Event) Encode() ([]byte, error) {
b, err := easyjson.Marshal(evt)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -146,5 +147,6 @@ func (e *Event) IsValid() (bool, error) {

// check signature
hash := sha256.Sum256(e.Serialize())

return sig.Verify(hash[:], pubkey), nil
}
2 changes: 1 addition & 1 deletion types/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type (
)

const (
// Ranges
// Ranges.
Regular Range = iota
Replaceable
Ephemeral
Expand Down
2 changes: 2 additions & 0 deletions types/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func (tag Tag) MarshalTo(dst []byte) []byte {
dst = EscapeString(dst, s)
}
dst = append(dst, ']')

return dst
}

Expand All @@ -26,5 +27,6 @@ func MarshalTo(tags []Tag, dst []byte) []byte {
dst = tag.MarshalTo(dst)
}
dst = append(dst, ']')

return dst
}

0 comments on commit 242f2a9

Please sign in to comment.