aboutsummaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-03-15 03:17:49 +0700
committerShulhan <ms@kilabit.info>2024-03-15 03:39:16 +0700
commite671f2a5eb1b7dd2f506150c55227eb5a886e4d6 (patch)
treea69f2b0d00ff33b94c959a38df48fea7437082a1 /lib/http
parent72f2c183724199c2b749ec8efb59aa20b59d9e96 (diff)
downloadpakakeh.go-e671f2a5eb1b7dd2f506150c55227eb5a886e4d6.tar.xz
lib/http: refactor type of RequestType from int to string
The reason is to make storing or encoding the RequestType value readable from human point of view instead of number, 0, 1, 2, etc.
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/request_type.go14
-rw-r--r--lib/http/request_type_test.go11
2 files changed, 13 insertions, 12 deletions
diff --git a/lib/http/request_type.go b/lib/http/request_type.go
index db578e55..c6310e87 100644
--- a/lib/http/request_type.go
+++ b/lib/http/request_type.go
@@ -5,16 +5,16 @@
package http
// RequestType define type of HTTP request.
-type RequestType int
+type RequestType string
// List of valid request type.
const (
- RequestTypeNone RequestType = iota
- RequestTypeQuery
- RequestTypeForm
- RequestTypeMultipartForm
- RequestTypeJSON
- RequestTypeXML
+ RequestTypeNone RequestType = ``
+ RequestTypeQuery RequestType = `query`
+ RequestTypeForm RequestType = `form-urlencoded`
+ RequestTypeMultipartForm RequestType = `form-data`
+ RequestTypeJSON RequestType = `json`
+ RequestTypeXML RequestType = `xml`
)
// String return the string representation of request type as in
diff --git a/lib/http/request_type_test.go b/lib/http/request_type_test.go
index a593ff5f..0bb05f99 100644
--- a/lib/http/request_type_test.go
+++ b/lib/http/request_type_test.go
@@ -15,11 +15,12 @@ func TestRequestType_String(t *testing.T) {
exp string
rt RequestType
}{
- {rt: 0, exp: ""},
- {rt: 1, exp: ""},
- {rt: 2, exp: ContentTypeForm},
- {rt: 3, exp: ContentTypeMultipartForm},
- {rt: 4, exp: ContentTypeJSON},
+ {rt: RequestTypeNone, exp: ``},
+ {rt: RequestTypeQuery, exp: ``},
+ {rt: RequestTypeForm, exp: ContentTypeForm},
+ {rt: RequestTypeMultipartForm, exp: ContentTypeMultipartForm},
+ {rt: RequestTypeJSON, exp: ContentTypeJSON},
+ {rt: RequestTypeXML, exp: ContentTypeXML},
}
for _, c := range cases {