1
0
mirror of synced 2024-11-22 04:56:06 +03:00

lint fixes

This commit is contained in:
Pavel 2023-11-10 13:56:57 +03:00
parent 6a02d91fed
commit 33a8c6ce6b
4 changed files with 23 additions and 22 deletions

View File

@ -157,6 +157,7 @@ issues:
exclude-rules: exclude-rules:
- path: _test\.go - path: _test\.go
linters: linters:
- dupl
- gomnd - gomnd
- lll - lll
- bodyclose - bodyclose

View File

@ -87,8 +87,8 @@ func (b *TemplateButtons) UnmarshalJSON(value []byte) error {
btn = &PlainButton{} btn = &PlainButton{}
case ButtonTypePhone: case ButtonTypePhone:
btn = &PhoneButton{} btn = &PhoneButton{}
case ButtonTypeUrl: case ButtonTypeURL:
btn = &UrlButton{} btn = &URLButton{}
default: default:
return errors.New("undefined type of button") return errors.New("undefined type of button")
} }
@ -139,7 +139,7 @@ type ButtonType string
const ( const (
ButtonTypePlain ButtonType = "plain" ButtonTypePlain ButtonType = "plain"
ButtonTypePhone ButtonType = "phone" ButtonTypePhone ButtonType = "phone"
ButtonTypeUrl ButtonType = "url" ButtonTypeURL ButtonType = "url"
) )
type PlainButton struct { type PlainButton struct {
@ -155,12 +155,12 @@ type PhoneButton struct {
func (PhoneButton) ButtonType() ButtonType { return ButtonTypePhone } func (PhoneButton) ButtonType() ButtonType { return ButtonTypePhone }
type UrlButton struct { type URLButton struct {
Label string `json:"label"` 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 { type HeaderContent interface {
HeaderContentType() HeaderContentType HeaderContentType() HeaderContentType

View File

@ -101,9 +101,9 @@ func TestUnmarshalInteractiveTemplate_TextHeader(t *testing.T) {
assert.Equal(t, "Hello, {{1}}!", h.Body) assert.Equal(t, "Hello, {{1}}!", h.Body)
assert.Equal(t, "Scooter", template.Footer) assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus) assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType()) assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url) 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, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType()) assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label) assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)
@ -148,9 +148,9 @@ func TestUnmarshalInteractiveTemplate_DocumentHeader(t *testing.T) {
assert.NotNil(t, template.Header.DocumentContent()) assert.NotNil(t, template.Header.DocumentContent())
assert.Equal(t, "Scooter", template.Footer) assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus) assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType()) assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url) 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, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType()) assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label) assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)
@ -195,9 +195,9 @@ func TestUnmarshalInteractiveTemplate_ImageHeader(t *testing.T) {
assert.NotNil(t, template.Header.ImageContent()) assert.NotNil(t, template.Header.ImageContent())
assert.Equal(t, "Scooter", template.Footer) assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus) assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType()) assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url) 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, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType()) assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label) assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)
@ -242,9 +242,9 @@ func TestUnmarshalInteractiveTemplate_VideoHeader(t *testing.T) {
assert.NotNil(t, template.Header.VideoContent()) assert.NotNil(t, template.Header.VideoContent())
assert.Equal(t, "Scooter", template.Footer) assert.Equal(t, "Scooter", template.Footer)
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus) assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType()) assert.Equal(t, ButtonTypeURL, template.Buttons.Items[0].ButtonType())
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url) 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, "Go to website", template.Buttons.Items[0].(*URLButton).Label)
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType()) assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label) assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)

View File

@ -17,14 +17,14 @@ var TypeMap = [][]byte{
TemplateTypeMedia: []byte("media"), TemplateTypeMedia: []byte("media"),
} }
var UnknownTypeValue = errors.New("unknown TemplateType") var ErrUnknownTypeValue = errors.New("unknown TemplateType")
func (e TemplateType) MarshalText() (text []byte, err error) { func (e TemplateType) MarshalText() (text []byte, err error) {
if e.isValid() { if e.isValid() {
return TypeMap[e], nil return TypeMap[e], nil
} }
return nil, UnknownTypeValue return nil, ErrUnknownTypeValue
} }
func (e TemplateType) String() string { func (e TemplateType) String() string {
@ -32,7 +32,7 @@ func (e TemplateType) String() string {
return string(TypeMap[e]) return string(TypeMap[e])
} }
panic(UnknownTypeValue) panic(ErrUnknownTypeValue)
} }
func (e *TemplateType) UnmarshalText(text []byte) error { func (e *TemplateType) UnmarshalText(text []byte) error {
@ -45,7 +45,7 @@ func (e *TemplateType) UnmarshalText(text []byte) error {
return nil return nil
} }
return UnknownTypeValue return ErrUnknownTypeValue
} }
func (e TemplateType) isValid() bool { func (e TemplateType) isValid() bool {