chore: add some annotation

This commit is contained in:
thinkerou 2018-09-14 10:26:33 +08:00
parent 453e4e97dc
commit b5eaa4de67
6 changed files with 16 additions and 3 deletions

View File

@ -6,7 +6,7 @@ import (
"github.com/gin-gonic/gin"
)
var DB = make(map[string]string)
var db = make(map[string]string)
func setupRouter() *gin.Engine {
// Disable Console Color
@ -21,7 +21,7 @@ func setupRouter() *gin.Engine {
// Get user value
r.GET("/user/:name", func(c *gin.Context) {
user := c.Params.ByName("name")
value, ok := DB[user]
value, ok := db[user]
if ok {
c.JSON(http.StatusOK, gin.H{"user": user, "value": value})
} else {
@ -50,7 +50,7 @@ func setupRouter() *gin.Engine {
}
if c.Bind(&json) == nil {
DB[user] = json.Value
db[user] = json.Value
c.JSON(http.StatusOK, gin.H{"status": "ok"})
}
})

View File

@ -10,6 +10,7 @@ import (
"gopkg.in/go-playground/validator.v8"
)
// Booking contains object which need to bind and validate data.
type Booking struct {
CheckIn time.Time `form:"check_in" binding:"required,bookabledate" time_format:"2006-01-02"`
CheckOut time.Time `form:"check_out" binding:"required,gtfield=CheckIn" time_format:"2006-01-02"`

View File

@ -13,16 +13,19 @@ func main() {
StartGin()
}
// ConfigRuntime sets the number of operating system threads.
func ConfigRuntime() {
nuCPU := runtime.NumCPU()
runtime.GOMAXPROCS(nuCPU)
fmt.Printf("Running with %d CPUs\n", nuCPU)
}
// StartWrokers start starsWorker by goroutine.
func StartWorkers() {
go statsWorker()
}
// StartGin starts gin web server with setting router.
func StartGin() {
gin.SetMode(gin.ReleaseMode)

View File

@ -50,6 +50,7 @@ func connectedUsers() uint64 {
return uint64(connected)
}
// Stats returns savedStats data.
func Stats() map[string]uint64 {
mutexStats.RLock()
defer mutexStats.RUnlock()

View File

@ -9,8 +9,12 @@ package json
import "encoding/json"
var (
// Marshal is exported by gin/json package.
Marshal = json.Marshal
// MarshalIndent is exported by gin/json package.
MarshalIndent = json.MarshalIndent
// NewDecoder is exported by gin/json package.
NewDecoder = json.NewDecoder
// NewEncoder is exported by gin/json package.
NewEncoder = json.NewEncoder
)

View File

@ -10,8 +10,12 @@ import "github.com/json-iterator/go"
var (
json = jsoniter.ConfigCompatibleWithStandardLibrary
// Marshal is exported by gin/json package.
Marshal = json.Marshal
// MarshalIndent is exported by gin/json package.
MarshalIndent = json.MarshalIndent
// NewDecoder is exported by gin/json package.
NewDecoder = json.NewDecoder
// NewEncoder is exported by gin/json package.
NewEncoder = json.NewEncoder
)