Skip to content

Commit

Permalink
Rename some variables (#2393)
Browse files Browse the repository at this point in the history
  • Loading branch information
bestgopher committed May 25, 2020
1 parent 5f261fa commit c9b8535
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ 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() {
case reflect.Struct:
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.
Expand Down Expand Up @@ -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
}
}

Expand Down
6 changes: 3 additions & 3 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
)

type onlyfilesFS struct {
type onlyFilesFS struct {
fs http.FileSystem
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion routergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit c9b8535

Please sign in to comment.