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

Improved some conditions #1386

Merged
merged 16 commits into from
Jun 17, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/fasttemplate/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (t *Template) Reset(template, startTag, endTag string) error {
s = s[n+len(a):]
n = bytes.Index(s, b)
if n < 0 {
return fmt.Errorf("Cannot find end tag=%q in the template=%q starting from %q", endTag, template, s)
return fmt.Errorf("cannot find end tag=%q in the template=%q starting from %q", endTag, template, s)
}

t.tags = append(t.tags, unsafeBytes2String(s[:n]))
Expand Down
2 changes: 1 addition & 1 deletion internal/gopsutil/cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func parseStatLine(line string) (*TimesStat, error) {
return nil, errors.New("stat does not contain cpu info")
}

if strings.HasPrefix(fields[0], "cpu") == false {
if !strings.HasPrefix(fields[0], "cpu") {
return nil, errors.New("not contain cpu")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/gopsutil/net/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func IOCountersByFileWithContext(ctx context.Context, pernic bool, filename stri
ret = append(ret, nic)
}

if pernic == false {
if !pernic {
return getIOCountersAll(ret)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/msgp/read_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func ReadBytesBytes(b []byte, scratch []byte) (v []byte, o []byte, err error) {
return readBytesBytes(b, scratch, false)
}

func readBytesBytes(b []byte, scratch []byte, zc bool) (v []byte, o []byte, err error) {
func readBytesBytes(b, scratch []byte, zc bool) (v, o []byte, err error) {
l := len(b)
if l < 1 {
return nil, nil, ErrShortBytes
Expand Down Expand Up @@ -766,7 +766,7 @@ func readBytesBytes(b []byte, scratch []byte, zc bool) (v []byte, o []byte, err
// Possible errors:
// - ErrShortBytes (b not long enough)
// - TypeError{} (object not 'bin')
func ReadBytesZC(b []byte) (v []byte, o []byte, err error) {
func ReadBytesZC(b []byte) (v, o []byte, err error) {
return readBytesBytes(b, nil, true)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/msgp/write_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func AppendUint16(b []byte, u uint16) []byte { return AppendUint64(b, uint64(u))
func AppendUint32(b []byte, u uint32) []byte { return AppendUint64(b, uint64(u)) }

// AppendBytes appends bytes to the slice as MessagePack 'bin' data
func AppendBytes(b []byte, bts []byte) []byte {
func AppendBytes(b, bts []byte) []byte {
sz := len(bts)
var o []byte
var n int
Expand Down Expand Up @@ -229,7 +229,7 @@ func AppendString(b []byte, s string) []byte {

// AppendStringFromBytes appends a []byte
// as a MessagePack 'str' to the slice 'b.'
func AppendStringFromBytes(b []byte, str []byte) []byte {
func AppendStringFromBytes(b, str []byte) []byte {
sz := len(str)
var n int
var o []byte
Expand Down
12 changes: 6 additions & 6 deletions internal/schema/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sync"
)

var invalidPath = errors.New("schema: invalid path")
var errInvalidPath = errors.New("schema: invalid path")

// newCache returns a new cache.
func newCache() *cache {
Expand Down Expand Up @@ -53,13 +53,13 @@ func (c *cache) parsePath(p string, t reflect.Type) ([]pathPart, error) {
keys := strings.Split(p, ".")
for i := 0; i < len(keys); i++ {
if t.Kind() != reflect.Struct {
return nil, invalidPath
return nil, errInvalidPath
}
if struc = c.get(t); struc == nil {
return nil, invalidPath
return nil, errInvalidPath
}
if field = struc.get(keys[i]); field == nil {
return nil, invalidPath
return nil, errInvalidPath
}
// Valid field. Append index.
path = append(path, field.name)
Expand All @@ -72,10 +72,10 @@ func (c *cache) parsePath(p string, t reflect.Type) ([]pathPart, error) {
// So checking i+2 is not necessary anymore.
i++
if i+1 > len(keys) {
return nil, invalidPath
return nil, errInvalidPath
}
if index64, err = strconv.ParseInt(keys[i], 10, 0); err != nil {
return nil, invalidPath
return nil, errInvalidPath
}
parts = append(parts, pathPart{
path: path,
Expand Down
2 changes: 1 addition & 1 deletion internal/tlstest/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"
)

func GetTLSConfigs() (serverTLSConf *tls.Config, clientTLSConf *tls.Config, err error) {
func GetTLSConfigs() (serverTLSConf, clientTLSConf *tls.Config, err error) {
// set up our CA certificate
ca := &x509.Certificate{
SerialNumber: big.NewInt(2021),
Expand Down
4 changes: 2 additions & 2 deletions middleware/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func Test_Cache_CustomNext(t *testing.T) {

app.Use(New(Config{
Next: func(c *fiber.Ctx) bool {
return !(c.Response().StatusCode() == fiber.StatusOK)
return c.Response().StatusCode() != fiber.StatusOK
},
CacheControl: true,
}))
Expand Down Expand Up @@ -305,7 +305,7 @@ func Test_CacheHeader(t *testing.T) {
app.Use(New(Config{
Expiration: 10 * time.Second,
Next: func(c *fiber.Ctx) bool {
return !(c.Response().StatusCode() == fiber.StatusOK)
return c.Response().StatusCode() != fiber.StatusOK
},
}))

Expand Down
6 changes: 3 additions & 3 deletions middleware/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Test_Query_Params(t *testing.T) {
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, fiber.StatusNotFound, resp.StatusCode)

expected := fmt.Sprintf("foo=bar&baz=moz")
expected := "foo=bar&baz=moz"
utils.AssertEqual(t, expected, buf.String())
}

Expand All @@ -192,15 +192,15 @@ func Test_Response_Body(t *testing.T) {
_, err := app.Test(httptest.NewRequest("GET", "/", nil))
utils.AssertEqual(t, nil, err)

expectedGetResponse := fmt.Sprintf("Sample response body")
expectedGetResponse := "Sample response body"
utils.AssertEqual(t, expectedGetResponse, buf.String())

buf.Reset() // Reset buffer to test POST

_, err = app.Test(httptest.NewRequest("POST", "/test", nil))
utils.AssertEqual(t, nil, err)

expectedPostResponse := fmt.Sprintf("Post in test")
expectedPostResponse := "Post in test"
utils.AssertEqual(t, expectedPostResponse, buf.String())
}

Expand Down
4 changes: 2 additions & 2 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func parseRoute(pattern string) routeParser {
// addParameterMetaInfo add important meta information to the parameter segments
// to simplify the search for the end of the parameter
func addParameterMetaInfo(segs []*routeSegment) []*routeSegment {
comparePart := ""
var comparePart string
segLen := len(segs)
// loop from end to begin
for i := segLen - 1; i >= 0; i-- {
Expand Down Expand Up @@ -278,7 +278,7 @@ func (routeParser *routeParser) getMatch(detectionPath, path string, params *[ma
detectionPath, path = detectionPath[i:], path[i:]
}
}
if len(detectionPath) != 0 && !partialCheck {
if detectionPath != "" && !partialCheck {
return false
}

Expand Down
4 changes: 2 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (app *App) register(method, pathRaw string, handlers ...Handler) Router {

func (app *App) registerStatic(prefix, root string, config ...Static) Router {
// For security we want to restrict to the current work directory.
if len(root) == 0 {
if root == "" {
root = "."
}
// Cannot have an empty prefix
Expand Down Expand Up @@ -359,7 +359,7 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Router {
fileHandler := fs.NewRequestHandler()
handler := func(c *Ctx) error {
// Don't execute middleware if Next returns true
if config != nil && config[0].Next != nil && config[0].Next(c) {
if len(config) != 0 && config[0].Next != nil && config[0].Next(c) {
return c.Next()
}
// Serve file
Expand Down