Skip to content

Commit fb6b9c8

Browse files
author
dsokolyuk
committed
goreleaser
1 parent 4d5e804 commit fb6b9c8

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ builds:
66
- CGO_ENABLED=1
77
goos:
88
- windows
9+
- linux
910
goarch:
1011
- amd64
1112
nfpms:

cfg/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import (
99
"strings"
1010
)
1111

12+
func Exists(filePath string) bool {
13+
if _, err := os.Stat(filePath); os.IsNotExist(err) {
14+
return false
15+
}
16+
17+
return true
18+
}
19+
1220
func Load(filePath string) (*Config, error) {
1321
file, err := os.Open(filePath)
1422
if err != nil {

main.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package main
22

33
import (
4+
_ "embed"
45
"fmt"
56
"log"
67
"log/slog"
78
"net"
89
"net/http"
10+
_ "net/http/pprof"
911
"os"
1012
"os/exec"
11-
12-
_ "net/http/pprof"
13+
"path"
1314

1415
"github.com/DaniilSokolyuk/go-pcap2socks/cfg"
1516
"github.com/DaniilSokolyuk/go-pcap2socks/core"
@@ -19,13 +20,33 @@ import (
1920
"gvisor.dev/gvisor/pkg/tcpip/stack"
2021
)
2122

23+
//go:embed config.json
24+
var configData string
25+
2226
func main() {
2327
// get config file from first argument or use config.json
2428
var cfgFile string
2529
if len(os.Args) > 1 {
2630
cfgFile = os.Args[1]
2731
} else {
28-
cfgFile = "config.json"
32+
executable, err := os.Executable()
33+
if err != nil {
34+
slog.Error("get executable error", "error", err)
35+
return
36+
}
37+
38+
cfgFile = path.Join(path.Dir(executable), "config.json")
39+
}
40+
41+
cfgExists := cfg.Exists(cfgFile)
42+
if !cfgExists {
43+
slog.Info("Config file not found, creating a new one", "file", cfgFile)
44+
//path to near executable file
45+
err := os.WriteFile(cfgFile, []byte(configData), 0666)
46+
if err != nil {
47+
slog.Error("write config error", "file", cfgFile, "error", err)
48+
return
49+
}
2950
}
3051

3152
config, err := cfg.Load(cfgFile)

0 commit comments

Comments
 (0)