mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 14:52:18 +08:00
chore: update the result of CR
This commit is contained in:
parent
abc4fa0718
commit
6bd6454ad1
5
auth.go
5
auth.go
@ -70,8 +70,9 @@ func BasicAuth(accounts Accounts) HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func processAccounts(accounts Accounts) authPairs {
|
func processAccounts(accounts Accounts) authPairs {
|
||||||
assert1(len(accounts) > 0, "Empty list of authorized credentials")
|
length := len(accounts)
|
||||||
pairs := make(authPairs, 0, len(accounts))
|
assert1(length > 0, "Empty list of authorized credentials")
|
||||||
|
pairs := make(authPairs, 0, length)
|
||||||
for user, password := range accounts {
|
for user, password := range accounts {
|
||||||
assert1(user != "", "User can not be empty")
|
assert1(user != "", "User can not be empty")
|
||||||
value := authorizationHeader(user, password)
|
value := authorizationHeader(user, password)
|
||||||
|
@ -34,9 +34,10 @@ const (
|
|||||||
MIMEPOSTForm = binding.MIMEPOSTForm
|
MIMEPOSTForm = binding.MIMEPOSTForm
|
||||||
MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
|
MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
|
||||||
MIMEYAML = binding.MIMEYAML
|
MIMEYAML = binding.MIMEYAML
|
||||||
BodyBytesKey = "_gin-gonic/gin/bodybyteskey"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const bodyBytesKey = "_gin-gonic/gin/bodybyteskey"
|
||||||
|
|
||||||
const abortIndex int8 = math.MaxInt8 / 2
|
const abortIndex int8 = math.MaxInt8 / 2
|
||||||
|
|
||||||
// Context is the most important part of gin. It allows us to pass variables between middleware,
|
// Context is the most important part of gin. It allows us to pass variables between middleware,
|
||||||
@ -686,7 +687,7 @@ func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error {
|
|||||||
// ShouldBindWith for better performance if you need to call only once.
|
// ShouldBindWith for better performance if you need to call only once.
|
||||||
func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (err error) {
|
func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (err error) {
|
||||||
var body []byte
|
var body []byte
|
||||||
if cb, ok := c.Get(BodyBytesKey); ok {
|
if cb, ok := c.Get(bodyBytesKey); ok {
|
||||||
if cbb, ok := cb.([]byte); ok {
|
if cbb, ok := cb.([]byte); ok {
|
||||||
body = cbb
|
body = cbb
|
||||||
}
|
}
|
||||||
@ -696,7 +697,7 @@ func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.Set(BodyBytesKey, body)
|
c.Set(bodyBytesKey, body)
|
||||||
}
|
}
|
||||||
return bb.BindBody(body, obj)
|
return bb.BindBody(body, obj)
|
||||||
}
|
}
|
||||||
|
7
gin.go
7
gin.go
@ -20,11 +20,12 @@ import (
|
|||||||
const defaultMultipartMemory = 32 << 20 // 32 MB
|
const defaultMultipartMemory = 32 << 20 // 32 MB
|
||||||
|
|
||||||
var (
|
var (
|
||||||
default404Body = []byte("404 page not found")
|
default404Body = []byte("404 page not found")
|
||||||
default405Body = []byte("405 method not allowed")
|
default405Body = []byte("405 method not allowed")
|
||||||
defaultAppEngine bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var defaultAppEngine bool
|
||||||
|
|
||||||
// HandlerFunc defines the handler used by gin middleware as return value.
|
// HandlerFunc defines the handler used by gin middleware as return value.
|
||||||
type HandlerFunc func(*Context)
|
type HandlerFunc func(*Context)
|
||||||
|
|
||||||
|
1
mode.go
1
mode.go
@ -22,6 +22,7 @@ const (
|
|||||||
// TestMode indicates gin mode is test.
|
// TestMode indicates gin mode is test.
|
||||||
TestMode = "test"
|
TestMode = "test"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
debugCode = iota
|
debugCode = iota
|
||||||
releaseCode
|
releaseCode
|
||||||
|
7
path.go
7
path.go
@ -136,10 +136,11 @@ func bufApp(buf *[]byte, s string, w int, c byte) {
|
|||||||
|
|
||||||
// Otherwise use either the stack buffer, if it is large enough, or
|
// Otherwise use either the stack buffer, if it is large enough, or
|
||||||
// allocate a new buffer on the heap, and copy all previous characters.
|
// allocate a new buffer on the heap, and copy all previous characters.
|
||||||
if l := len(s); l > cap(b) {
|
length := len(s)
|
||||||
*buf = make([]byte, len(s))
|
if length > cap(b) {
|
||||||
|
*buf = make([]byte, length)
|
||||||
} else {
|
} else {
|
||||||
*buf = (*buf)[:l]
|
*buf = (*buf)[:length]
|
||||||
}
|
}
|
||||||
b = *buf
|
b = *buf
|
||||||
|
|
||||||
|
@ -146,6 +146,6 @@ func function(pc uintptr) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func timeFormat(t time.Time) string {
|
func timeFormat(t time.Time) string {
|
||||||
var timeString = t.Format("2006/01/02 - 15:04:05")
|
timeString := t.Format("2006/01/02 - 15:04:05")
|
||||||
return timeString
|
return timeString
|
||||||
}
|
}
|
||||||
|
5
utils.go
5
utils.go
@ -14,8 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BindKey indicates a default bind key.
|
const bindKey = "_gin-gonic/gin/bindkey"
|
||||||
const BindKey = "_gin-gonic/gin/bindkey"
|
|
||||||
|
|
||||||
// Bind is a helper function for given interface object and returns a Gin middleware.
|
// Bind is a helper function for given interface object and returns a Gin middleware.
|
||||||
func Bind(val interface{}) HandlerFunc {
|
func Bind(val interface{}) HandlerFunc {
|
||||||
@ -30,7 +29,7 @@ func Bind(val interface{}) HandlerFunc {
|
|||||||
return func(c *Context) {
|
return func(c *Context) {
|
||||||
obj := reflect.New(typ).Interface()
|
obj := reflect.New(typ).Interface()
|
||||||
if c.Bind(obj) == nil {
|
if c.Bind(obj) == nil {
|
||||||
c.Set(BindKey, obj)
|
c.Set(bindKey, obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user