forked from mirror/gin
Rename some variables (#2393)
This commit is contained in:
parent
5f261fa752
commit
c9b8535817
20
errors.go
20
errors.go
|
@ -55,7 +55,7 @@ func (msg *Error) SetMeta(data interface{}) *Error {
|
|||
|
||||
// JSON creates a properly formatted JSON
|
||||
func (msg *Error) JSON() interface{} {
|
||||
json := H{}
|
||||
jsonData := H{}
|
||||
if msg.Meta != nil {
|
||||
value := reflect.ValueOf(msg.Meta)
|
||||
switch value.Kind() {
|
||||
|
@ -63,16 +63,16 @@ func (msg *Error) JSON() interface{} {
|
|||
return msg.Meta
|
||||
case reflect.Map:
|
||||
for _, key := range value.MapKeys() {
|
||||
json[key.String()] = value.MapIndex(key).Interface()
|
||||
jsonData[key.String()] = value.MapIndex(key).Interface()
|
||||
}
|
||||
default:
|
||||
json["meta"] = msg.Meta
|
||||
jsonData["meta"] = msg.Meta
|
||||
}
|
||||
}
|
||||
if _, ok := json["error"]; !ok {
|
||||
json["error"] = msg.Error()
|
||||
if _, ok := jsonData["error"]; !ok {
|
||||
jsonData["error"] = msg.Error()
|
||||
}
|
||||
return json
|
||||
return jsonData
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaller interface.
|
||||
|
@ -135,17 +135,17 @@ func (a errorMsgs) Errors() []string {
|
|||
}
|
||||
|
||||
func (a errorMsgs) JSON() interface{} {
|
||||
switch len(a) {
|
||||
switch length := len(a); length {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return a.Last().JSON()
|
||||
default:
|
||||
json := make([]interface{}, len(a))
|
||||
jsonData := make([]interface{}, length)
|
||||
for i, err := range a {
|
||||
json[i] = err.JSON()
|
||||
jsonData[i] = err.JSON()
|
||||
}
|
||||
return json
|
||||
return jsonData
|
||||
}
|
||||
}
|
||||
|
||||
|
|
6
fs.go
6
fs.go
|
@ -9,7 +9,7 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
type onlyfilesFS struct {
|
||||
type onlyFilesFS struct {
|
||||
fs http.FileSystem
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,11 @@ func Dir(root string, listDirectory bool) http.FileSystem {
|
|||
if listDirectory {
|
||||
return fs
|
||||
}
|
||||
return &onlyfilesFS{fs}
|
||||
return &onlyFilesFS{fs}
|
||||
}
|
||||
|
||||
// Open conforms to http.Filesystem.
|
||||
func (fs onlyfilesFS) Open(name string) (http.File, error) {
|
||||
func (fs onlyFilesFS) Open(name string) (http.File, error) {
|
||||
f, err := fs.fs.Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -187,7 +187,7 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
|
|||
fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
|
||||
|
||||
return func(c *Context) {
|
||||
if _, nolisting := fs.(*onlyfilesFS); nolisting {
|
||||
if _, noListing := fs.(*onlyFilesFS); noListing {
|
||||
c.Writer.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue