From 625722e9087173d7b01acfb786de935fe09f4310 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 15 Mar 2024 03:21:42 +0700 Subject: lib/http: refactoring type of ResponseType from int to string The reason is to make storing or encoding the value readable from human point of view instead of number, 0, 1, 2, etc. --- lib/http/response_type.go | 16 ++++++++-------- lib/http/response_type_test.go | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/http/response_type.go b/lib/http/response_type.go index 75fb7146..4fee2e88 100644 --- a/lib/http/response_type.go +++ b/lib/http/response_type.go @@ -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 diff --git a/lib/http/response_type_test.go b/lib/http/response_type_test.go index f95726c2..efbc2114 100644 --- a/lib/http/response_type_test.go +++ b/lib/http/response_type_test.go @@ -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}, -- cgit v1.3