実行中のバイナリの絶対パスをもとにcute-ostrich.txtを取得するようにした

This commit is contained in:
Haruki
2023-08-25 09:46:44 +09:00
parent 67b1301896
commit 0b9bdba022
2 changed files with 24 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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())