mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 01:12:16 +08:00
Merge branch 'master' into master
This commit is contained in:
commit
aa25e24b63
@ -61,6 +61,10 @@ type FooStructForMapType struct {
|
|||||||
MapFoo map[string]interface{} `form:"map_foo"`
|
MapFoo map[string]interface{} `form:"map_foo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FooStructForIgnoreFormTag struct {
|
||||||
|
Foo *string `form:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
type InvalidNameType struct {
|
type InvalidNameType struct {
|
||||||
TestName string `invalid_name:"test_name"`
|
TestName string `invalid_name:"test_name"`
|
||||||
}
|
}
|
||||||
@ -278,6 +282,12 @@ func TestBindingFormForTime2(t *testing.T) {
|
|||||||
"", "")
|
"", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFormBindingIgnoreField(t *testing.T) {
|
||||||
|
testFormBindingIgnoreField(t, "POST",
|
||||||
|
"/", "/",
|
||||||
|
"-=bar", "")
|
||||||
|
}
|
||||||
|
|
||||||
func TestBindingFormInvalidName(t *testing.T) {
|
func TestBindingFormInvalidName(t *testing.T) {
|
||||||
testFormBindingInvalidName(t, "POST",
|
testFormBindingInvalidName(t, "POST",
|
||||||
"/", "/",
|
"/", "/",
|
||||||
@ -860,6 +870,21 @@ func testFormBindingForTimeFailLocation(t *testing.T, method, path, badPath, bod
|
|||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testFormBindingIgnoreField(t *testing.T, method, path, badPath, body, badBody string) {
|
||||||
|
b := Form
|
||||||
|
assert.Equal(t, "form", b.Name())
|
||||||
|
|
||||||
|
obj := FooStructForIgnoreFormTag{}
|
||||||
|
req := requestWithBody(method, path, body)
|
||||||
|
if method == "POST" {
|
||||||
|
req.Header.Add("Content-Type", MIMEPOSTForm)
|
||||||
|
}
|
||||||
|
err := b.Bind(req, &obj)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Nil(t, obj.Foo)
|
||||||
|
}
|
||||||
|
|
||||||
func testFormBindingInvalidName(t *testing.T, method, path, badPath, body, badBody string) {
|
func testFormBindingInvalidName(t *testing.T, method, path, badPath, body, badBody string) {
|
||||||
b := Form
|
b := Form
|
||||||
assert.Equal(t, "form", b.Name())
|
assert.Equal(t, "form", b.Name())
|
||||||
|
@ -41,6 +41,9 @@ func mapFormByTag(ptr interface{}, form map[string][]string, tag string) error {
|
|||||||
defaultValue = defaultList[1]
|
defaultValue = defaultList[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if inputFieldName == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if inputFieldName == "" {
|
if inputFieldName == "" {
|
||||||
inputFieldName = typeField.Name
|
inputFieldName = typeField.Name
|
||||||
|
|
||||||
|
@ -64,6 +64,8 @@ type LogFormatterParams struct {
|
|||||||
ErrorMessage string
|
ErrorMessage string
|
||||||
// IsTerm shows whether does gin's output descriptor refers to a terminal.
|
// IsTerm shows whether does gin's output descriptor refers to a terminal.
|
||||||
IsTerm bool
|
IsTerm bool
|
||||||
|
// BodySize is the size of the Response Body
|
||||||
|
BodySize int
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaultLogFormatter is the default log format function Logger middleware uses.
|
// defaultLogFormatter is the default log format function Logger middleware uses.
|
||||||
@ -191,6 +193,8 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
|
|||||||
param.StatusCode = c.Writer.Status()
|
param.StatusCode = c.Writer.Status()
|
||||||
param.ErrorMessage = c.Errors.ByType(ErrorTypePrivate).String()
|
param.ErrorMessage = c.Errors.ByType(ErrorTypePrivate).String()
|
||||||
|
|
||||||
|
param.BodySize = c.Writer.Size()
|
||||||
|
|
||||||
if raw != "" {
|
if raw != "" {
|
||||||
path = path + "?" + raw
|
path = path + "?" + raw
|
||||||
}
|
}
|
||||||
|
6
mode.go
6
mode.go
@ -11,8 +11,8 @@ import (
|
|||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ENV_GIN_MODE indicates environment name for gin mode.
|
// EnvGinMode indicates environment name for gin mode.
|
||||||
const ENV_GIN_MODE = "GIN_MODE"
|
const EnvGinMode = "GIN_MODE"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DebugMode indicates gin mode is debug.
|
// DebugMode indicates gin mode is debug.
|
||||||
@ -44,7 +44,7 @@ var ginMode = debugCode
|
|||||||
var modeName = DebugMode
|
var modeName = DebugMode
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
mode := os.Getenv(ENV_GIN_MODE)
|
mode := os.Getenv(EnvGinMode)
|
||||||
SetMode(mode)
|
SetMode(mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
os.Setenv(ENV_GIN_MODE, TestMode)
|
os.Setenv(EnvGinMode, TestMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetMode(t *testing.T) {
|
func TestSetMode(t *testing.T) {
|
||||||
assert.Equal(t, testCode, ginMode)
|
assert.Equal(t, testCode, ginMode)
|
||||||
assert.Equal(t, TestMode, Mode())
|
assert.Equal(t, TestMode, Mode())
|
||||||
os.Unsetenv(ENV_GIN_MODE)
|
os.Unsetenv(EnvGinMode)
|
||||||
|
|
||||||
SetMode("")
|
SetMode("")
|
||||||
assert.Equal(t, debugCode, ginMode)
|
assert.Equal(t, debugCode, ginMode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user