Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename getQueryCache/getFormCache to initQueryCache/initFormCache #2375

Merged
merged 1 commit into from May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions context.go
Expand Up @@ -414,7 +414,7 @@ func (c *Context) QueryArray(key string) []string {
return values
}

func (c *Context) getQueryCache() {
func (c *Context) initQueryCache() {
if c.queryCache == nil {
c.queryCache = c.Request.URL.Query()
}
Expand All @@ -423,7 +423,7 @@ func (c *Context) getQueryCache() {
// 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.
func (c *Context) GetQueryArray(key string) ([]string, bool) {
c.getQueryCache()
c.initQueryCache()
if values, ok := c.queryCache[key]; ok && len(values) > 0 {
return values, true
}
Expand All @@ -439,7 +439,7 @@ func (c *Context) QueryMap(key string) map[string]string {
// GetQueryMap returns a map for a given query key, plus a boolean value
// whether at least one value exists for the given key.
func (c *Context) GetQueryMap(key string) (map[string]string, bool) {
c.getQueryCache()
c.initQueryCache()
return c.get(c.queryCache, key)
}

Expand Down Expand Up @@ -481,7 +481,7 @@ func (c *Context) PostFormArray(key string) []string {
return values
}

func (c *Context) getFormCache() {
func (c *Context) initFormCache() {
if c.formCache == nil {
c.formCache = make(url.Values)
req := c.Request
Expand All @@ -497,7 +497,7 @@ func (c *Context) getFormCache() {
// 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.
func (c *Context) GetPostFormArray(key string) ([]string, bool) {
c.getFormCache()
c.initFormCache()
if values := c.formCache[key]; len(values) > 0 {
return values, true
}
Expand All @@ -513,7 +513,7 @@ func (c *Context) PostFormMap(key string) map[string]string {
// GetPostFormMap returns a map for a given form key, plus a boolean value
// whether at least one value exists for the given key.
func (c *Context) GetPostFormMap(key string) (map[string]string, bool) {
c.getFormCache()
c.initFormCache()
return c.get(c.formCache, key)
}

Expand Down
13 changes: 6 additions & 7 deletions utils.go
Expand Up @@ -90,13 +90,13 @@ func filterFlags(content string) string {
}

func chooseData(custom, wildcard interface{}) interface{} {
if custom == nil {
if wildcard == nil {
panic("negotiation config is invalid")
}
if custom != nil {
return custom
}
if wildcard != nil {
return wildcard
}
return custom
panic("negotiation config is invalid")
}

func parseAccept(acceptHeader string) []string {
Expand Down Expand Up @@ -127,8 +127,7 @@ func joinPaths(absolutePath, relativePath string) string {
}

finalPath := path.Join(absolutePath, relativePath)
appendSlash := lastChar(relativePath) == '/' && lastChar(finalPath) != '/'
if appendSlash {
if lastChar(relativePath) == '/' && lastChar(finalPath) != '/' {
return finalPath + "/"
}
return finalPath
Expand Down