Skip to content

Commit

Permalink
Merge pull request #18 from softwarespot/refactor-formatting
Browse files Browse the repository at this point in the history
refactor(all): Refactored the formatting of files
  • Loading branch information
bgcicca authored Oct 30, 2024
2 parents ac3021c + dcf9ff8 commit d98bd16
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion examples/cors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func HelloHandler(req *req.Request, res *req.Response) {
}

func main() {

app := router.NewApp()

// Use the cors middleware
Expand Down
6 changes: 4 additions & 2 deletions examples/crud/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ type User struct {
Age int `json:"age"`
}

var users = make(map[int]User)
var nextID = 1
var (
users = make(map[int]User)
nextID = 1
)

// CreateUser adds a new user to the system.
//
Expand Down
1 change: 0 additions & 1 deletion middleware/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestCORSMiddlewareDefaultOptions(t *testing.T) {
assert.Equal(t, "", recorder.Header().Get("Access-Control-Expose-Headers"))
assert.Equal(t, "600", recorder.Header().Get("Access-Control-Max-Age"))
assert.Equal(t, "GET,HEAD,DELETE,OPTIONS,PATCH,POST", recorder.Header().Get("Access-Control-Allow-Methods"))

}

func TestCORSMiddlewareOriginNotAllowed(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion middleware/csrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func TestCSRFMiddleware(t *testing.T) {

validToken := GenerateCSRFToken()
isValidToken := func(token string) bool {
return token == validToken
Expand Down
4 changes: 2 additions & 2 deletions plugins/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type MockRouter struct {
registeredRoutes map[string]func(req *req.Request, res *MockResponse)
}

func (m *MockRouter) Route(method string, path string, handler func(req *req.Request, res *MockResponse)) {
func (m *MockRouter) Route(method, path string, handler func(req *req.Request, res *MockResponse)) {
if m.registeredRoutes == nil {
m.registeredRoutes = make(map[string]func(req *req.Request, res *MockResponse))
}
Expand All @@ -27,7 +27,7 @@ func (m *MockRouter) Route(method string, path string, handler func(req *req.Req

type MockPlugin struct{}

func (p *MockPlugin) Register(route func(method string, path string, handler func(req *req.Request, res *MockResponse))) {
func (p *MockPlugin) Register(route func(method, path string, handler func(req *req.Request, res *MockResponse))) {
route("GET", "/mock-plugin-route", func(req *req.Request, res *MockResponse) {
res.Send("Mock Plugin Route")
})
Expand Down
5 changes: 4 additions & 1 deletion router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a *App) RegisterPlugins() {
}
}

func (a *App) Route(method string, path string, handler func(req *req.Request, res *req.Response)) {
func (a *App) Route(method, path string, handler func(req *req.Request, res *req.Response)) {
if a.routes[path] == nil {
a.routes[path] = make(map[string]http.HandlerFunc)
}
Expand Down Expand Up @@ -83,16 +83,19 @@ func (a *App) Delete(path string, handler func(req *req.Request, res *req.Respon
func (a *App) Patch(path string, handler func(req *req.Request, res *req.Response)) {
a.Route(http.MethodPatch, path, handler)
}

func (a *App) Options(path string, handler func(req *req.Request, res *req.Response)) {
a.Route(http.MethodOptions, path, handler)
}

func (a *App) Head(path string, handler func(req *req.Request, res *req.Response)) {
a.Route(http.MethodHead, path, handler)
}

func (a *App) Connect(path string, handler func(req *req.Request, res *req.Response)) {
a.Route(http.MethodConnect, path, handler)
}

func (a *App) Trace(path string, handler func(req *req.Request, res *req.Response)) {
a.Route(http.MethodTrace, path, handler)
}
Expand Down

0 comments on commit d98bd16

Please sign in to comment.