changed project structure
This commit is contained in:
+3
-2
@@ -1,2 +1,3 @@
|
||||
serveg.toml
|
||||
serveg
|
||||
/serveg.toml
|
||||
/serveg
|
||||
bin/
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "serveg",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"program": "${workspaceFolder}/cmd/serveg",
|
||||
"cwd": "${workspaceFolder}/bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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
|
||||
@@ -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) {
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user