Skip to content

Commit ad6f367

Browse files
authored
refactor: change some method and function names (#35)
1 parent d3ad906 commit ad6f367

15 files changed

+173
-173
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
func main() {
2626
k := kid.New()
2727

28-
k.GET("/hello", helloHandler)
28+
k.Get("/hello", helloHandler)
2929

3030
k.Run()
3131
}

Diff for: context_test.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestNewContext(t *testing.T) {
4040
assert.Nil(t, ctx.response)
4141
}
4242

43-
func TestContextReset(t *testing.T) {
43+
func TestContext_reset(t *testing.T) {
4444
ctx := newContext(New())
4545

4646
req := httptest.NewRequest(http.MethodGet, "/", nil)
@@ -55,7 +55,7 @@ func TestContextReset(t *testing.T) {
5555
assert.Equal(t, make(Params), ctx.params)
5656
}
5757

58-
func TestContextRequest(t *testing.T) {
58+
func TestContext_Request(t *testing.T) {
5959
ctx := newContext(New())
6060

6161
req := httptest.NewRequest(http.MethodGet, "/", nil)
@@ -65,7 +65,7 @@ func TestContextRequest(t *testing.T) {
6565
assert.Equal(t, req, ctx.Request())
6666
}
6767

68-
func TestContextResponse(t *testing.T) {
68+
func TestContext_Response(t *testing.T) {
6969
ctx := newContext(New())
7070

7171
res := httptest.NewRecorder()
@@ -76,7 +76,7 @@ func TestContextResponse(t *testing.T) {
7676
assert.Equal(t, expectedRes, ctx.Response())
7777
}
7878

79-
func TestContextSetParams(t *testing.T) {
79+
func TestContext_setParams(t *testing.T) {
8080
ctx := newContext(New())
8181

8282
params := Params{"foo": "bar", "abc": "xyz"}
@@ -86,7 +86,7 @@ func TestContextSetParams(t *testing.T) {
8686
assert.Equal(t, params, ctx.params)
8787
}
8888

89-
func TestContextParams(t *testing.T) {
89+
func TestContext_Params(t *testing.T) {
9090
ctx := newContext(New())
9191

9292
params := Params{"foo": "bar", "abc": "xyz"}
@@ -96,7 +96,7 @@ func TestContextParams(t *testing.T) {
9696
assert.Equal(t, params, ctx.Params())
9797
}
9898

99-
func TestContextParam(t *testing.T) {
99+
func TestContext_Param(t *testing.T) {
100100
ctx := newContext(New())
101101

102102
params := Params{"foo": "bar", "abc": "xyz"}
@@ -107,7 +107,7 @@ func TestContextParam(t *testing.T) {
107107
assert.Equal(t, params["abc"], ctx.Param("abc"))
108108
}
109109

110-
func TestContextQueryParams(t *testing.T) {
110+
func TestContext_QueryParams(t *testing.T) {
111111
ctx := newContext(New())
112112

113113
req := httptest.NewRequest(http.MethodGet, "/?foo=bar&abc=xyz&abc=2", nil)
@@ -123,7 +123,7 @@ func TestContextQueryParams(t *testing.T) {
123123
assert.Equal(t, url.Values{}, ctx.QueryParams())
124124
}
125125

126-
func TestContextQueryParam(t *testing.T) {
126+
func TestContext_QueryParam(t *testing.T) {
127127
ctx := newContext(New())
128128

129129
req := httptest.NewRequest(http.MethodGet, "/?foo=bar&abc=xyz&abc=2", nil)
@@ -135,7 +135,7 @@ func TestContextQueryParam(t *testing.T) {
135135
assert.Equal(t, "", ctx.QueryParam("does_not_exist"))
136136
}
137137

138-
func TestContextQueryParamMultiple(t *testing.T) {
138+
func TestContext_QueryParamMultiple(t *testing.T) {
139139
ctx := newContext(New())
140140

141141
req := httptest.NewRequest(http.MethodGet, "/?foo=bar&abc=xyz&abc=2", nil)
@@ -147,7 +147,7 @@ func TestContextQueryParamMultiple(t *testing.T) {
147147
assert.Equal(t, []string{}, ctx.QueryParamMultiple("does_not_exist"))
148148
}
149149

150-
func TestContextSet(t *testing.T) {
150+
func TestContext_Set(t *testing.T) {
151151
ctx := newContext(New())
152152
ctx.reset(nil, nil)
153153

@@ -160,7 +160,7 @@ func TestContextSet(t *testing.T) {
160160
assert.Equal(t, 1, len(ctx.storage))
161161
}
162162

163-
func TestContextGet(t *testing.T) {
163+
func TestContext_Get(t *testing.T) {
164164
ctx := newContext(New())
165165
ctx.reset(nil, nil)
166166

@@ -172,7 +172,7 @@ func TestContextGet(t *testing.T) {
172172
assert.Equal(t, 12.64, val)
173173
}
174174

175-
func TestContextGetSetDataRace(t *testing.T) {
175+
func TestContext_GetSet_DataRace(t *testing.T) {
176176
ctx := newContext(New())
177177
ctx.reset(nil, nil)
178178

@@ -188,7 +188,7 @@ func TestContextGetSetDataRace(t *testing.T) {
188188
<-ch
189189
}
190190

191-
func TestContextWriteContentType(t *testing.T) {
191+
func TestContext_writeContentType(t *testing.T) {
192192
ctx := newContext(New())
193193

194194
res := httptest.NewRecorder()
@@ -207,7 +207,7 @@ func TestContextWriteContentType(t *testing.T) {
207207
assert.Equal(t, "application/json", ctx.response.Header().Get("Content-Type"))
208208
}
209209

210-
func TestNoContent(t *testing.T) {
210+
func Test_NoContent(t *testing.T) {
211211
ctx := newContext(New())
212212

213213
res := httptest.NewRecorder()
@@ -218,7 +218,7 @@ func TestNoContent(t *testing.T) {
218218
assert.Equal(t, http.StatusNoContent, res.Code)
219219
}
220220

221-
func TestContextReadJSON(t *testing.T) {
221+
func TestContext_ReadJSON(t *testing.T) {
222222
ctx := newContext(New())
223223

224224
req := httptest.NewRequest(http.MethodGet, "/", strings.NewReader("{\"name\":\"Mojix\",\"age\":22}"))
@@ -245,7 +245,7 @@ func TestContextReadJSON(t *testing.T) {
245245
assert.Equal(t, http.StatusBadRequest, httpErr.Code)
246246
}
247247

248-
func TestContextJSON(t *testing.T) {
248+
func TestContext_JSON(t *testing.T) {
249249
ctx := newContext(New())
250250

251251
res := httptest.NewRecorder()
@@ -271,7 +271,7 @@ func TestContextJSON(t *testing.T) {
271271
assert.Equal(t, http.StatusInternalServerError, httpErr.Code)
272272
}
273273

274-
func TestContextJSONIndent(t *testing.T) {
274+
func TestContext_JSONIndent(t *testing.T) {
275275
ctx := newContext(New())
276276

277277
res := httptest.NewRecorder()
@@ -297,7 +297,7 @@ func TestContextJSONIndent(t *testing.T) {
297297
assert.Equal(t, http.StatusInternalServerError, httpErr.Code)
298298
}
299299

300-
func TestContextJSONByte(t *testing.T) {
300+
func TestContext_JSONByte(t *testing.T) {
301301
ctx := newContext(New())
302302

303303
res := httptest.NewRecorder()
@@ -317,7 +317,7 @@ func TestContextJSONByte(t *testing.T) {
317317
assert.Equal(t, "{\"name\":\"foo\",\"age\":1999}", res.Body.String())
318318
}
319319

320-
func TestContextReadXML(t *testing.T) {
320+
func TestContext_ReadXML(t *testing.T) {
321321
ctx := newContext(New())
322322

323323
req := httptest.NewRequest(http.MethodGet, "/", strings.NewReader("<person><name>Mojix</name><age>22</age></person>"))
@@ -342,7 +342,7 @@ func TestContextReadXML(t *testing.T) {
342342
assert.Equal(t, http.StatusBadRequest, httpErr.Code)
343343
}
344344

345-
func TestContextXML(t *testing.T) {
345+
func TestContext_XML(t *testing.T) {
346346
ctx := newContext(New())
347347

348348
res := httptest.NewRecorder()
@@ -368,7 +368,7 @@ func TestContextXML(t *testing.T) {
368368
assert.Equal(t, http.StatusInternalServerError, httpErr.Code)
369369
}
370370

371-
func TestContextXMLIndent(t *testing.T) {
371+
func TestContext_XMLIndent(t *testing.T) {
372372
ctx := newContext(New())
373373

374374
res := httptest.NewRecorder()
@@ -394,7 +394,7 @@ func TestContextXMLIndent(t *testing.T) {
394394
assert.Equal(t, http.StatusInternalServerError, httpErr.Code)
395395
}
396396

397-
func TestContextXMLByte(t *testing.T) {
397+
func TestContext_XMLByte(t *testing.T) {
398398
ctx := newContext(New())
399399

400400
res := httptest.NewRecorder()
@@ -414,7 +414,7 @@ func TestContextXMLByte(t *testing.T) {
414414
assert.Equal(t, "<person><name>foo</name><age>1999</age></person>", res.Body.String())
415415
}
416416

417-
func TestContextHTML(t *testing.T) {
417+
func TestContext_HTML(t *testing.T) {
418418
k := New()
419419
renderer := htmlrenderer.New("testdata/templates/", "layouts/", ".html", false)
420420
renderer.AddFunc("greet", func() int { return 1 })
@@ -439,7 +439,7 @@ func TestContextHTML(t *testing.T) {
439439
assert.Equal(t, "text/html", res.Header().Get("Content-Type"))
440440
}
441441

442-
func TestContextHTMLString(t *testing.T) {
442+
func TestContext_HTMLString(t *testing.T) {
443443
ctx := newContext(New())
444444

445445
res := httptest.NewRecorder()

Diff for: defaults_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import (
1313
func setupKid() *Kid {
1414
k := New()
1515

16-
k.POST("/post", func(c *Context) error {
16+
k.Post("/post", func(c *Context) error {
1717
return c.JSON(http.StatusOK, Map{"method": c.Request().Method})
1818
})
1919

20-
k.GET("/http-error", func(c *Context) error {
20+
k.Get("/http-error", func(c *Context) error {
2121
return kiderrors.NewHTTPError(http.StatusBadRequest)
2222
})
2323

24-
k.GET("/error", func(c *Context) error {
24+
k.Get("/error", func(c *Context) error {
2525
return errors.New("something went wrong")
2626
})
2727

28-
k.HEAD("/error-head", func(c *Context) error {
28+
k.Head("/error-head", func(c *Context) error {
2929
return kiderrors.NewHTTPError(http.StatusBadRequest)
3030
})
3131

Diff for: errors/errors_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ func TestNewHTTPError(t *testing.T) {
1818
assert.Nil(t, err.Err)
1919
}
2020

21-
func TestWithMessage(t *testing.T) {
21+
func TestHTTPError_WithMessage(t *testing.T) {
2222
err := NewHTTPError(http.StatusOK).WithMessage("new message")
2323

2424
assert.Equal(t, http.StatusOK, err.Code)
2525
assert.Equal(t, "new message", err.Message)
2626
assert.Nil(t, err.Err)
2727
}
2828

29-
func TestWithError(t *testing.T) {
29+
func TestHTTPError_WithError(t *testing.T) {
3030
someErr := errors.New("some error")
3131
err := NewHTTPError(http.StatusOK).WithError(someErr)
3232

@@ -35,7 +35,7 @@ func TestWithError(t *testing.T) {
3535
assert.ErrorIs(t, err.Err, someErr)
3636
}
3737

38-
func TestError(t *testing.T) {
38+
func TestHTTPError_Error(t *testing.T) {
3939
err := NewHTTPError(http.StatusOK)
4040

4141
assert.Equal(t, `{"code": 200, "message": "OK"}`, err.Error())
@@ -45,7 +45,7 @@ func TestError(t *testing.T) {
4545
assert.Equal(t, `{"code": 200, "message": "something went wrong", "error": "some error"}`, err.Error())
4646
}
4747

48-
func TestUnwrap(t *testing.T) {
48+
func TestHTTPError_Unwrap(t *testing.T) {
4949
someErr := errors.New("some error")
5050
err := NewHTTPError(http.StatusForbidden).WithError(someErr)
5151

Diff for: examples/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func main() {
1010
k := kid.New()
1111

12-
k.GET("/hello", helloHandler)
12+
k.Get("/hello", helloHandler)
1313

1414
k.Run()
1515
}

Diff for: html_renderer/html_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestDefault(t *testing.T) {
4646
assert.Empty(t, htmlRenderer.templates)
4747
}
4848

49-
func TestDefaultHTMLRendererAddFunc(t *testing.T) {
49+
func TestDefaultHTMLRenderer_AddFunc(t *testing.T) {
5050
htmlRenderer := Default(false)
5151

5252
assert.PanicsWithValue(t, "function cannot be nil", func() {
@@ -58,7 +58,7 @@ func TestDefaultHTMLRendererAddFunc(t *testing.T) {
5858
assert.Equal(t, 1, len(htmlRenderer.funcMap))
5959
}
6060

61-
func TestDefaultHTMLRendererGetTemplateAndLayoutFiles(t *testing.T) {
61+
func TestDefaultHTMLRenderer_getTemplateAndLayoutFiles(t *testing.T) {
6262
htmlRenderer := newTestHTMLRenderer()
6363

6464
templateFiles, layoutFiles, err := htmlRenderer.getTemplateAndLayoutFiles()
@@ -86,7 +86,7 @@ func TestDefaultHTMLRendererGetTemplateAndLayoutFiles(t *testing.T) {
8686
assert.Nil(t, templateFiles)
8787
}
8888

89-
func TestDefaultHTMLRendererLoadTemplates(t *testing.T) {
89+
func TestDefaultHTMLRenderer_loadTemplates(t *testing.T) {
9090
htmlRenderer := newTestHTMLRenderer()
9191
htmlRenderer.rootDir = "invalid_path"
9292

@@ -113,7 +113,7 @@ func TestDefaultHTMLRendererLoadTemplates(t *testing.T) {
113113
assert.IsType(t, &template.Template{}, htmlRenderer.templates["pages/page2.html"])
114114
}
115115

116-
func TestDefaultHTMLRendererShouldntLoadTemplates(t *testing.T) {
116+
func TestDefaultHTMLRenderer_shouldntLoadTemplates(t *testing.T) {
117117
htmlRenderer := newTestHTMLRenderer()
118118

119119
htmlRenderer.debug = false
@@ -133,21 +133,21 @@ func TestDefaultHTMLRendererShouldntLoadTemplates(t *testing.T) {
133133
assert.True(t, htmlRenderer.shouldntLoadTemplates())
134134
}
135135

136-
func TestDefaultHTMLRendererIsLayout(t *testing.T) {
136+
func TestDefaultHTMLRenderer_isLayout(t *testing.T) {
137137
htmlRenderer := newTestHTMLRenderer()
138138

139139
assert.False(t, htmlRenderer.isLayout("../testdata/templates/index.html"))
140140
assert.True(t, htmlRenderer.isLayout("../testdata/templates/layouts/base.html"))
141141
}
142142

143-
func TestDefaultHTMLRendererGetTemplateName(t *testing.T) {
143+
func TestDefaultHTMLRenderer_getTemplateName(t *testing.T) {
144144
htmlRenderer := newTestHTMLRenderer()
145145

146146
assert.Equal(t, "index.html", htmlRenderer.getTemplateName("../testdata/templates/index.html"))
147147
assert.Equal(t, "pages/page.html", htmlRenderer.getTemplateName("../testdata/templates/pages/page.html"))
148148
}
149149

150-
func TestDefaultHTMLRendererGetFilesToParse(t *testing.T) {
150+
func TestDefaultHTMLRenderer_getFilesToParse(t *testing.T) {
151151
layouts := []string{"base.html"}
152152
file := "index.html"
153153

@@ -156,7 +156,7 @@ func TestDefaultHTMLRendererGetFilesToParse(t *testing.T) {
156156
assert.Equal(t, []string{file, layouts[0]}, files)
157157
}
158158

159-
func TestDefaultHTMLRendererRenderHTML(t *testing.T) {
159+
func TestDefaultHTMLRenderer_RenderHTML(t *testing.T) {
160160
htmlRenderer := newTestHTMLRenderer()
161161
htmlRenderer.rootDir = "invalid_path"
162162

0 commit comments

Comments
 (0)