-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(223): replace router with gin (#74)
- Loading branch information
1 parent
5abb619
commit 9d9f3e7
Showing
17 changed files
with
220 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,20 @@ | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
|
||
"github.com/julienschmidt/httprouter" | ||
) | ||
|
||
// index basic request to / | ||
// nolint: revive // do not check for unused param required by interface | ||
func index(w http.ResponseWriter, req *http.Request, _ httprouter.Params) { | ||
func index(c *gin.Context) { | ||
responseData := map[string]interface{}{"message": "Welcome to the Paymail Server ✌(◕‿-)✌"} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
err := json.NewEncoder(w).Encode(responseData) | ||
|
||
if err != nil { | ||
ErrorResponse(w, req, ErrorEncodingResponse, err.Error(), http.StatusInternalServerError, nil) | ||
return | ||
} | ||
c.Header("Content-Type", "application/json") | ||
c.JSON(http.StatusOK, responseData) | ||
} | ||
|
||
// health is a basic request to return a health response | ||
func health(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) { | ||
w.WriteHeader(http.StatusOK) | ||
} | ||
|
||
// notFound handles all 404 requests | ||
// nolint: revive // do not check for unused param required by interface | ||
func notFound(w http.ResponseWriter, req *http.Request) { | ||
ErrorResponse(w, req, ErrorRequestNotFound, "request not found", http.StatusNotFound, nil) | ||
} | ||
|
||
// methodNotAllowed handles all 405 requests | ||
func methodNotAllowed(w http.ResponseWriter, req *http.Request) { | ||
ErrorResponse(w, req, ErrorMethodNotFound, "method "+req.Method+" not allowed", http.StatusMethodNotAllowed, nil) | ||
func health(c *gin.Context) { | ||
c.Status(http.StatusOK) | ||
} |
Oops, something went wrong.