Skip to content

Commit

Permalink
code quality updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Dec 28, 2018
1 parent 31fcc59 commit def7ed0
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 67 deletions.
4 changes: 2 additions & 2 deletions aah.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Application struct {
// Introduced in v0.12.0 release.
func (a *Application) InitForCLI(importPath string) error {
a.settings.ImportPath = path.Clean(importPath)
a.Log().(*log.Logger).SetLevel("warn")
_ = a.Log().(*log.Logger).SetLevel("warn")
var err error
if err = a.initPath(); err != nil {
return err
Expand All @@ -147,7 +147,7 @@ func (a *Application) InitForCLI(importPath string) error {
if err = a.initRouter(); err != nil {
return err
}
a.Log().(*log.Logger).SetLevel("debug")
_ = a.Log().(*log.Logger).SetLevel("debug")
return nil
}

Expand Down
11 changes: 6 additions & 5 deletions aah_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func TestAahApp(t *testing.T) {
secretstr := ts.app.SecurityManager().AntiCSRF.SaltCipherSecret(secret)
form.Add("anti_csrf_token", secretstr)
wt := httptest.NewRecorder()
ts.app.SecurityManager().AntiCSRF.SetCookie(wt, secret)
err = ts.app.SecurityManager().AntiCSRF.SetCookie(wt, secret)
assert.Nil(t, err)
cookieValue := wt.Header().Get("Set-Cookie")
req, err = http.NewRequest(ahttp.MethodPost, ts.URL+"/form-submit", strings.NewReader(form.Encode()))
assert.Nil(t, err)
Expand Down Expand Up @@ -221,13 +222,13 @@ func TestAppMisc(t *testing.T) {
l, _ := log.New(config.NewEmpty())
pa.logger = l
pa.SetPackaged(true)
pa.initPath()
_ = pa.initPath()

// App embedded mode
assert.False(t, pa.VFS().IsEmbeddedMode())
pa.VFS().SetEmbeddedMode()
assert.True(t, pa.VFS().IsEmbeddedMode())
pa.initPath()
_ = pa.initPath()

// App WS engine
assert.Nil(t, pa.WSEngine())
Expand Down Expand Up @@ -268,7 +269,7 @@ func TestLogInitRelativeFilePath(t *testing.T) {
err := a.initLog()
assert.Nil(t, err)

a.AddLoggerHook("myapphook", func(e log.Entry) {
_ = a.AddLoggerHook("myapphook", func(e log.Entry) {
t.Logf("%v", e)
})
}
Expand All @@ -288,7 +289,7 @@ func TestLogInitNoFilePath(t *testing.T) {
err := a.initLog()
assert.Nil(t, err)

a.AddLoggerHook("myapphook", func(e log.Entry) {
_ = a.AddLoggerHook("myapphook", func(e log.Entry) {
t.Logf("%v", e)
})
}
Expand Down
3 changes: 1 addition & 2 deletions aruntime/diagnosis/diagnosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func (d *Diagnosis) doProfileByName(w io.Writer, name string, gc bool, debug, va
runtime.SetMutexProfileFraction(val) // https://golang.org/pkg/runtime/#SetMutexProfileFraction
defer func() { runtime.SetMutexProfileFraction(0) }()
}
p.WriteTo(w, debug)
return nil
return p.WriteTo(w, debug)
}

func (d *Diagnosis) sleep(w io.Writer, dur time.Duration) {
Expand Down
4 changes: 2 additions & 2 deletions aruntime/diagnosis/http_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (d *Diagnosis) dynamicProfileHandler(w http.ResponseWriter, r *http.Request
return
}
}
w.Write([]byte("Unknown profile"))
_, _ = w.Write([]byte("Unknown profile"))
}

// CmdlineHandler responds with the running program's
Expand Down Expand Up @@ -322,7 +322,7 @@ func (d *Diagnosis) symbolHandler(w http.ResponseWriter, r *http.Request) {
}
}

w.Write(buf.Bytes())
_, _ = w.Write(buf.Bytes())
}

func durationExceedsWriteTimeout(r *http.Request, seconds float64) bool {
Expand Down
6 changes: 3 additions & 3 deletions console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestConsoleMisc(t *testing.T) {
cli.AppHelpTemplate = ""
cli.CommandHelpTemplate = ""
cli.SubcommandHelpTemplate = ""
ShowAppHelp(ctx)
ShowCommandHelp(ctx, "help")
ShowSubcommandHelp(ctx)
_ = ShowAppHelp(ctx)
_ = ShowCommandHelp(ctx, "help")
_ = ShowSubcommandHelp(ctx)
}
4 changes: 2 additions & 2 deletions essentials/filepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ func CopyDir(dest, src string, excludes Excludes) error {
}

// copy source into destination
if _, err = CopyFile(destPath, srcPath); err != nil {
return err
if _, er := CopyFile(destPath, srcPath); er != nil {
return er
}

// Apply source permision into target as well
Expand Down
7 changes: 1 addition & 6 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package util

import (
"errors"
"html/template"
"io"
"mime"
Expand All @@ -18,10 +17,6 @@ import (
"aahframe.work/ahttp"
)

var (
errSeeker = errors.New("static: seeker can't seek")
)

// IsValidTimeUnit method to check supported time unit suffixes.
// If supported returns true otherwise false.
func IsValidTimeUnit(str string, units ...string) bool {
Expand All @@ -47,7 +42,7 @@ func DetectFileContentType(file string, content io.ReadSeeker) (string, error) {

// rewind to output whole file
if _, err := content.Seek(0, io.SeekStart); err != nil {
return "", errSeeker
return "", err
}
}
return ctype, nil
Expand Down
20 changes: 1 addition & 19 deletions log/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package log

import (
"bytes"
"encoding/json"
"fmt"
slog "log"
Expand All @@ -15,8 +14,7 @@ import (
)

var (
entryPool *sync.Pool
bufPool *sync.Pool
entryPool = &sync.Pool{New: func() interface{} { return newEntry() }}
_ Loggerer = (*Entry)(nil)
)

Expand Down Expand Up @@ -326,19 +324,3 @@ func releaseEntry(e *Entry) {
e.Reset()
entryPool.Put(e)
}

func acquireBuffer() *bytes.Buffer {
return bufPool.Get().(*bytes.Buffer)
}

func releaseBuffer(buf *bytes.Buffer) {
if buf != nil {
buf.Reset()
bufPool.Put(buf)
}
}

func init() {
bufPool = &sync.Pool{New: func() interface{} { return &bytes.Buffer{} }}
entryPool = &sync.Pool{New: func() interface{} { return newEntry() }}
}
4 changes: 1 addition & 3 deletions reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,9 @@ func releaseBuffer(b *bytes.Buffer) {
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Render Definiyions
// Render Definitions
//______________________________________________________________________________

const defaultSecureJSONPrefix = ")]}',\n"

var xmlHeaderBytes = []byte(xml.Header)

// Render interface to various rendering classifcation for HTTP responses.
Expand Down
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func handleRoute(ctx *Context) flowResult {
ctx.Req.URLParams = urlParams

// Serving static file
if route.IsStatic {
if ctx.route.IsStatic {
if err := ctx.a.staticMgr.Serve(ctx); err == errFileNotFound {
ctx.Log().Warnf("Static file not found, Host: %s, Path: %s", ctx.Req.Host, ctx.Req.Path)
ctx.Reply().done = false
Expand Down
2 changes: 1 addition & 1 deletion security/anticsrf/anti_csrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestAntiCSRFNotEnabled(t *testing.T) {

assert.False(t, antiCSRF.Enabled)

antiCSRF.SetCookie(nil, []byte{})
_ = antiCSRF.SetCookie(nil, []byte{})
antiCSRF.ClearCookie(nil, nil)
antiCSRF.CipherSecret(nil)

Expand Down
5 changes: 2 additions & 3 deletions security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,14 @@ security {
client := &http.Client{Jar: cookieJar}

r1, _ := http.NewRequest(http.MethodGet, ts.URL+"/local-oauth/login", nil)
resp, err := client.Do(r1)
_, err = client.Do(r1)
assert.Nil(t, err)
// assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)

testOAuth2 := new(testOAuth2Auth)
assert.Nil(t, oauth.SetPrincipalProvider(testOAuth2))
assert.Nil(t, oauth.SetAuthorizer(testOAuth2))

resp, err = client.Do(r1)
resp, err := client.Do(r1)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)

Expand Down
5 changes: 0 additions & 5 deletions static.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package aah

import (
"bytes"
"errors"
"fmt"
"html/template"
"io"
Expand All @@ -24,10 +23,6 @@ import (
"aahframe.work/vfs"
)

var (
errSeeker = errors.New("static: seeker can't seek")
)

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// app Unexported methods
//______________________________________________________________________________
Expand Down
4 changes: 2 additions & 2 deletions vfs/vfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func createVFS(t *testing.T) *VFS {
assert.Nil(t, err)
assert.NotNil(t, m)

err = filepath.Walk(mountDir, func(fpath string, info os.FileInfo, err error) error {
werr := filepath.Walk(mountDir, func(fpath string, info os.FileInfo, err error) error {
if info.IsDir() {
err = m.AddDir(&NodeInfo{
Dir: info.IsDir(),
Expand Down Expand Up @@ -275,7 +275,7 @@ func createVFS(t *testing.T) *VFS {
}
return nil
})
assert.Nil(t, err)
assert.Nil(t, werr)

return fs
}
Expand Down
11 changes: 1 addition & 10 deletions view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ package view

import (
"html/template"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"testing"

"aahframe.work/config"
"aahframe.work/log"
"aahframe.work/vfs"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -73,16 +70,10 @@ func testdataBaseDir() string {

func newVFS() *vfs.VFS {
fs := new(vfs.VFS)
fs.AddMount("/testdata", testdataBaseDir())
_ = fs.AddMount("/testdata", testdataBaseDir())
return fs
}

func join(s ...string) string {
return "/" + path.Join(s...)
}

func newLog() log.Loggerer {
l, _ := log.New(config.NewEmpty())
l.SetWriter(ioutil.Discard)
return l
}
2 changes: 1 addition & 1 deletion ws/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func addWebSocketEvents(t *testing.T, wse *Engine) {
assert.Equal(t, EventOnPostConnect, eventName)
assert.NotNil(t, ctx)
if ctx.Req.QueryValue("disconnect") == "true" {
ctx.Disconnect()
_ = ctx.Disconnect()
}
})
wse.OnPostDisconnect(func(eventName string, ctx *Context) {
Expand Down

0 comments on commit def7ed0

Please sign in to comment.