-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from LucienShui/chore/remove_v2
remove release-v prefix, remove v2 api
- Loading branch information
Showing
21 changed files
with
215 additions
and
713 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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func NotFoundHandler(context *gin.Context) { | ||
context.JSON(http.StatusOK, gin.H{ | ||
"status": http.StatusNotFound, | ||
"message": ErrNoRouterFounded.Error(), | ||
}) | ||
} | ||
|
||
func Beat(context *gin.Context) { | ||
method := context.DefaultQuery("method", "none") | ||
if method == "beat" { | ||
context.JSON(http.StatusOK, gin.H{ | ||
"status": http.StatusOK, | ||
}) | ||
} else { | ||
NotFoundHandler(context) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package common | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrNoRouterFounded = errors.New("no router founded") | ||
) |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package logging | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func exportField(requests *gin.Context) []zap.Field { | ||
var result []zap.Field | ||
result = append(result, zap.String("ip", requests.ClientIP())) | ||
return result | ||
} | ||
|
||
func loggerPreprocess(fields []interface{}) []zap.Field { | ||
var result []zap.Field | ||
|
||
if len(fields) != 0 { | ||
var beginIndex = 0 | ||
switch fields[0].(type) { | ||
case *gin.Context: | ||
context := fields[0].(*gin.Context) | ||
zapField := exportField(context) | ||
result = append(result, zapField...) | ||
beginIndex = 1 | ||
} | ||
for _, each := range fields[beginIndex:] { | ||
result = append(result, each.(zap.Field)) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
type loggerFunc func(string, ...interface{}) | ||
|
||
func getLogger(log func(string, ...zap.Field)) loggerFunc { | ||
return func(msg string, a ...interface{}) { | ||
log(msg, loggerPreprocess(a)...) | ||
} | ||
} |
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
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
Oops, something went wrong.