env

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package env provides paths on different platforms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllDirs added in v0.1.2

func AllDirs(dir ...string) ([]string, error)

AllDirs returns all (unique) directories for the environment.

func AppPath

func AppPath(opt ...PathOption) (string, error)

AppPath returns where to store app (data) files.

Darwin: ~/Library/Application Support Windows: %LOCALAPPDATA% (~/AppData/Local) Linux: ~/.local/share

darwin: env.AppPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "~/Library/Application Support/MyApp/test.txt"

windows: env.AppPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "%LOCALAPPDATA%/MyApp/test.txt"

linux: env.AppPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "~/.local/share/MyApp/test.txt"

func ConfigPath added in v0.1.2

func ConfigPath(opt ...PathOption) (string, error)

ConfigPath returns where to store config files.

Darwin: ~/Library/Application Support Windows: %APPDATA% (~/AppData/Roaming) Linux: ~/.config

darwin: env.ConfigPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "~/Library/Application Support/MyApp/test.txt"

windows: env.ConfigPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "%APPDATA%/MyApp/test.txt"

linux: env.ConfigPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "~/.config/MyApp/test.txt"

func HomeDir

func HomeDir() (string, error)

HomeDir returns current user home directory. On linux, when running an AppImage, HomeDir can be empty string.

func LogsPath

func LogsPath(opt ...PathOption) (string, error)

LogsPath returns directory for log files.

Darwin: ~/Library/Logs Windows: %LOCALAPPDATA% (~/AppData/Local) Linux: ~/.cache

darwin: env.AppPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "~/Library/Application Support/MyApp/test.txt"

windows: env.AppPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "%LOCALAPPDATA%/MyApp/test.txt"

linux: env.AppPath(env.Dir("MyApp"), env.File("test.txt"), env.Mkdir())

=> "~/.cache/MyApp/test.txt"

func MustAppPath

func MustAppPath(opt ...PathOption) string

MustAppPath returns AppPath or panics.

func MustHomeDir added in v0.1.2

func MustHomeDir() string

MustHomeDir returns current user home directory.

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if path exists.

Types

type PathOption

type PathOption func(*PathOptions) error

PathOption ...

func Dir

func Dir(dirs ...string) PathOption

Dir ...

func File

func File(file string) PathOption

File ...

func Mkdir

func Mkdir() PathOption

Mkdir ...

type PathOptions

type PathOptions struct {
	Dirs  []string
	File  string
	Mkdir bool
}

PathOptions ...

Jump to

Keyboard shortcuts

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