fix golint issues, else blocks (#457)
This commit is contained in:
@@ -315,12 +315,13 @@ func buildRequest(rs requestSettings) (*http.Request, error) {
|
||||
var path string
|
||||
var query string
|
||||
if len(rs.requestUri) > 0 {
|
||||
if u, err := url.Parse(rs.requestUri); err != nil {
|
||||
u, err := url.Parse(rs.requestUri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
path = u.Path
|
||||
query = u.RawQuery
|
||||
}
|
||||
|
||||
path = u.Path
|
||||
query = u.RawQuery
|
||||
} else {
|
||||
path = r.URL.Path
|
||||
query = r.URL.RawQuery
|
||||
@@ -377,10 +378,9 @@ func createTempFile(body []byte) (string, error) {
|
||||
tmpFile, err := ioutil.TempFile(os.TempDir(), "go-unit-*.tmp")
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
tmpFile.Close()
|
||||
}
|
||||
|
||||
tmpFile.Close()
|
||||
err = ioutil.WriteFile(tmpFile.Name(), body, os.ModePerm)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -114,9 +114,9 @@ func dumpRequest(r *http.Request) string {
|
||||
reqContent, err := httputil.DumpRequest(r, true)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
} else {
|
||||
return string(reqContent)
|
||||
}
|
||||
|
||||
return string(reqContent)
|
||||
}
|
||||
|
||||
func logBrief(r *http.Request, code int, timer *utils.ElapsedTimer, logs *internal.LogCollector) {
|
||||
|
||||
@@ -89,9 +89,9 @@ type mockShedder struct {
|
||||
func (s mockShedder) Allow() (load.Promise, error) {
|
||||
if s.allow {
|
||||
return mockPromise{}, nil
|
||||
} else {
|
||||
return nil, load.ErrServiceOverloaded
|
||||
}
|
||||
|
||||
return nil, load.ErrServiceOverloaded
|
||||
}
|
||||
|
||||
type mockPromise struct {
|
||||
|
||||
@@ -24,6 +24,7 @@ var (
|
||||
pathUnmarshaler = mapping.NewUnmarshaler(pathKey, mapping.WithStringValues())
|
||||
)
|
||||
|
||||
// Parse parses the request.
|
||||
func Parse(r *http.Request, v interface{}) error {
|
||||
if err := ParsePath(r, v); err != nil {
|
||||
return err
|
||||
@@ -36,7 +37,7 @@ func Parse(r *http.Request, v interface{}) error {
|
||||
return ParseJsonBody(r, v)
|
||||
}
|
||||
|
||||
// Parses the form request.
|
||||
// ParseForm parses the form request.
|
||||
func ParseForm(r *http.Request, v interface{}) error {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
return err
|
||||
@@ -80,7 +81,7 @@ func ParseHeader(headerValue string) map[string]string {
|
||||
return ret
|
||||
}
|
||||
|
||||
// Parses the post request which contains json in body.
|
||||
// ParseJsonBody parses the post request which contains json in body.
|
||||
func ParseJsonBody(r *http.Request, v interface{}) error {
|
||||
var reader io.Reader
|
||||
if withJsonBody(r) {
|
||||
@@ -92,7 +93,7 @@ func ParseJsonBody(r *http.Request, v interface{}) error {
|
||||
return mapping.UnmarshalJsonReader(reader, v)
|
||||
}
|
||||
|
||||
// Parses the symbols reside in url path.
|
||||
// ParsePath parses the symbols reside in url path.
|
||||
// Like http://localhost/bag/:name
|
||||
func ParsePath(r *http.Request, v interface{}) error {
|
||||
vars := context.Vars(r)
|
||||
|
||||
@@ -4,7 +4,7 @@ import "net/http"
|
||||
|
||||
const xForwardFor = "X-Forward-For"
|
||||
|
||||
// Returns the peer address, supports X-Forward-For
|
||||
// GetRemoteAddr returns the peer address, supports X-Forward-For.
|
||||
func GetRemoteAddr(r *http.Request) string {
|
||||
v := r.Header.Get(xForwardFor)
|
||||
if len(v) > 0 {
|
||||
|
||||
@@ -43,13 +43,14 @@ func (pr *patRouter) Handle(method, reqPath string, handler http.Handler) error
|
||||
}
|
||||
|
||||
cleanPath := path.Clean(reqPath)
|
||||
if tree, ok := pr.trees[method]; ok {
|
||||
return tree.Add(cleanPath, handler)
|
||||
} else {
|
||||
tree = search.NewTree()
|
||||
pr.trees[method] = tree
|
||||
tree, ok := pr.trees[method]
|
||||
if ok {
|
||||
return tree.Add(cleanPath, handler)
|
||||
}
|
||||
|
||||
tree = search.NewTree()
|
||||
pr.trees[method] = tree
|
||||
return tree.Add(cleanPath, handler)
|
||||
}
|
||||
|
||||
func (pr *patRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -110,9 +111,9 @@ func (pr *patRouter) methodsAllowed(method, path string) (string, bool) {
|
||||
|
||||
if len(allows) > 0 {
|
||||
return strings.Join(allows, allowMethodSeparator), true
|
||||
} else {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
func validMethod(method string) bool {
|
||||
|
||||
@@ -58,9 +58,9 @@ func (tp *TokenParser) ParseToken(r *http.Request, secret, prevSecret string) (*
|
||||
token, err = tp.doParseToken(r, second)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
tp.incrementCount(second)
|
||||
}
|
||||
|
||||
tp.incrementCount(second)
|
||||
} else {
|
||||
tp.incrementCount(first)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user