Merge remote-tracking branch 'upstream/master'

This commit is contained in:
thinkerou 2021-08-24 10:34:14 +08:00
commit a90425011f
5 changed files with 35 additions and 44 deletions

View File

@ -21,7 +21,7 @@ jobs:
- name: Setup golangci-lint - name: Setup golangci-lint
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
version: v1.41.1 version: v1.42.0
args: --verbose args: --verbose
test: test:
strategy: strategy:

View File

@ -7,9 +7,6 @@ linters:
- revive - revive
issues: issues:
exclude-rules: exclude-rules:
- linters:
- deadcode
text: "`static` is unused"
- linters: - linters:
- structcheck - structcheck
- unused - unused

View File

@ -210,7 +210,7 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel
case reflect.Int64: case reflect.Int64:
switch value.Interface().(type) { switch value.Interface().(type) {
case time.Duration: case time.Duration:
return setTimeDuration(val, value, field) return setTimeDuration(val, value)
} }
return setIntField(val, 64, value) return setIntField(val, 64, value)
case reflect.Uint: case reflect.Uint:
@ -359,7 +359,7 @@ func setSlice(vals []string, value reflect.Value, field reflect.StructField) err
return nil return nil
} }
func setTimeDuration(val string, value reflect.Value, field reflect.StructField) error { func setTimeDuration(val string, value reflect.Value) error {
d, err := time.ParseDuration(val) d, err := time.ParseDuration(val)
if err != nil { if err != nil {
return err return err

View File

@ -391,9 +391,9 @@ func (c *Context) Param(key string) string {
// c.Query("name") == "Manu" // c.Query("name") == "Manu"
// c.Query("value") == "" // c.Query("value") == ""
// c.Query("wtf") == "" // c.Query("wtf") == ""
func (c *Context) Query(key string) string { func (c *Context) Query(key string) (value string) {
value, _ := c.GetQuery(key) value, _ = c.GetQuery(key)
return value return
} }
// DefaultQuery returns the keyed url query value if it exists, // DefaultQuery returns the keyed url query value if it exists,
@ -427,9 +427,9 @@ func (c *Context) GetQuery(key string) (string, bool) {
// QueryArray returns a slice of strings for a given query key. // QueryArray returns a slice of strings for a given query key.
// The length of the slice depends on the number of params with the given key. // The length of the slice depends on the number of params with the given key.
func (c *Context) QueryArray(key string) []string { func (c *Context) QueryArray(key string) (values []string) {
values, _ := c.GetQueryArray(key) values, _ = c.GetQueryArray(key)
return values return
} }
func (c *Context) initQueryCache() { func (c *Context) initQueryCache() {
@ -444,18 +444,16 @@ func (c *Context) initQueryCache() {
// GetQueryArray returns a slice of strings for a given query key, plus // GetQueryArray returns a slice of strings for a given query key, plus
// a boolean value whether at least one value exists for the given key. // a boolean value whether at least one value exists for the given key.
func (c *Context) GetQueryArray(key string) ([]string, bool) { func (c *Context) GetQueryArray(key string) (values []string, ok bool) {
c.initQueryCache() c.initQueryCache()
if values, ok := c.queryCache[key]; ok && len(values) > 0 { values, ok = c.queryCache[key]
return values, true return
}
return []string{}, false
} }
// QueryMap returns a map for a given query key. // QueryMap returns a map for a given query key.
func (c *Context) QueryMap(key string) map[string]string { func (c *Context) QueryMap(key string) (dicts map[string]string) {
dicts, _ := c.GetQueryMap(key) dicts, _ = c.GetQueryMap(key)
return dicts return
} }
// GetQueryMap returns a map for a given query key, plus a boolean value // GetQueryMap returns a map for a given query key, plus a boolean value
@ -467,9 +465,9 @@ func (c *Context) GetQueryMap(key string) (map[string]string, bool) {
// PostForm returns the specified key from a POST urlencoded form or multipart form // PostForm returns the specified key from a POST urlencoded form or multipart form
// when it exists, otherwise it returns an empty string `("")`. // when it exists, otherwise it returns an empty string `("")`.
func (c *Context) PostForm(key string) string { func (c *Context) PostForm(key string) (value string) {
value, _ := c.GetPostForm(key) value, _ = c.GetPostForm(key)
return value return
} }
// DefaultPostForm returns the specified key from a POST urlencoded form or multipart form // DefaultPostForm returns the specified key from a POST urlencoded form or multipart form
@ -498,9 +496,9 @@ func (c *Context) GetPostForm(key string) (string, bool) {
// PostFormArray returns a slice of strings for a given form key. // PostFormArray returns a slice of strings for a given form key.
// The length of the slice depends on the number of params with the given key. // The length of the slice depends on the number of params with the given key.
func (c *Context) PostFormArray(key string) []string { func (c *Context) PostFormArray(key string) (values []string) {
values, _ := c.GetPostFormArray(key) values, _ = c.GetPostFormArray(key)
return values return
} }
func (c *Context) initFormCache() { func (c *Context) initFormCache() {
@ -518,18 +516,16 @@ func (c *Context) initFormCache() {
// GetPostFormArray returns a slice of strings for a given form key, plus // GetPostFormArray returns a slice of strings for a given form key, plus
// a boolean value whether at least one value exists for the given key. // a boolean value whether at least one value exists for the given key.
func (c *Context) GetPostFormArray(key string) ([]string, bool) { func (c *Context) GetPostFormArray(key string) (values []string, ok bool) {
c.initFormCache() c.initFormCache()
if values := c.formCache[key]; len(values) > 0 { values, ok = c.formCache[key]
return values, true return
}
return []string{}, false
} }
// PostFormMap returns a map for a given form key. // PostFormMap returns a map for a given form key.
func (c *Context) PostFormMap(key string) map[string]string { func (c *Context) PostFormMap(key string) (dicts map[string]string) {
dicts, _ := c.GetPostFormMap(key) dicts, _ = c.GetPostFormMap(key)
return dicts return
} }
// GetPostFormMap returns a map for a given form key, plus a boolean value // GetPostFormMap returns a map for a given form key, plus a boolean value

View File

@ -102,8 +102,7 @@ func (r SecureJSON) Render(w http.ResponseWriter) error {
// if the jsonBytes is array values // if the jsonBytes is array values
if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes, if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes,
bytesconv.StringToBytes("]")) { bytesconv.StringToBytes("]")) {
_, err = w.Write(bytesconv.StringToBytes(r.Prefix)) if _, err = w.Write(bytesconv.StringToBytes(r.Prefix)); err != nil {
if err != nil {
return err return err
} }
} }
@ -130,20 +129,19 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
} }
callback := template.JSEscapeString(r.Callback) callback := template.JSEscapeString(r.Callback)
_, err = w.Write(bytesconv.StringToBytes(callback)) if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil {
if err != nil {
return err return err
} }
_, err = w.Write(bytesconv.StringToBytes("("))
if err != nil { if _, err = w.Write(bytesconv.StringToBytes("(")); err != nil {
return err return err
} }
_, err = w.Write(ret)
if err != nil { if _, err = w.Write(ret); err != nil {
return err return err
} }
_, err = w.Write(bytesconv.StringToBytes(");"))
if err != nil { if _, err = w.Write(bytesconv.StringToBytes(");")); err != nil {
return err return err
} }