Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func WithPort(port uint) APIOption {
}
}

// Initialize singleton API instance
// Initialize singleton API instance.
var apiInstance = &APIv1{
engine: ConfigureRouter(false),
Host: "0.0.0.0",
Expand All @@ -70,6 +70,7 @@ func New(debug bool, options ...APIOption) *APIv1 {
opt(apiInstance)
}
})

return apiInstance
}

Expand Down Expand Up @@ -115,7 +116,7 @@ func (a *APIv1) Start() error {

func (a *APIv1) AddRoute(method, path string, handler gin.HandlerFunc) {
// Inner function to add routes to a given target
//(either gin.Engine or gin.RouterGroup)
// (either gin.Engine or gin.RouterGroup)
addRouteToTarget := func(target gin.IRoutes) {
switch method {
case "GET":
Expand Down Expand Up @@ -150,6 +151,7 @@ func ConfigureRouter(debug bool) *gin.Engine {
if !debug {
gin.SetMode(gin.ReleaseMode)
}

gin.DisableConsoleColor()
g := gin.New()
g.Use(gin.Recovery())
Expand All @@ -163,6 +165,7 @@ func ConfigureRouter(debug bool) *gin.Engine {
})
// Swagger UI
g.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

return g
}

Expand All @@ -179,7 +182,12 @@ func accessLogger(param gin.LogFormatterParams) string {
"user_agent": param.Request.UserAgent(),
"error_message": param.ErrorMessage,
}
ret, _ := json.Marshal(logEntry)

ret, err := json.Marshal(logEntry)
if err != nil {
return ""
}

return string(ret) + "\n"
}

Expand Down
2 changes: 0 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func TestRouteRegistration(t *testing.T) {

// Initialize the API and set it to debug mode for testing
apiInstance := api.New(true)

Expand All @@ -35,7 +34,6 @@ func TestRouteRegistration(t *testing.T) {

// Check the status code
assert.Equal(t, http.StatusNotFound, rr.Code, "Expected status not found")

// You can also check the response body, headers, etc.
// TODO check for JSON response (#338)
// assert.Equal(t, `{"fcmToken":"someToken"}`, rr.Body.String())
Expand Down