Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
arxdsilva committed Oct 19, 2022
1 parent ad79f36 commit c30e946
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 30 deletions.
8 changes: 2 additions & 6 deletions adapters/postgres/internal/connection/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ func GetPool() *Pool {

func getDatabaseFromPool(name string) *sqlx.DB {
var DB *sqlx.DB
var p *Pool

p = GetPool()
p := GetPool()

p.Mtx.Lock()
DB = p.DB[GetURI(name)]
Expand All @@ -112,9 +110,7 @@ func getDatabaseFromPool(name string) *sqlx.DB {

// AddDatabaseToPool add connection to pool
func AddDatabaseToPool(name string, DB *sqlx.DB) {
var p *Pool

p = GetPool()
p := GetPool()

p.Mtx.Lock()
p.DB[GetURI(name)] = DB
Expand Down
6 changes: 2 additions & 4 deletions adapters/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1385,9 +1385,7 @@ func columnsByRequest(r *http.Request) (columns []string, err error) {
columnsArr := queries["_select"]
for _, j := range columnsArr {
cArgs := strings.Split(j, ",")
for _, columnName := range cArgs {
columns = append(columns, columnName)
}
columns = append(columns, cArgs...)
}
if queries.Get("_groupby") != "" {
columns, err = normalizeAll(columns)
Expand All @@ -1405,7 +1403,7 @@ func (adapter *Postgres) DistinctClause(r *http.Request) (distinctQuery string,
distinctQuery = ""

if checkQuery == "true" {
distinctQuery = fmt.Sprintf("SELECT DISTINCT")
distinctQuery = "SELECT DISTINCT"
}
return
}
Expand Down
20 changes: 5 additions & 15 deletions adapters/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,26 +916,16 @@ func TestGetQueryOperator(t *testing.T) {
}

for _, tc := range testCases {
t.Log(fmt.Sprintf("Query operator %s", tc.in))
t.Logf("Query operator %s", tc.in)
op, err := GetQueryOperator(tc.in)
if err != nil {
t.Errorf("expected no errors, got: %v", err)
}

if op != tc.out {
t.Errorf("expected %s, got: %s", tc.out, op)
}
require.NoError(t, err)
require.Equal(t, tc.out, op)
}

t.Log("Invalid query operator")
op, err := GetQueryOperator("!lol")
if err == nil {
t.Errorf("expected errors, got: %v", err)
}

if op != "" {
t.Errorf("expected empty op, got: %s", op)
}
require.Error(t, err)
require.Empty(t, op)
}

func TestOrderByRequest(t *testing.T) {
Expand Down
9 changes: 4 additions & 5 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ var authUpCmd = &cobra.Command{
if config.PrestConf.Adapter == nil {
postgres.Load()
}

db, err := postgres.Get()
if err != nil {
fmt.Fprintf(os.Stdout, err.Error())
fmt.Fprint(os.Stdout, err.Error())
return err
}
_, err = db.Exec("CREATE TABLE IF NOT EXISTS %s.%s (id serial, name text, username text unique, password text, metadata jsonb)", config.PrestConf.AuthSchema, config.PrestConf.AuthTable)
if err != nil {
fmt.Fprintf(os.Stdout, err.Error())
fmt.Fprint(os.Stdout, err.Error())
return err
}
return nil
Expand All @@ -43,12 +42,12 @@ var authDownCmd = &cobra.Command{

db, err := postgres.Get()
if err != nil {
fmt.Fprintf(os.Stdout, err.Error())
fmt.Fprint(os.Stdout, err.Error())
return err
}
_, err = db.Exec("DROP TABLE IF EXISTS %s.%s", config.PrestConf.AuthSchema, config.PrestConf.AuthTable)
if err != nil {
fmt.Fprintf(os.Stdout, err.Error())
fmt.Fprint(os.Stdout, err.Error())
return err
}
return nil
Expand Down
1 change: 1 addition & 0 deletions controllers/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func ExecuteFromScripts(w http.ResponseWriter, r *http.Request) {
// Cache arrow if enabled
cache.BuntSet(r.URL.String(), string(result))
}
//nolint
w.Write(result)
}

Expand Down
1 change: 1 addition & 0 deletions controllers/sql_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint
package controllers

import (
Expand Down
1 change: 1 addition & 0 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ func HandlerPlugin(w http.ResponseWriter, r *http.Request) {
}
// Cache arrow if enabled
cache.BuntSet(r.URL.String(), ret)
//nolint
w.Write([]byte(ret))
}

0 comments on commit c30e946

Please sign in to comment.