Skip to content

Commit

Permalink
lib/http: refactoring type of ResponseType from int to string
Browse files Browse the repository at this point in the history
The reason is to make storing or encoding the value readable
from human point of view instead of number, 0, 1, 2, etc.
  • Loading branch information
shuLhan committed Mar 14, 2024
1 parent e671f2a commit 625722e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions lib/http/response_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

package http

// ResponseType define type for HTTP response.
type ResponseType int
// ResponseType define the content type for HTTP response.
type ResponseType string

// List of valid response type.
const (
ResponseTypeNone ResponseType = iota
ResponseTypeBinary
ResponseTypeHTML
ResponseTypeJSON
ResponseTypePlain
ResponseTypeXML
ResponseTypeNone ResponseType = ``
ResponseTypeBinary ResponseType = `binary`
ResponseTypeHTML ResponseType = `html`
ResponseTypeJSON ResponseType = `json`
ResponseTypePlain ResponseType = `plain`
ResponseTypeXML ResponseType = `xml`
)

// String return the string representation of ResponseType as in
Expand Down
12 changes: 6 additions & 6 deletions lib/http/response_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func TestResponseType_String(t *testing.T) {
exp string
restype ResponseType
}{
{restype: 0, exp: ""},
{restype: 1, exp: ContentTypeBinary},
{restype: 2, exp: ContentTypeHTML},
{restype: 3, exp: ContentTypeJSON},
{restype: 4, exp: ContentTypePlain},
{restype: 5, exp: ContentTypeXML},
{restype: ``, exp: ``},
{restype: `binary`, exp: ContentTypeBinary},
{restype: `html`, exp: ContentTypeHTML},
{restype: `json`, exp: ContentTypeJSON},
{restype: `plain`, exp: ContentTypePlain},
{restype: `xml`, exp: ContentTypeXML},
{restype: ResponseTypeNone, exp: ""},
{restype: ResponseTypeBinary, exp: ContentTypeBinary},
{restype: ResponseTypeHTML, exp: ContentTypeHTML},
Expand Down

0 comments on commit 625722e

Please sign in to comment.