diff --git a/.gitignore b/.gitignore index f769868..0a7fba8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -serveg.toml -serveg +/serveg.toml +/serveg +bin/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ffaea61 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "serveg", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}/cmd/serveg", + "cwd": "${workspaceFolder}/bin" + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8f2c771 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +build: + go build -trimpath -ldflags="-s -w" -o bin/ ./cmd/serveg + ls -lh bin + +run: build + cd bin && ./serveg + +clean: + rm -rf bin diff --git a/Config.go b/cmd/serveg/Config.go similarity index 89% rename from Config.go rename to cmd/serveg/Config.go index 56bd2e9..c60db5b 100644 --- a/Config.go +++ b/cmd/serveg/Config.go @@ -16,8 +16,6 @@ type Config struct { Ip IP `toml:"ip"` } -var ConfigPath = "serveg.toml" - func ReadConfig(path string) (*Config, error) { var config = new(Config) tomlMeta, err := toml.DecodeFile(path, config) @@ -40,13 +38,13 @@ func DefaultConfig() *Config { } } -func ParseOrCreateDefault() (*Config, error) { - config, err := ReadConfig(ConfigPath) +func ParseOrCreateDefault(path string) (*Config, error) { + config, err := ReadConfig(path) if !errors.Is(err, fs.ErrNotExist) { return config, err // either a parsed config, or a real error } config = DefaultConfig() - return config, WriteConfig(config, ConfigPath) + return config, WriteConfig(config, path) } func WriteConfig(config *Config, path string) (err error) { diff --git a/main.go b/cmd/serveg/main.go similarity index 91% rename from main.go rename to cmd/serveg/main.go index 46daec2..989bd31 100644 --- a/main.go +++ b/cmd/serveg/main.go @@ -2,10 +2,11 @@ package main import ( "context" + "flag" "net" "os" "os/signal" - "serveg/common/log" + "serveg/internal/log" "strconv" "syscall" "time" @@ -24,7 +25,10 @@ func run() int { ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) //defer stop() - conf, err := ParseOrCreateDefault() + configPath := *flag.String("config", "serveg.toml", "path to config file") + flag.Parse() + + conf, err := ParseOrCreateDefault(configPath) if err != nil { logger.Error(err) return 1 diff --git a/common/log/ConsoleColor.go b/internal/log/ConsoleColor.go similarity index 100% rename from common/log/ConsoleColor.go rename to internal/log/ConsoleColor.go diff --git a/common/log/log.go b/internal/log/log.go similarity index 100% rename from common/log/log.go rename to internal/log/log.go