From 51f28a6397a73ef11d2e723ecd505697d4608ca5 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Thu, 19 Sep 2024 15:51:46 +0300 Subject: [PATCH] fixed path resolution --- src/gui.go | 2 +- src/owncast.go | 5 +++-- src/server.go | 16 ++++++++++++++-- src/twitch.go | 5 +++-- webroot/index.html | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/gui.go b/src/gui.go index 8f0ea98..def1685 100644 --- a/src/gui.go +++ b/src/gui.go @@ -25,7 +25,7 @@ func init() { bro := webview.New(debug) /* create a browser instance */ bro.SetSize(320, 720, webview.HintNone) defer bro.Destroy() - bro.SetTitle("StreamGoose v0.0.1") + bro.SetTitle("StreamGoose") bro.Navigate("http://" + target_addr) bro.Run() } diff --git a/src/owncast.go b/src/owncast.go index 3ec407c..e688d3c 100644 --- a/src/owncast.go +++ b/src/owncast.go @@ -15,6 +15,7 @@ import ( "encoding/json" "net/http" "io/ioutil" + "path/filepath" ) /* global API root URL placeholder */ @@ -124,11 +125,11 @@ func oc_process_message(rawmsg map[string]interface{}) { /* entry point */ func owncast_run(config map[string]interface{}) { - token_path := "auth/oc-token.txt" + token_path := filepath.Join(APP_ROOT_DIR, "auth", "oc-token.txt") token, err := ioutil.ReadFile(token_path) token_err_msg := "[owncast] No Owncast token file provided or it is empty. " token_err_msg += "Please generate a token in your Owncast admin panel " - token_err_msg += "and paste it into the auth/oc-token.txt file!" + token_err_msg += "and paste it into the " + token_path + " file!" if err != nil { log.Fatal(token_err_msg + "\nDetailed error: ", err) } diff --git a/src/server.go b/src/server.go index 29bf646..d4196a2 100644 --- a/src/server.go +++ b/src/server.go @@ -15,6 +15,7 @@ import ( "encoding/json" "net/http" "io/ioutil" + "path/filepath" ) /* main chat message structure */ @@ -30,6 +31,7 @@ type ChatMessage struct { var global_msg_id uint64 = 0 /* track global message ID */ var message_transport chan ChatMessage /* global message channel */ var sse_transports []chan string /* SSE output channels */ +var APP_ROOT_DIR string /* global application root directory */ /* headless behaviour by default */ var goose_start_gui = func(config map[string]interface{}) { @@ -130,7 +132,17 @@ func sseHandler(w http.ResponseWriter, r *http.Request) { /* entry point */ func main() { - config_path := "config.json" + /* detect current executable directory and load the config from there */ + ex, err := os.Executable() + if err != nil { + panic(err) + } + ex, err = filepath.EvalSymlinks(ex) + if err != nil { + panic(err) + } + APP_ROOT_DIR = filepath.Dir(ex) + config_path := filepath.Join(APP_ROOT_DIR, "config.json") if len(os.Args) > 1 { config_path = os.Args[1] } @@ -158,7 +170,7 @@ func main() { /* serve the GET /sse */ http.HandleFunc("/sse", sseHandler) /* serve the webroot directory */ - fs := http.FileServer(http.Dir("./webroot")) + fs := http.FileServer(http.Dir(filepath.Join(APP_ROOT_DIR, "webroot"))) http.Handle("/", fs) log.Println(fmt.Sprintf("Listening on %s\n", target_addr)) err = http.ListenAndServe(target_addr, nil) diff --git a/src/twitch.go b/src/twitch.go index 5845c3e..e5e526a 100644 --- a/src/twitch.go +++ b/src/twitch.go @@ -14,6 +14,7 @@ import ( "time" "net" "io/ioutil" + "path/filepath" "unicode/utf8" ) @@ -143,11 +144,11 @@ func tw_process_message(rawmsg string) { /* entry point */ func twitch_run(config map[string]interface{}) { - token_path := "auth/twitch-token.txt" + token_path := filepath.Join(APP_ROOT_DIR, "auth", "twitch-token.txt") token, err := ioutil.ReadFile(token_path) token_err_msg := "[twitch] No Twitch token file provided or it is empty. " token_err_msg += "Please visit https://twitchapps.com/tmi/, generate a token there " - token_err_msg += "and paste it into the auth/twitch-token.txt file!" + token_err_msg += "and paste it into the " + token_path +" file!" if err != nil { log.Fatal(token_err_msg + "\nDetailed error: ", err) } diff --git a/webroot/index.html b/webroot/index.html index 045bd55..e6258a5 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -2,7 +2,7 @@ - StreamGoose v0.0.1 + StreamGoose