Add basic library code to manage projects, activities and times.
This commit is contained in:
parent
529efb3668
commit
fb576f3d51
7 changed files with 663 additions and 0 deletions
39
lib/common.go
Normal file
39
lib/common.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Package lib provides routines for creating and reading data files as defined by the specification.
|
||||
package lib
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// dataDir holds the configured directory to read/write data from/to.
|
||||
var dataDir string
|
||||
|
||||
// SetDataDir sets the global directory to read/write data from/to. It is typically called once at application start.
|
||||
func SetDataDir(directory string) {
|
||||
dataDir = directory
|
||||
}
|
||||
|
||||
// getDataDir gets the global directory to read/write data from/to for a schema entity.
|
||||
func getDataDir(entity string) (string, error) {
|
||||
if dataDir != "" {
|
||||
return filepath.Join(dataDir, entity), nil
|
||||
}
|
||||
|
||||
home, homeErr := os.UserHomeDir()
|
||||
if homeErr != nil {
|
||||
return "", homeErr
|
||||
}
|
||||
|
||||
return filepath.Join(home, ".protime", entity), nil
|
||||
}
|
||||
|
||||
// newUUID creates a new UUID for an entity instance using the OS command `uuidgen`.
|
||||
func newUUID() (string, error) {
|
||||
out, err := exec.Command("uuidgen").Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(out[:len(out)-1]), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue