changed project structure

This commit is contained in:
Altair-sh
2026-10-29 18:43:35 +01:00
parent ec1275db24
commit f6818cc59a
7 changed files with 34 additions and 9 deletions
+3 -2
View File
@@ -1,2 +1,3 @@
serveg.toml
serveg
/serveg.toml
/serveg
bin/
+13
View File
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "serveg",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/serveg",
"cwd": "${workspaceFolder}/bin"
}
]
}
+9
View File
@@ -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
+3 -5
View File
@@ -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) {
+6 -2
View File
@@ -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