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.toml
serveg /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"` Ip IP `toml:"ip"`
} }
var ConfigPath = "serveg.toml"
func ReadConfig(path string) (*Config, error) { func ReadConfig(path string) (*Config, error) {
var config = new(Config) var config = new(Config)
tomlMeta, err := toml.DecodeFile(path, config) tomlMeta, err := toml.DecodeFile(path, config)
@@ -40,13 +38,13 @@ func DefaultConfig() *Config {
} }
} }
func ParseOrCreateDefault() (*Config, error) { func ParseOrCreateDefault(path string) (*Config, error) {
config, err := ReadConfig(ConfigPath) config, err := ReadConfig(path)
if !errors.Is(err, fs.ErrNotExist) { if !errors.Is(err, fs.ErrNotExist) {
return config, err // either a parsed config, or a real error return config, err // either a parsed config, or a real error
} }
config = DefaultConfig() config = DefaultConfig()
return config, WriteConfig(config, ConfigPath) return config, WriteConfig(config, path)
} }
func WriteConfig(config *Config, path string) (err error) { func WriteConfig(config *Config, path string) (err error) {
+6 -2
View File
@@ -2,10 +2,11 @@ package main
import ( import (
"context" "context"
"flag"
"net" "net"
"os" "os"
"os/signal" "os/signal"
"serveg/common/log" "serveg/internal/log"
"strconv" "strconv"
"syscall" "syscall"
"time" "time"
@@ -24,7 +25,10 @@ func run() int {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
//defer stop() //defer stop()
conf, err := ParseOrCreateDefault() configPath := *flag.String("config", "serveg.toml", "path to config file")
flag.Parse()
conf, err := ParseOrCreateDefault(configPath)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
return 1 return 1