gobookmarks

package module
v1.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

README

gobookmarks

logo.png

The purpose of the site is to display a list of links for you to see every time you open your browser. I have tried to move as much of the work into the app as possible with minimal effort but you will need to use github occasionally.

img_4.png

This project is a converstion of a project: goa4web-bookmarks to remove the SQL and replace it with Github. Which itself is extract from goa4web, which is a Go port of a C++ site I made in 2003. Ported using ChatGPT: a4web. It's all been minimally modified and as close to the original as I could get but with the changes I required. I made modifications to this because StartHere my SPA version using modern tech failed because of Github Oauth2 restrictions on SPA sites. You can read more about this here: https://arranubels.substack.com/p/quicklinks

How to use

  1. Create a (private or public doesn't matter) repo in github under your user name called: "MyBookmarks"
  2. Create 1 file in it called bookmarks.txt Put the following content (or anything you want really):
Category: Search
http://www.google.com.au Google
Category: Wikies
http://en.wikipedia.org/wiki/Main_Page Wikipedia
http://mathworld.wolfram.com/ Math World
http://gentoo-wiki.com/Main_Page Gentoo-wiki

Ie: img_3.png 3. Goto the URL this app is deployed at, your private instance or: https://bookmarks.arran.net.au 4. Enjoy

File format

It's a basic file format. Every command must be on it's own line empty lines are ignored.

Code Meaning
Category: <category> Will create a category title.
<Link> Will create a link to <Link> with the display name <Link>
<Link> <Name> Will create a link to <Link> with the display name <Name>
Column Will create a column
Page Creates a new page
-- Inserts a horizontal rule and resets columns

Editing

The /edit page allows updating the entire bookmark file. Each category heading on the index page now includes a small pencil icon link that opens /editCategory. This page shows only the selected category text and saves changes back to your bookmarks without touching other sections. Edits check the file's SHA so you'll get an error if it changed while you were editing.

img.png

img_1.png

img_2.png

How to setup for yourself

You can run this yourself. There is a docker version available under my github packages. There are also precompiled versions under the releases section of this git repo: https://github.com/arran4/StartHere/releases

Configuration values can be supplied as environment variables, via a JSON configuration file or using command line arguments. Environment variables are the lowest priority, followed by the configuration file and finally command line arguments. If /etc/gobookmarks/gobookmarks.env exists it will be loaded before reading the environment.

Name Description
OAUTH2_CLIENT_ID OAuth2 client ID from https://github.com/settings/developers
OAUTH2_SECRET OAuth2 client secret from https://github.com/settings/developers
EXTERNAL_URL Fully qualified URL the service is reachable on, e.g. http://localhost:8080
GBM_CSS_COLUMNS If set (to any value) the Column keyword in your bookmarks will create CSS multi-column breaks rather than table cells.
GBM_PROVIDER Git provider to use (github or gitlab). Defaults to github.
GBM_NAMESPACE Optional suffix added to the bookmarks repository name.
GBM_TITLE Overrides the page title shown in the browser.
GIT_SERVER Base URL for a self-hosted git provider, e.g. https://gitlab.example.com. Defaults to the public server for the selected provider.
GOBM_ENV_FILE Path to a file of KEY=VALUE pairs loaded before the environment. Defaults to /etc/gobookmarks/gobookmarks.env.
GOBM_CONFIG_FILE Path to the JSON config file. If unset the program uses $XDG_CONFIG_HOME/gobookmarks/config.json or $HOME/.config/gobookmarks/config.json for normal users and /etc/gobookmarks/config.json when run as root.

You can place these settings in /etc/gobookmarks/gobookmarks.env as KEY=VALUE pairs and the service will load them automatically if the file exists. The release packages do not install this file; create it manually if you want to use environment-based settings.

Use --config <path> or set GOBM_CONFIG_FILE to control which configuration file is loaded.

The --provider command line flag or GBM_PROVIDER environment variable selects which git provider to use. By default the binary includes both GitHub and GitLab support. Use build tags nogithub or nogitlab to exclude either provider when building from source. If you specify an unknown provider the program will exit with an error listing the available options. The --title flag or GBM_TITLE environment variable sets the browser page title. Use --git-server or GIT_SERVER to override the base URL of the git provider (defaults to the provider's public server).

Running gobookmarks --version will print the version information along with the list of compiled-in providers. Use --dump-config to print the final configuration after merging the environment, config file and command line arguments.

Oauth2 setup

Visit: https://github.com/settings/developers

Create an application, call it what ever you like. Set the Callback URL what ever you put in EXTERNAL_URL and add: /oauth2Callback to the end, ie if you entered: http://localhost:8080 it should be: http://localhost:8080/oauth2Callback

Upload logo.png for the logo.

Generate a secret key and use it for the environment variables with the Client Id.

Running as a Service

The release packages include service files for both systemd and FreeBSD rc.d. During installation these files can be copied to your system so the server starts automatically on boot.

When installed from the release packages the service files pass --config /etc/gobookmarks/config.json. An example config file is included in the packages and is installed with permissions 0600 owned by the gobookmarks user. The installation process creates this user automatically and both service files run the daemon as gobookmarks.

Docker

The Docker image continues to work as before. Mount /data if you need persistent storage and pass the same environment variables as listed above. You can also mount a config file and env file:

docker run -v /my/config.json:/etc/gobookmarks/config.json \
           -v /my/gobookmarks.env:/etc/gobookmarks/gobookmarks.env \
           -p 8080:8080 arran4/gobookmarks

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Oauth2Config *oauth2.Config
	SessionStore sessions.Store
	SessionName  string
)
View Source
var (
	UseCssColumns bool
	Namespace     string
	SiteTitle     string
	GitServer     string
)
View Source
var ErrHandled = errors.New("handled")

ErrHandled is returned by handlers when they have already written a response and no further handlers should run.

View Source
var ErrRepoNotFound = errors.New("repository not found")

ErrRepoNotFound indicates that the bookmarks repository does not exist.

View Source
var (
	FaviconCache = struct {
		sync.RWMutex
		cache map[string]*FavIcon
	}{/* contains filtered or unexported fields */}
)

Functions

func BP added in v1.0.2

func BP(b bool) *bool

func Bookmarks

func Bookmarks(r *http.Request) (string, error)

func BookmarksEditCreateAction

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

func BookmarksEditSaveAction

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

func BookmarksExist added in v1.0.23

func BookmarksExist(r *http.Request) (bool, error)

func CategoryEditSaveAction added in v1.0.16

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

func CoreAdderMiddleware

func CoreAdderMiddleware(next http.Handler) http.Handler

func CreateBookmarks

func CreateBookmarks(ctx context.Context, user string, token *oauth2.Token, branch, text string) error

func DefaultConfigPath added in v1.0.22

func DefaultConfigPath() string

DefaultConfigPath returns the path to the config file depending on environment and the effective user. If running as a non-root user and XDG variables are set, the config lives under the XDG config directory. Otherwise it falls back to /etc/gobookmarks/config.json.

func EditCategoryPage added in v1.0.16

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

func ExtractCategoryByIndex added in v1.0.16

func ExtractCategoryByIndex(bookmarks string, index int) (string, error)

ExtractCategoryByIndex returns the category text for the nth category (0 based)

func FaviconProxyHandler added in v1.0.4

func FaviconProxyHandler(w http.ResponseWriter, r *http.Request)

func GetBookmarks

func GetBookmarks(ctx context.Context, user, ref string, token *oauth2.Token) (string, string, error)

func GetBookmarksRepoName added in v1.0.2

func GetBookmarksRepoName() string

GetBookmarksRepoName returns the repository name based on the current configuration and build mode. When running a development build the name is suffixed with "-dev". The Namespace value is appended if supplied.

func GetCompiledTemplates

func GetCompiledTemplates(funcs template.FuncMap) *template.Template

func GetFavicon

func GetFavicon() []byte

func GetMainCSSData

func GetMainCSSData() []byte

func LoadEnvFile added in v1.0.22

func LoadEnvFile(path string) error

Lines should be in KEY=VALUE format and may be commented with '#'.

func MergeConfig added in v1.0.22

func MergeConfig(dst *Config, src Config)

MergeConfig copies values from src into dst if they are non-zero.

func NewFuncs

func NewFuncs(r *http.Request) template.FuncMap

func Oauth2CallbackPage

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

func ProviderNames added in v1.0.22

func ProviderNames() []string

func RegisterProvider added in v1.0.22

func RegisterProvider(p Provider)

func ReplaceCategoryByIndex added in v1.0.16

func ReplaceCategoryByIndex(bookmarks string, index int, newText string) (string, error)

ReplaceCategoryByIndex replaces the nth category with newText

func SP

func SP(s string) *string

func SetProviderByName added in v1.0.22

func SetProviderByName(name string) bool

SetProviderByName activates the named provider. It returns true if the provider exists.

func SetVersion added in v1.0.6

func SetVersion(pVersion, pCommit, pDate string)

func TaskDoneAutoRefreshPage

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

func UpdateBookmarks

func UpdateBookmarks(ctx context.Context, user string, token *oauth2.Token, sourceRef, branch, text, expectSHA string) error

func UserAdderMiddleware

func UserAdderMiddleware(next http.Handler) http.Handler

func UserLogoutAction

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

Types

type BookmarkBlock added in v1.0.15

type BookmarkBlock struct {
	Columns []*BookmarkColumn
	HR      bool
}

type BookmarkCategory

type BookmarkCategory struct {
	Name    string
	Entries []*BookmarkEntry
	Index   int
}

type BookmarkColumn

type BookmarkColumn struct {
	Categories []*BookmarkCategory
}

type BookmarkEntry

type BookmarkEntry struct {
	Url  string
	Name string
}

type BookmarkPage added in v1.0.15

type BookmarkPage struct {
	Blocks []*BookmarkBlock
}

func PreprocessBookmarks

func PreprocessBookmarks(bookmarks string) []*BookmarkPage

type Branch added in v1.0.22

type Branch struct {
	Name string
}

func GetBranches

func GetBranches(ctx context.Context, user string, token *oauth2.Token) ([]*Branch, error)

type Commit added in v1.0.22

type Commit struct {
	SHA            string
	Message        string
	CommitterName  string
	CommitterEmail string
	CommitterDate  time.Time
}

func GetCommits

func GetCommits(ctx context.Context, user string, token *oauth2.Token) ([]*Commit, error)

type Config added in v1.0.22

type Config struct {
	Oauth2ClientID string `json:"oauth2_client_id"`
	Provider       string `json:"provider"`
	Oauth2Secret   string `json:"oauth2_secret"`
	ExternalURL    string `json:"external_url"`
	CssColumns     bool   `json:"css_columns"`
	Namespace      string `json:"namespace"`
	Title          string `json:"title"`
	GitServer      string `json:"git_server"`
}

Config holds runtime configuration values.

func LoadConfigFile added in v1.0.22

func LoadConfigFile(path string) (Config, error)

LoadConfigFile loads configuration from the given path if it exists.

type Configuration

type Configuration struct {
	// contains filtered or unexported fields
}

func NewConfiguration

func NewConfiguration() *Configuration

TODO use for settings

type ContextValues

type ContextValues string

type CoreData

type CoreData struct {
	Title       string
	AutoRefresh bool
	UserRef     string
}

type FavIcon added in v1.0.9

type FavIcon struct {
	Data        []byte
	ContentType string
}

type GitHubProvider added in v1.0.22

type GitHubProvider struct{}

GitHubProvider implements Provider for GitHub.

func (GitHubProvider) CreateBookmarks added in v1.0.22

func (p GitHubProvider) CreateBookmarks(ctx context.Context, user string, token *oauth2.Token, branch, text string) error

func (GitHubProvider) CreateRepo added in v1.0.23

func (p GitHubProvider) CreateRepo(ctx context.Context, user string, token *oauth2.Token, name string) error

func (GitHubProvider) CurrentUser added in v1.0.22

func (p GitHubProvider) CurrentUser(ctx context.Context, token *oauth2.Token) (*User, error)

func (GitHubProvider) DefaultServer added in v1.0.23

func (GitHubProvider) DefaultServer() string

func (GitHubProvider) GetBookmarks added in v1.0.22

func (p GitHubProvider) GetBookmarks(ctx context.Context, user, ref string, token *oauth2.Token) (string, string, error)

func (GitHubProvider) GetBranches added in v1.0.22

func (p GitHubProvider) GetBranches(ctx context.Context, user string, token *oauth2.Token) ([]*Branch, error)

func (GitHubProvider) GetCommits added in v1.0.22

func (p GitHubProvider) GetCommits(ctx context.Context, user string, token *oauth2.Token) ([]*Commit, error)

func (GitHubProvider) GetTags added in v1.0.22

func (p GitHubProvider) GetTags(ctx context.Context, user string, token *oauth2.Token) ([]*Tag, error)

func (GitHubProvider) Name added in v1.0.22

func (GitHubProvider) Name() string

func (GitHubProvider) OAuth2Config added in v1.0.22

func (GitHubProvider) OAuth2Config(clientID, clientSecret, redirectURL string) *oauth2.Config

func (GitHubProvider) UpdateBookmarks added in v1.0.22

func (p GitHubProvider) UpdateBookmarks(ctx context.Context, user string, token *oauth2.Token, sourceRef, branch, text, expectSHA string) error

type GitLabProvider added in v1.0.22

type GitLabProvider struct{}

GitLabProvider implements Provider for GitLab.

The GitLab server URL can be overridden using the GitServer variable defined in settings.go.

func (GitLabProvider) CreateBookmarks added in v1.0.22

func (GitLabProvider) CreateBookmarks(ctx context.Context, user string, token *oauth2.Token, branch, text string) error

func (GitLabProvider) CreateRepo added in v1.0.23

func (p GitLabProvider) CreateRepo(ctx context.Context, user string, token *oauth2.Token, name string) error

func (GitLabProvider) CurrentUser added in v1.0.22

func (GitLabProvider) CurrentUser(ctx context.Context, token *oauth2.Token) (*User, error)

func (GitLabProvider) DefaultServer added in v1.0.23

func (GitLabProvider) DefaultServer() string

func (GitLabProvider) GetBookmarks added in v1.0.22

func (GitLabProvider) GetBookmarks(ctx context.Context, user, ref string, token *oauth2.Token) (string, string, error)

func (GitLabProvider) GetBranches added in v1.0.22

func (GitLabProvider) GetBranches(ctx context.Context, user string, token *oauth2.Token) ([]*Branch, error)

func (GitLabProvider) GetCommits added in v1.0.22

func (GitLabProvider) GetCommits(ctx context.Context, user string, token *oauth2.Token) ([]*Commit, error)

func (GitLabProvider) GetTags added in v1.0.22

func (GitLabProvider) GetTags(ctx context.Context, user string, token *oauth2.Token) ([]*Tag, error)

func (GitLabProvider) Name added in v1.0.22

func (GitLabProvider) Name() string

func (GitLabProvider) OAuth2Config added in v1.0.22

func (GitLabProvider) OAuth2Config(clientID, clientSecret, redirectURL string) *oauth2.Config

func (GitLabProvider) UpdateBookmarks added in v1.0.22

func (GitLabProvider) UpdateBookmarks(ctx context.Context, user string, token *oauth2.Token, sourceRef, branch, text, expectSHA string) error

type Provider added in v1.0.22

type Provider interface {
	Name() string
	OAuth2Config(clientID, clientSecret, redirectURL string) *oauth2.Config
	CurrentUser(ctx context.Context, token *oauth2.Token) (*User, error)
	GetTags(ctx context.Context, user string, token *oauth2.Token) ([]*Tag, error)
	GetBranches(ctx context.Context, user string, token *oauth2.Token) ([]*Branch, error)
	GetCommits(ctx context.Context, user string, token *oauth2.Token) ([]*Commit, error)
	GetBookmarks(ctx context.Context, user, ref string, token *oauth2.Token) (string, string, error)
	UpdateBookmarks(ctx context.Context, user string, token *oauth2.Token, sourceRef, branch, text, expectSHA string) error
	CreateBookmarks(ctx context.Context, user string, token *oauth2.Token, branch, text string) error
	CreateRepo(ctx context.Context, user string, token *oauth2.Token, name string) error
	DefaultServer() string
}
var ActiveProvider Provider

func GetProvider added in v1.0.22

func GetProvider(name string) Provider

type Tag added in v1.0.22

type Tag struct {
	Name string
}

func GetTags

func GetTags(ctx context.Context, user string, token *oauth2.Token) ([]*Tag, error)

type User added in v1.0.22

type User struct {
	Login string
}

Directories

Path Synopsis
cmd
gobookmarks command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL