-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
35 lines (28 loc) · 824 Bytes
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"errors"
"path/filepath"
"runtime"
)
const DEFAULT_CONFIG_FOLDER_NAME = ".adr"
const DEFAULT_CONFIG_FILE_NAME = "config.json"
const DEFAULT_TEMPLATE_FILE_NAME = "template.md"
var configFolderPath = filepath.Join(getWorkDir(), DEFAULT_CONFIG_FOLDER_NAME)
var configFilePath = filepath.Join(configFolderPath, DEFAULT_CONFIG_FILE_NAME)
var templateFilePath = filepath.Join(configFolderPath, DEFAULT_TEMPLATE_FILE_NAME)
// Filename is the __filename equivalent
func Filename() (string, error) {
_, filename, _, ok := runtime.Caller(1)
if !ok {
return "", errors.New("unable to get the current filename")
}
return filename, nil
}
// Dirname is the __dirname equivalent
func getWorkDir() string {
filename, err := Filename()
if err != nil {
panic(err)
}
return filepath.Dir(filename)
}