Zarthus / appdir

Small go-lang helper library for where to place stuff, OS-agnostic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

app directories

MIT License Go Reference

Small helper library to help you locate useful directories based on the following resources:

Add it to your project

go get github.com/zarthus/appdir

Description

API:

GetApplicationDirectory(); // not for linux (presently)
GetUserConfigDirectory();

Example:

package main

import (
	"github.com/zarthus/appdir"
	"path/filepath"
	"os"
)

func main() {
	dir, _ := appdir.GetUserConfigDirectory() // TODO error handling
	apppath := filepath.Join(dir, "myapp")
	_ = os.MkdirAll(apppath, 0750)
	_ = os.WriteFile(filepath.Join(apppath, "config.json"), []byte("{\"foo\": true}"), 0644)
	
	// on linux, this would for example create `~/.config/myapp/config.json` with `{"foo": true}`
}

About

Small go-lang helper library for where to place stuff, OS-agnostic

License:MIT License


Languages

Language:Go 100.0%