mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 01:57:55 +08:00
chore: add some annotation
This commit is contained in:
parent
453e4e97dc
commit
b5eaa4de67
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DB = make(map[string]string)
|
var db = make(map[string]string)
|
||||||
|
|
||||||
func setupRouter() *gin.Engine {
|
func setupRouter() *gin.Engine {
|
||||||
// Disable Console Color
|
// Disable Console Color
|
||||||
@ -21,7 +21,7 @@ func setupRouter() *gin.Engine {
|
|||||||
// Get user value
|
// Get user value
|
||||||
r.GET("/user/:name", func(c *gin.Context) {
|
r.GET("/user/:name", func(c *gin.Context) {
|
||||||
user := c.Params.ByName("name")
|
user := c.Params.ByName("name")
|
||||||
value, ok := DB[user]
|
value, ok := db[user]
|
||||||
if ok {
|
if ok {
|
||||||
c.JSON(http.StatusOK, gin.H{"user": user, "value": value})
|
c.JSON(http.StatusOK, gin.H{"user": user, "value": value})
|
||||||
} else {
|
} else {
|
||||||
@ -50,7 +50,7 @@ func setupRouter() *gin.Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.Bind(&json) == nil {
|
if c.Bind(&json) == nil {
|
||||||
DB[user] = json.Value
|
db[user] = json.Value
|
||||||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"gopkg.in/go-playground/validator.v8"
|
"gopkg.in/go-playground/validator.v8"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Booking contains object which need to bind and validate data.
|
||||||
type Booking struct {
|
type Booking struct {
|
||||||
CheckIn time.Time `form:"check_in" binding:"required,bookabledate" time_format:"2006-01-02"`
|
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"`
|
CheckOut time.Time `form:"check_out" binding:"required,gtfield=CheckIn" time_format:"2006-01-02"`
|
||||||
|
@ -13,16 +13,19 @@ func main() {
|
|||||||
StartGin()
|
StartGin()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfigRuntime sets the number of operating system threads.
|
||||||
func ConfigRuntime() {
|
func ConfigRuntime() {
|
||||||
nuCPU := runtime.NumCPU()
|
nuCPU := runtime.NumCPU()
|
||||||
runtime.GOMAXPROCS(nuCPU)
|
runtime.GOMAXPROCS(nuCPU)
|
||||||
fmt.Printf("Running with %d CPUs\n", nuCPU)
|
fmt.Printf("Running with %d CPUs\n", nuCPU)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartWrokers start starsWorker by goroutine.
|
||||||
func StartWorkers() {
|
func StartWorkers() {
|
||||||
go statsWorker()
|
go statsWorker()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartGin starts gin web server with setting router.
|
||||||
func StartGin() {
|
func StartGin() {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ func connectedUsers() uint64 {
|
|||||||
return uint64(connected)
|
return uint64(connected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stats returns savedStats data.
|
||||||
func Stats() map[string]uint64 {
|
func Stats() map[string]uint64 {
|
||||||
mutexStats.RLock()
|
mutexStats.RLock()
|
||||||
defer mutexStats.RUnlock()
|
defer mutexStats.RUnlock()
|
||||||
|
@ -9,8 +9,12 @@ package json
|
|||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Marshal is exported by gin/json package.
|
||||||
Marshal = json.Marshal
|
Marshal = json.Marshal
|
||||||
|
// MarshalIndent is exported by gin/json package.
|
||||||
MarshalIndent = json.MarshalIndent
|
MarshalIndent = json.MarshalIndent
|
||||||
|
// NewDecoder is exported by gin/json package.
|
||||||
NewDecoder = json.NewDecoder
|
NewDecoder = json.NewDecoder
|
||||||
|
// NewEncoder is exported by gin/json package.
|
||||||
NewEncoder = json.NewEncoder
|
NewEncoder = json.NewEncoder
|
||||||
)
|
)
|
||||||
|
@ -10,8 +10,12 @@ import "github.com/json-iterator/go"
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
// Marshal is exported by gin/json package.
|
||||||
Marshal = json.Marshal
|
Marshal = json.Marshal
|
||||||
|
// MarshalIndent is exported by gin/json package.
|
||||||
MarshalIndent = json.MarshalIndent
|
MarshalIndent = json.MarshalIndent
|
||||||
|
// NewDecoder is exported by gin/json package.
|
||||||
NewDecoder = json.NewDecoder
|
NewDecoder = json.NewDecoder
|
||||||
|
// NewEncoder is exported by gin/json package.
|
||||||
NewEncoder = json.NewEncoder
|
NewEncoder = json.NewEncoder
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user