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
515 changes: 515 additions & 0 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

72 changes: 0 additions & 72 deletions .github/workflows/goreleaser.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/test.yml

This file was deleted.

5 changes: 0 additions & 5 deletions authHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ func LoginWithProvider(w http.ResponseWriter, r *http.Request) error {

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

type ErrorData struct {
*CoreData
Error string
}

session, err := getSession(w, r)
if session, err = sanitizeSession(w, r, session, err); err != nil {
return fmt.Errorf("session error: %w", err)
Expand Down
6 changes: 0 additions & 6 deletions autoRefreshPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,3 @@ func TaskDoneAutoRefreshPage(w http.ResponseWriter, r *http.Request) error {
}
return nil
}

func taskRedirectWithoutQueryArgs(w http.ResponseWriter, r *http.Request) {
u := r.URL
u.RawQuery = ""
http.Redirect(w, r, u.String(), http.StatusSeeOther)
}
17 changes: 0 additions & 17 deletions bookmark_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,20 +563,3 @@ func FindPageBySha(tabs BookmarkList, sha string) *BookmarkPage {
return nil
}

// indexAfterColumn returns the global index after the last category in the specified column.
func indexAfterColumn(tabs BookmarkList, page *BookmarkPage, colIdx int) int {
idx := 0
for _, t := range tabs {
for _, p := range t.Pages {
for _, b := range p.Blocks {
for ci, col := range b.Columns {
idx += len(col.Categories)
if p == page && ci == colIdx {
return idx
}
}
}
}
}
return idx
}
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
4 changes: 2 additions & 2 deletions cmd/gobookmarks/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,12 @@ func runHandlerChain(chain ...any) func(http.ResponseWriter, *http.Request) {
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 func(http.ResponseWriter, *http.Request):
each(w, r)
case http.Handler:
each.ServeHTTP(w, r)
case func(http.ResponseWriter, *http.Request) error:
if err := each(w, r); err != nil {
if errors.Is(err, ErrHandled) {
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 @@ -149,9 +149,6 @@ https://example.com Example Link
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 @@ https://example.com Example Link
// 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
3 changes: 1 addition & 2 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
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
20 changes: 10 additions & 10 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ func NewFuncs(r *http.Request) template.FuncMap {

ref := r.URL.Query().Get("ref")
bookmarks, _, err := GetBookmarks(r.Context(), login, ref, token)
var bookmark = defaultBookmarks
var bookmark string
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
bookmark = defaultBookmarks
} else {
return nil, fmt.Errorf("bookmarkPages: %w", err)
}
Expand All @@ -250,10 +250,10 @@ func NewFuncs(r *http.Request) template.FuncMap {

ref := r.URL.Query().Get("ref")
bookmarks, _, err := GetBookmarks(r.Context(), login, ref, token)
var bookmark = defaultBookmarks
var bookmark string
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
bookmark = defaultBookmarks
} else {
return nil, fmt.Errorf("bookmarkTabs: %w", err)
}
Expand Down Expand Up @@ -290,10 +290,10 @@ func NewFuncs(r *http.Request) template.FuncMap {

ref := r.URL.Query().Get("ref")
bookmarks, _, err := GetBookmarks(r.Context(), login, ref, token)
var bookmark = defaultBookmarks
var bookmark string
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
bookmark = defaultBookmarks
} else {
return nil, fmt.Errorf("bookmarkTabsWithPages: %w", err)
}
Expand Down Expand Up @@ -332,10 +332,10 @@ func NewFuncs(r *http.Request) template.FuncMap {
}

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

bookmarks, _, err := GetBookmarks(r.Context(), login, r.URL.Query().Get("ref"), token)
var bookmark = defaultBookmarks
var bookmark string
if err != nil {
if errors.Is(err, ErrRepoNotFound) {
bookmark = ""
bookmark = defaultBookmarks
} else {
return nil, fmt.Errorf("bookmarkColumns: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/arran4/gobookmarks

go 1.25.0
go 1.24.0

require (
github.com/PuerkitoBio/goquery v1.8.1
Expand All @@ -15,7 +15,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.17
github.com/xanzy/go-gitlab v0.115.0
golang.org/x/crypto v0.45.0
golang.org/x/image v0.38.0
golang.org/x/image v0.24.0
golang.org/x/oauth2 v0.27.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/image v0.38.0 h1:5l+q+Y9JDC7mBOMjo4/aPhMDcxEptsX+Tt3GgRQRPuE=
golang.org/x/image v0.38.0/go.mod h1:/3f6vaXC+6CEanU4KJxbcUZyEePbyKbaLoDOe4ehFYY=
golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ=
golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand Down Expand Up @@ -147,8 +147,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
6 changes: 0 additions & 6 deletions provider_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ func getCachedBookmarks(user, ref string) (string, string, bool) {
return entry.bookmarks, entry.sha, true
}

func setCachedBookmarks(user, ref, bookmarks, sha string) {
key := cacheKey(user, ref)
bookmarksCache.Lock()
bookmarksCache.data[key] = &bookmarkCacheEntry{bookmarks: bookmarks, sha: sha, expiry: time.Now().Add(time.Minute)}
bookmarksCache.Unlock()
}

func invalidateBookmarkCache(user string) {
bookmarksCache.Lock()
Expand Down
5 changes: 3 additions & 2 deletions provider_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (GitHubProvider) client(ctx context.Context, token *oauth2.Token) *github.C
if server == "" || server == "https://github.com" {
return github.NewClient(httpClient)
}
c, err := github.NewEnterpriseClient(server+"/api/v3/", server+"/upload/v3/", httpClient)
c, err := github.NewClient(httpClient).WithEnterpriseURLs(server+"/api/v3/", server+"/upload/v3/")
if err != nil {
return github.NewClient(httpClient)
}
Expand Down Expand Up @@ -150,7 +150,8 @@ func (p GitHubProvider) GetBookmarks(ctx context.Context, user, ref string, toke

var commitAuthor = &github.CommitAuthor{Name: SP("Gobookmarks"), Email: SP("Gobookmarks@arran.net.au")}

func (p GitHubProvider) getDefaultBranch(ctx context.Context, user string, client *github.Client, branch string) (string, error) {
func (p GitHubProvider) getDefaultBranch(ctx context.Context, user string, client *github.Client, _ string) (string, error) {
var branch string
rep, resp, err := client.Repositories.Get(ctx, user, Config.GetRepoName())
if resp != nil && resp.StatusCode == 404 {
return "", ErrRepoNotFound
Expand Down
5 changes: 4 additions & 1 deletion provider_gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (GitLabProvider) Config(clientID, clientSecret, redirectURL string) *oauth2
}
}

//nolint:staticcheck
func (GitLabProvider) client(token *oauth2.Token) (*gitlab.Client, error) {
server := Config.GitlabServer
if server == "" {
Expand Down Expand Up @@ -182,7 +183,9 @@ func (GitLabProvider) GetBookmarks(ctx context.Context, user, ref string, token
return string(data), f.LastCommitID, nil
}

func (GitLabProvider) getDefaultBranch(ctx context.Context, user string, client *gitlab.Client, branch string) (string, error) {
//nolint:staticcheck
func (GitLabProvider) getDefaultBranch(ctx context.Context, user string, client *gitlab.Client, _ string) (string, error) {
var branch string
p, _, err := client.Projects.GetProject(user+"/"+Config.GetRepoName(), nil)
if err != nil {
if respErr, ok := err.(*gitlab.ErrorResponse); ok {
Expand Down
Loading
Loading