feat(main.go): actually detect instance path
This commit is contained in:
parent
1a8a0896aa
commit
ff2ade5e84
1 changed files with 25 additions and 1 deletions
26
main.go
26
main.go
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
running := true
|
running := true
|
||||||
instance_path, err := filepath.Abs("/home/pauljako/boundaries")
|
instance_path, err := get_instance_path()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -80,3 +80,27 @@ func accept_clients(ln *net.Listener, instance *string, running *bool) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func get_instance_path() (string, error) {
|
||||||
|
if len(os.Args) == 2 {
|
||||||
|
return filepath.Abs(os.Args[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
// When bndd has been started by boundaries, this can be used to get the instance it used
|
||||||
|
app_dir, has := os.LookupEnv("APP_DIR")
|
||||||
|
if has {
|
||||||
|
return filepath.Abs(filepath.Join(app_dir, "..", ".."))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to the user-path
|
||||||
|
home, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
home_instance_path, err := filepath.Abs(filepath.Join(home, "boundaries"))
|
||||||
|
if exists, err := exists(home_instance_path); exists && err == nil {
|
||||||
|
return home_instance_path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", errors.New("no suitable instance path found")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue