init
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// Package paths resolves platform-specific application directories.
|
||||
//
|
||||
// Layout follows each platform's conventions. On macOS:
|
||||
//
|
||||
// ~/Library/Application Support/com.lmvpn.client/ user data, db, config
|
||||
// ~/Library/Caches/com.lmvpn.client/ caches
|
||||
// ~/Library/Logs/com.lmvpn.client/ logs
|
||||
package paths
|
||||
|
||||
import "os"
|
||||
|
||||
// BundleID is the application bundle identifier used as the per-app
|
||||
// subdirectory name under the platform library folders.
|
||||
const BundleID = "com.lmvpn.client"
|
||||
|
||||
// AppName is the human-readable application name.
|
||||
const AppName = "LMVPN"
|
||||
|
||||
// Dirs describes the resolved application directories.
|
||||
type Dirs struct {
|
||||
Data string // persistent user data (db, config)
|
||||
Cache string // recreatable caches
|
||||
Log string // log files
|
||||
}
|
||||
|
||||
// Paths is the resolved directory set for the current platform.
|
||||
var Paths Dirs
|
||||
|
||||
// EnsureDirs creates the application directories if they do not exist.
|
||||
func EnsureDirs() error {
|
||||
for _, d := range []string{Paths.Data, Paths.Cache, Paths.Log} {
|
||||
if err := os.MkdirAll(d, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DBPath returns the path to the SQLite database file.
|
||||
func DBPath() string { return Paths.Data + "/lmvpn.db" }
|
||||
|
||||
// ConfigPath returns the path to the application config file.
|
||||
func ConfigPath() string { return Paths.Data + "/config.yml" }
|
||||
|
||||
// LogFile returns the path to the GUI log file.
|
||||
func LogFile() string { return Paths.Log + "/lmvpn.log" }
|
||||
|
||||
// DaemonLogFile returns the path to the daemon log file.
|
||||
func DaemonLogFile() string { return Paths.Log + "/lmvpn-daemon.log" }
|
||||
|
||||
// IPCSocketPath returns the path to the unix domain socket used for
|
||||
// GUI <-> daemon communication.
|
||||
func IPCSocketPath() string { return "/tmp/lmvpn.sock" }
|
||||
@@ -0,0 +1,18 @@
|
||||
//go:build darwin
|
||||
|
||||
package paths
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func init() {
|
||||
home, _ := os.UserHomeDir()
|
||||
lib := filepath.Join(home, "Library")
|
||||
Paths = Dirs{
|
||||
Data: filepath.Join(lib, "Application Support", BundleID),
|
||||
Cache: filepath.Join(lib, "Caches", BundleID),
|
||||
Log: filepath.Join(lib, "Logs", BundleID),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//go:build !darwin
|
||||
|
||||
package paths
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func init() {
|
||||
home, _ := os.UserHomeDir()
|
||||
Paths = Dirs{
|
||||
Data: filepath.Join(home, ".local", "share", BundleID),
|
||||
Cache: filepath.Join(home, ".cache", BundleID),
|
||||
Log: filepath.Join(home, ".local", "state", BundleID, "log"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user