diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-29 02:33:10 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-29 06:11:47 +0900 |
| commit | 46cd3a28c83e93b5d66c52d06a8366c11910d5c0 (patch) | |
| tree | 6e25c5078b5cd9de78b7a6c9b253f1132358812b /internal/path.go | |
| parent | ad1bc6794f0053c3e63eab408a0d530d53e8b51c (diff) | |
container: remove global msg
This frees all container instances of side effects.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/path.go')
| -rw-r--r-- | internal/path.go | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/internal/path.go b/internal/path.go index 81af5a20..fca0fdf0 100644 --- a/internal/path.go +++ b/internal/path.go @@ -2,9 +2,8 @@ package internal import ( "log" - "path" - "hakurei.app/internal/hlog" + "hakurei.app/container" ) var ( @@ -12,22 +11,23 @@ var ( hsu = compPoison ) -func MustHakureiPath() string { - if name, ok := checkPath(hmain); ok { - return name - } - hlog.BeforeExit() - log.Fatal("invalid hakurei path, this program is compiled incorrectly") - return compPoison // unreachable -} +// MustHakureiPath returns the absolute path to hakurei, configured at compile time. +func MustHakureiPath() *container.Absolute { return mustCheckPath(log.Fatal, "hakurei", hmain) } -func MustHsuPath() string { - if name, ok := checkPath(hsu); ok { - return name +// MustHsuPath returns the absolute path to hakurei, configured at compile time. +func MustHsuPath() *container.Absolute { return mustCheckPath(log.Fatal, "hsu", hsu) } + +// mustCheckPath checks a pathname against compPoison, then [container.NewAbs], calling fatal if either step fails. +func mustCheckPath(fatal func(v ...any), name, pathname string) *container.Absolute { + if pathname != compPoison && pathname != "" { + if a, err := container.NewAbs(pathname); err != nil { + fatal(err.Error()) + return nil // unreachable + } else { + return a + } + } else { + fatal("invalid " + name + " path, this program is compiled incorrectly") + return nil // unreachable } - hlog.BeforeExit() - log.Fatal("invalid hsu path, this program is compiled incorrectly") - return compPoison // unreachable } - -func checkPath(p string) (string, bool) { return p, p != compPoison && p != "" && path.IsAbs(p) } |
