appdir

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 2 Imported by: 0

README

go-appdir

GoDoc

Minimalistic Go package to get application directories such as config and cache.

Platform Windows Linux/BSDs macOS
User-specific config %APPDATA% (C:\Users\%USERNAME%\AppData\Roaming) $XDG_CONFIG_HOME ($HOME/.config) $HOME/Library/Application Support
User-specific cache %LOCALAPPDATA% (C:\Users\%USERNAME%\AppData\Local) $XDG_CACHE_HOME ($HOME/.cache) $HOME/Library/Caches
User-specific data %LOCALAPPDATA% (C:\Users\%USERNAME%\AppData\Local) $XDG_DATA_HOME ($HOME/.local/share) $HOME/Library/Application Support
User-specific logs %LOCALAPPDATA% (C:\Users\%USERNAME%\AppData\Local) $XDG_CACHE_HOME/<name>/logs $HOME/Library/Logs

Inspired by configdir.

Usage

package main

import (
	"os"
	"path/filepath"

	"github.com/ProtonMail/go-appdir"
)

func main() {
	// Get directories for our app
	dirs := appdir.New("my-awesome-app")

	// Get user-specific config dir
	p := dirs.UserConfig()

	// Create our app config dir
	if err := os.MkdirAll(p, 0755); err != nil {
		panic(err)
	}

	// Now we can use it
	f, err := os.Create(filepath.Join(p, "config-file"))
	if err != nil {
		panic(err)
	}
	defer f.Close()

	f.Write([]byte("<3"))
}

License

MIT

Documentation

Overview

Get application directories such as config and cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dirs

type Dirs interface {
	// Get the user-specific config directory.
	UserConfig() string
	// Get the user-specific cache directory.
	UserCache() string
	// Get the user-specific logs directory.
	UserLogs() string
	// Get the user-specific data directory.
	UserData() string
}

Dirs requests application directories paths.

func New

func New(name string) Dirs

New creates a new App with the provided name.

Jump to

Keyboard shortcuts

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