directories

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Directories

Helper cross-platform Golang library to retrieve commonly used directories.

The library tries to get directory names using platform specific API instead of relying, for e.g., in environment variables that might not be present.

Usage

import "github.com/randlabs/directories"
dir, err := GetHomeDirectory()
if err == nil {
	fmt.Printf("Home directory: %v\n", dir)
} 

License

See LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	Home           Location = 1
	AppSettings             = 2
	SystemSettings          = 3
)

Variables

This section is empty.

Functions

func BuildFilename added in v1.0.1

func BuildFilename(location Location, name string) (string, error)

BuildFilename returns the complete file name using the desired location as a base.

func GetAppSettingsDirectory

func GetAppSettingsDirectory() (string, error)

GetAppSettingsDirectory gets the directory to save local app settings. Should be used for non system-wide applications.

func GetHomeDirectory

func GetHomeDirectory() (string, error)

GetHomeDirectory gets the user's home directory

func GetSystemSettingsDirectory

func GetSystemSettingsDirectory() (string, error)

GetSystemSettingsDirectory gets the directory to save app settings. Should be used for system-wide applications.

func Open added in v1.0.1

func Open(location Location, name string, flag int, perm os.FileMode) (*os.File, error)

Open is a shortcut to open and/or create a file under the desired location.

func SetAppName added in v1.0.1

func SetAppName(name string)

SetAppName sets the name of the current application. GetAppSettingsDirectory and GetSystemSettingsDirectory appends the application name automatically to the returned string.

Types

type Location added in v1.0.1

type Location int

Jump to

Keyboard shortcuts

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