@@ -50,7 +50,7 @@ func WithPort(port uint) APIOption {
5050 }
5151}
5252
53- // Initialize singleton API instance
53+ // Initialize singleton API instance.
5454var apiInstance = & APIv1 {
5555 engine : ConfigureRouter (false ),
5656 Host : "0.0.0.0" ,
@@ -70,6 +70,7 @@ func New(debug bool, options ...APIOption) *APIv1 {
7070 opt (apiInstance )
7171 }
7272 })
73+
7374 return apiInstance
7475}
7576
@@ -115,7 +116,7 @@ func (a *APIv1) Start() error {
115116
116117func (a * APIv1 ) AddRoute (method , path string , handler gin.HandlerFunc ) {
117118 // Inner function to add routes to a given target
118- //(either gin.Engine or gin.RouterGroup)
119+ // (either gin.Engine or gin.RouterGroup)
119120 addRouteToTarget := func (target gin.IRoutes ) {
120121 switch method {
121122 case "GET" :
@@ -150,6 +151,7 @@ func ConfigureRouter(debug bool) *gin.Engine {
150151 if ! debug {
151152 gin .SetMode (gin .ReleaseMode )
152153 }
154+
153155 gin .DisableConsoleColor ()
154156 g := gin .New ()
155157 g .Use (gin .Recovery ())
@@ -163,6 +165,7 @@ func ConfigureRouter(debug bool) *gin.Engine {
163165 })
164166 // Swagger UI
165167 g .GET ("/swagger/*any" , ginSwagger .WrapHandler (swaggerFiles .Handler ))
168+
166169 return g
167170}
168171
@@ -179,7 +182,12 @@ func accessLogger(param gin.LogFormatterParams) string {
179182 "user_agent" : param .Request .UserAgent (),
180183 "error_message" : param .ErrorMessage ,
181184 }
182- ret , _ := json .Marshal (logEntry )
185+
186+ ret , err := json .Marshal (logEntry )
187+ if err != nil {
188+ return ""
189+ }
190+
183191 return string (ret ) + "\n "
184192}
185193
0 commit comments