1
0
mirror of synced 2024-11-21 12:36:04 +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:
- path: _test\.go
linters:
- dupl
- gomnd
- lll
- bodyclose

View File

@ -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")
}
@ -139,7 +139,7 @@ type ButtonType string
const (
ButtonTypePlain ButtonType = "plain"
ButtonTypePhone ButtonType = "phone"
ButtonTypeUrl ButtonType = "url"
ButtonTypeURL ButtonType = "url"
)
type PlainButton struct {
@ -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

View File

@ -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)
@ -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)
@ -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)
@ -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)

View File

@ -17,14 +17,14 @@ 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 {
@ -32,7 +32,7 @@ func (e TemplateType) String() string {
return string(TypeMap[e])
}
panic(UnknownTypeValue)
panic(ErrUnknownTypeValue)
}
func (e *TemplateType) UnmarshalText(text []byte) error {
@ -45,7 +45,7 @@ func (e *TemplateType) UnmarshalText(text []byte) error {
return nil
}
return UnknownTypeValue
return ErrUnknownTypeValue
}
func (e TemplateType) isValid() bool {