Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Neur0toxine committed Nov 10, 2023
1 parent 6a02d91 commit 33a8c6c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ issues:
exclude-rules:
- path: _test\.go
linters:
- dupl
- gomnd
- lll
- bodyclose
Expand Down
12 changes: 6 additions & 6 deletions v1/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (b *TemplateButtons) UnmarshalJSON(value []byte) error {
btn = &PlainButton{}
case ButtonTypePhone:
btn = &PhoneButton{}
case ButtonTypeUrl:
btn = &UrlButton{}
case ButtonTypeURL:
btn = &URLButton{}
default:
return errors.New("undefined type of button")
}
Expand Down Expand Up @@ -139,7 +139,7 @@ type ButtonType string
const (
ButtonTypePlain ButtonType = "plain"
ButtonTypePhone ButtonType = "phone"
ButtonTypeUrl ButtonType = "url"
ButtonTypeURL ButtonType = "url"
)

type PlainButton struct {
Expand All @@ -155,12 +155,12 @@ type PhoneButton struct {

func (PhoneButton) ButtonType() ButtonType { return ButtonTypePhone }

type UrlButton struct {
type URLButton struct {
Label string `json:"label"`
Url string `json:"url"`
URL string `json:"url"`
}

func (UrlButton) ButtonType() ButtonType { return ButtonTypeUrl }
func (URLButton) ButtonType() ButtonType { return ButtonTypeURL }

type HeaderContent interface {
HeaderContentType() HeaderContentType
Expand Down
24 changes: 12 additions & 12 deletions v1/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func TestUnmarshalInteractiveTemplate_TextHeader(t *testing.T) {
assert.Equal(t, "Hello, {{1}}!", h.Body)
assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*URLButton).URL)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)

Expand Down Expand Up @@ -148,9 +148,9 @@ func TestUnmarshalInteractiveTemplate_DocumentHeader(t *testing.T) {
assert.NotNil(t, template.Header.DocumentContent())
assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*URLButton).URL)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)

Expand Down Expand Up @@ -195,9 +195,9 @@ func TestUnmarshalInteractiveTemplate_ImageHeader(t *testing.T) {
assert.NotNil(t, template.Header.ImageContent())
assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*URLButton).URL)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)

Expand Down Expand Up @@ -242,9 +242,9 @@ func TestUnmarshalInteractiveTemplate_VideoHeader(t *testing.T) {
assert.NotNil(t, template.Header.VideoContent())
assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*URLButton).URL)
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)

Expand Down
8 changes: 4 additions & 4 deletions v1/template_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ var TypeMap = [][]byte{
TemplateTypeMedia: []byte("media"),
}

var UnknownTypeValue = errors.New("unknown TemplateType")
var ErrUnknownTypeValue = errors.New("unknown TemplateType")

func (e TemplateType) MarshalText() (text []byte, err error) {
if e.isValid() {
return TypeMap[e], nil
}

return nil, UnknownTypeValue
return nil, ErrUnknownTypeValue
}

func (e TemplateType) String() string {
if e.isValid() {
return string(TypeMap[e])
}

panic(UnknownTypeValue)
panic(ErrUnknownTypeValue)
}

func (e *TemplateType) UnmarshalText(text []byte) error {
Expand All @@ -45,7 +45,7 @@ func (e *TemplateType) UnmarshalText(text []byte) error {
return nil
}

return UnknownTypeValue
return ErrUnknownTypeValue
}

func (e TemplateType) isValid() bool {
Expand Down

0 comments on commit 33a8c6c

Please sign in to comment.