From 0b9bdba0225e86002e4dbcc78f62e69b80e062c0 Mon Sep 17 00:00:00 2001 From: Haruki Date: Fri, 25 Aug 2023 09:46:44 +0900 Subject: [PATCH] =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E4=B8=AD=E3=81=AE=E3=83=90?= =?UTF-8?q?=E3=82=A4=E3=83=8A=E3=83=AA=E3=81=AE=E7=B5=B6=E5=AF=BE=E3=83=91?= =?UTF-8?q?=E3=82=B9=E3=82=92=E3=82=82=E3=81=A8=E3=81=ABcute-ostrich.txt?= =?UTF-8?q?=E3=82=92=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nostrh/cmd/paths/paths.go | 12 ++++++++++++ nostrh/main.go | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/nostrh/cmd/paths/paths.go b/nostrh/cmd/paths/paths.go index de52894..4c400ef 100644 --- a/nostrh/cmd/paths/paths.go +++ b/nostrh/cmd/paths/paths.go @@ -26,3 +26,15 @@ func GetSettingsDirectory() (string, error) { return dirPath, nil } + +func GetProjectRootDirectory() (string, error) { + // 実行中のバイナリの絶対パスを取得 + exePath, err := os.Executable() + if err != nil { + return "", err + } + + // ディレクトリパスを取得 + dir := filepath.Dir(exePath) + return dir, nil +} diff --git a/nostrh/main.go b/nostrh/main.go index af535fc..e7f9a70 100644 --- a/nostrh/main.go +++ b/nostrh/main.go @@ -4,15 +4,19 @@ import ( "bytes" "fmt" "os" + "path/filepath" "github.com/nbd-wtf/go-nostr" "github.com/studiokaiji/nostr-webhost/nostrh/cmd/deploy" "github.com/studiokaiji/nostr-webhost/nostrh/cmd/keystore" + "github.com/studiokaiji/nostr-webhost/nostrh/cmd/paths" "github.com/studiokaiji/nostr-webhost/nostrh/cmd/relays" "github.com/studiokaiji/nostr-webhost/nostrh/cmd/server" "github.com/urfave/cli/v2" ) +const cuteOstrichFileName = "cute-ostrich.txt" + func main() { var ( port string @@ -136,7 +140,13 @@ func main() { if len(os.Args) < 2 || os.Args[1] == "help" || os.Args[1] == "h" { // Display ostrich - file, err := os.Open("./cute-ostrich.txt") + projectDir, err := paths.GetProjectRootDirectory() + if err != nil { + fmt.Println(err) + } + + filePath := filepath.Join(projectDir, cuteOstrichFileName) + file, err := os.Open(filePath) if err != nil { fmt.Println(err) } @@ -149,7 +159,7 @@ func main() { break } if err != nil { - panic(err) + break } fmt.Println(buf.String())