Skip to content
Open
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
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v9
with:
version: latest
version: v2.11

go-test:
name: Go lint/test (${{ matrix.os }})
Expand All @@ -310,7 +310,7 @@ jobs:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
Expand All @@ -324,7 +324,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
Expand All @@ -340,7 +340,7 @@ jobs:

- name: Setup Go (if needed)
if: ${{ needs.discover.outputs.has_go == 'true' }}
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version-file: go.mod

Expand Down Expand Up @@ -410,7 +410,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod

Expand Down
13 changes: 0 additions & 13 deletions .golangci.yml

This file was deleted.

3 changes: 2 additions & 1 deletion authHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func UserLogoutAction(w http.ResponseWriter, r *http.Request) error {
return fmt.Errorf("session.Save Error: %w", err)
}

data.CoreData.UserRef = ""
data.UserRef = ""

return nil
}
Expand Down Expand Up @@ -106,6 +106,7 @@ func LoginWithProvider(w http.ResponseWriter, r *http.Request) error {

func Oauth2CallbackPage(w http.ResponseWriter, r *http.Request) error {

//nolint:unused
type ErrorData struct {
*CoreData
Error string
Expand Down
1 change: 1 addition & 0 deletions autoRefreshPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TaskDoneAutoRefreshPage(w http.ResponseWriter, r *http.Request) error {
return nil
}

//nolint:unused
func taskRedirectWithoutQueryArgs(w http.ResponseWriter, r *http.Request) {
u := r.URL
u.RawQuery = ""
Expand Down
2 changes: 1 addition & 1 deletion bookmarkTabEdit.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func ReplaceTabByIndex(bookmarks string, idx int, newName, newText string) (stri
end := starts[idx+1]

var replacement []string
includeHeader := !(idx == 0 && newName == "")
includeHeader := idx != 0 || newName != ""
if includeHeader {
if newName != "" {
replacement = append(replacement, "Tab: "+newName)
Expand Down
8 changes: 4 additions & 4 deletions bookmark_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestAddTab(t *testing.T) {
p := &BookmarkPage{Blocks: []*BookmarkBlock{{Columns: []*BookmarkColumn{{}}}}}
p.Blocks[0].Columns[0].AddCategory(&BookmarkCategory{Name: "C"})
nl.AddPage(p)
var list BookmarkList = tabs
list := BookmarkList(tabs)
list.AddTab(nl)
got := list.String()
if got != addTabExpected {
Expand All @@ -133,7 +133,7 @@ func TestInsertTab(t *testing.T) {
p := &BookmarkPage{Blocks: []*BookmarkBlock{{Columns: []*BookmarkColumn{{}}}}}
p.Blocks[0].Columns[0].AddCategory(&BookmarkCategory{Name: "X"})
nl.AddPage(p)
var list BookmarkList = tabs
list := BookmarkList(tabs)
list.InsertTab(1, nl)
got := list.String()
if got != insertTabExpected {
Expand All @@ -143,7 +143,7 @@ func TestInsertTab(t *testing.T) {

func TestSwitchTab(t *testing.T) {
tabs := ParseBookmarks(switchTabInput)
var list BookmarkList = tabs
list := BookmarkList(tabs)
list.SwitchTabs(0, 1)
got := list.String()
if got != switchTabExpected {
Expand All @@ -153,7 +153,7 @@ func TestSwitchTab(t *testing.T) {

func TestMoveTab(t *testing.T) {
tabs := ParseBookmarks(switchTabInput)
var list BookmarkList = tabs
list := BookmarkList(tabs)
list.MoveTab(0, 1)
got := list.String()
if got != switchTabExpected {
Expand Down
3 changes: 2 additions & 1 deletion bookmark_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type BookmarkTab struct {

func (t *BookmarkTab) stringWithContext(first bool) string {
var sb strings.Builder
if !(first && t.Name == "") {
if !first || t.Name != "" {
if t.Name != "" {
sb.WriteString("Tab: ")
sb.WriteString(t.Name)
Expand Down Expand Up @@ -564,6 +564,7 @@ func FindPageBySha(tabs BookmarkList, sha string) *BookmarkPage {
}

// indexAfterColumn returns the global index after the last category in the specified column.
//nolint:unused
func indexAfterColumn(tabs BookmarkList, page *BookmarkPage, colIdx int) int {
idx := 0
for _, t := range tabs {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gobookmarks/db_reset_password_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"flag"
"fmt"

. "github.com/arran4/gobookmarks"
. "github.com/arran4/gobookmarks" //nolint:staticcheck
)

type DbResetPasswordCommand struct {
Expand Down
6 changes: 3 additions & 3 deletions cmd/gobookmarks/db_users_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"
"fmt"

. "github.com/arran4/gobookmarks"
. "github.com/arran4/gobookmarks" //nolint:staticcheck
)

type DbUsersCommand struct {
Expand Down Expand Up @@ -57,14 +57,14 @@ func (c *DbUsersCommand) Execute(args []string) error {
printHelp(c, err)
return err
}
defer db.Close()
defer func() { _ = db.Close() }()

rows, err := db.Query("SELECT user FROM passwords")
if err != nil {
printHelp(c, err)
return err
}
defer rows.Close()
defer func() { _ = rows.Close() }()

for rows.Next() {
var user string
Expand Down
2 changes: 1 addition & 1 deletion cmd/gobookmarks/help_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *HelpCommand) Execute(args []string) error {
}
}
}
c.FlagSet().Parse(args)
_ = c.FlagSet().Parse(args)
c.FlagSet().Usage = func() {}
printHelp(target, nil)
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/gobookmarks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"os"

. "github.com/arran4/gobookmarks"
. "github.com/arran4/gobookmarks" //nolint:staticcheck
)

var (
Expand Down
8 changes: 4 additions & 4 deletions cmd/gobookmarks/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"errors"
"flag"
"fmt"
. "github.com/arran4/gobookmarks"

Check failure on line 16 in cmd/gobookmarks/serve.go

View workflow job for this annotation

GitHub Actions / lint

ST1001: should not use dot imports (staticcheck)
"github.com/arran4/gorillamuxlogic"
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
Expand Down Expand Up @@ -452,7 +452,7 @@
if err != nil {
log.Fatalf("Failed to create cert.pem file: %v", err)
}
defer certFile.Close()
defer func() { _ = certFile.Close() }()
if err := pem.Encode(certFile, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil {
log.Fatalf("Failed to write data to cert.pem: %v", err)
}
Expand All @@ -461,7 +461,7 @@
if err != nil {
log.Fatalf("Failed to create key.pem file: %v", err)
}
defer keyFile.Close()
defer func() { _ = keyFile.Close() }()
privBytes, err := x509.MarshalECPrivateKey(priv)
if err != nil {
log.Fatalf("Failed to marshal private key: %v", err)
Expand All @@ -475,10 +475,10 @@
return func(w http.ResponseWriter, r *http.Request) {
for _, each := range chain {
switch each := each.(type) {
case http.Handler:
each.ServeHTTP(w, r)
case http.HandlerFunc:
each(w, r)
case http.Handler:
each.ServeHTTP(w, r)
case func(http.ResponseWriter, *http.Request):
each(w, r)
case func(http.ResponseWriter, *http.Request) error:
Expand Down
9 changes: 3 additions & 6 deletions cmd/gobookmarks/test_verification_template_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"net/http"
"os"

. "github.com/arran4/gobookmarks"

Check failure on line 13 in cmd/gobookmarks/test_verification_template_command.go

View workflow job for this annotation

GitHub Actions / lint

ST1001: should not use dot imports (staticcheck)
)

type TemplateCommand struct {
Expand Down Expand Up @@ -149,9 +149,6 @@
if input.Bookmarks != "" {
bookmarksStr = input.Bookmarks
}
} else {
// Just to debug if set is true or not
// fmt.Println("DEBUG: DataFromJsonFile is NOT set")
}

// Create a dummy request to build the context
Expand Down Expand Up @@ -303,14 +300,14 @@
// For serving, we need to handle main.css and favicon too, otherwise the page looks broken
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write(output)
_, _ = w.Write(output)
})
mux.HandleFunc("/main.css", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/css")
w.Write(GetMainCSSData())
_, _ = w.Write(GetMainCSSData())
})
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
w.Write(GetFavicon())
_, _ = w.Write(GetFavicon())
})
// Also proxy/favicon if possible, but that might require internet or network
mux.HandleFunc("/proxy/favicon", func(w http.ResponseWriter, r *http.Request) {
Expand Down
7 changes: 3 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -93,7 +92,7 @@ func LoadConfigFile(path string) (Configuration, bool, error) {

log.Printf("attempting to load config from %s", path)

data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
log.Printf("config file %s not found", path)
Expand Down Expand Up @@ -280,7 +279,7 @@ func LoadEnvFile(path string) error {
}
return err
}
defer f.Close()
defer func() { _ = f.Close() }()

scanner := bufio.NewScanner(f)
for scanner.Scan() {
Expand All @@ -295,7 +294,7 @@ func LoadEnvFile(path string) error {
key := strings.TrimSpace(parts[0])
val := strings.TrimSpace(parts[1])
if os.Getenv(key) == "" {
os.Setenv(key, val)
_ = os.Setenv(key, val)
}
}
return scanner.Err()
Expand Down
4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func OpenDB() (*sql.DB, error) {
}

if err := db.Ping(); err != nil {
db.Close()
_ = db.Close()
return nil, NewSystemError("Database error", err)
}

if err := ensureSQLSchema(db); err != nil {
db.Close()
_ = db.Close()
return nil, NewSystemError("Database error", fmt.Errorf("failed to ensure schema: %w", err))
}
return db, nil
Expand Down
4 changes: 2 additions & 2 deletions favicon_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func newFaviconServer(t *testing.T, icon []byte) (*httptest.Server, *int) {
hits := 0
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<link rel='icon' href='/favicon.ico'>"))
_, _ = w.Write([]byte("<link rel='icon' href='/favicon.ico'>"))
})
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
hits++
w.Header().Set("Cache-Control", "max-age=1")
w.Header().Set("Content-Type", "image/png")
w.Write(icon)
_, _ = w.Write(icon)
})
return httptest.NewServer(mux), &hits
}
Expand Down
15 changes: 10 additions & 5 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ func NewFuncs(r *http.Request) template.FuncMap {

ref := r.URL.Query().Get("ref")
bookmarks, _, err := GetBookmarks(r.Context(), login, ref, token)
var bookmark = defaultBookmarks
bookmark := defaultBookmarks
_ = bookmark
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
Expand Down Expand Up @@ -250,7 +251,8 @@ func NewFuncs(r *http.Request) template.FuncMap {

ref := r.URL.Query().Get("ref")
bookmarks, _, err := GetBookmarks(r.Context(), login, ref, token)
var bookmark = defaultBookmarks
bookmark := defaultBookmarks
_ = bookmark
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
Expand Down Expand Up @@ -290,7 +292,8 @@ func NewFuncs(r *http.Request) template.FuncMap {

ref := r.URL.Query().Get("ref")
bookmarks, _, err := GetBookmarks(r.Context(), login, ref, token)
var bookmark = defaultBookmarks
bookmark := defaultBookmarks
_ = bookmark
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
Expand Down Expand Up @@ -332,7 +335,8 @@ func NewFuncs(r *http.Request) template.FuncMap {
}

bookmarks, _, err := GetBookmarks(r.Context(), login, r.URL.Query().Get("ref"), token)
var bookmark = defaultBookmarks
bookmark := defaultBookmarks
_ = bookmark
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
Expand Down Expand Up @@ -364,7 +368,8 @@ func NewFuncs(r *http.Request) template.FuncMap {
}

bookmarks, _, err := GetBookmarks(r.Context(), login, r.URL.Query().Get("ref"), token)
var bookmark = defaultBookmarks
bookmark := defaultBookmarks
_ = bookmark
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
Expand Down
Loading
Loading