Skip to content

Commit 43b8187

Browse files
committed
improve relative path handling
1 parent 9eb50ff commit 43b8187

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

config.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"log"
66
"os"
7-
"path/filepath"
87

98
"gopkg.in/yaml.v3"
109
)
@@ -67,13 +66,3 @@ func load(file string) (config config) {
6766

6867
return
6968
}
70-
71-
func relativePath(p string) string {
72-
ex, err := os.Executable()
73-
if err != nil {
74-
panic(err)
75-
}
76-
path := filepath.Dir(ex)
77-
78-
return fmt.Sprintf("%s/%s", path, p)
79-
}

gotv.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"log"
67
"os"
8+
"path/filepath"
79
)
810

911
type GoTv []Channel
@@ -16,8 +18,8 @@ type Channel struct {
1618
}
1719

1820
func main() {
19-
configFile := flag.String("config", relativePath("config.yml"), "config file to read configuration from")
20-
m3uFile := flag.String("m3u", relativePath("gotv.m3u"), "m3u file to save a new playlist into")
21+
configFile := flag.String("config", relPath("config.yml"), "config file to read configuration from")
22+
m3uFile := flag.String("m3u", relPath("gotv.m3u"), "m3u file to save a new playlist into")
2123
flag.Parse()
2224

2325
config := load(*configFile)
@@ -29,3 +31,12 @@ func main() {
2931

3032
os.Exit(0)
3133
}
34+
35+
func relPath(p string) string {
36+
ex, err := os.Executable()
37+
if err != nil {
38+
log.Fatal(err)
39+
}
40+
41+
return filepath.Join(filepath.Dir(ex), p)
42+
}

0 commit comments

Comments
 (0)