basic UDP server bound to an interface

This commit is contained in:
2023-05-02 09:27:27 -07:00
parent cb8e6c031c
commit 073dbac4bb
10 changed files with 264 additions and 9 deletions

View File

@@ -6,8 +6,10 @@ go_library(
importpath = "git.wntrmute.dev/kyle/kdhcp/cmd/kdhcpd",
visibility = ["//visibility:private"],
deps = [
"//config",
"//log",
"//server",
"@com_github_peterbourgon_ff_v3//ffcli",
],
)

View File

@@ -4,19 +4,25 @@ import (
"context"
"flag"
"os"
"strings"
"git.wntrmute.dev/kyle/kdhcp/bazel-kdhcp/external/com_github_davecgh_go_spew/spew"
"git.wntrmute.dev/kyle/kdhcp/config"
"git.wntrmute.dev/kyle/kdhcp/log"
"git.wntrmute.dev/kyle/kdhcp/server"
"github.com/peterbourgon/ff/v3/ffcli"
)
func main() {
var configPath string
logLevel := "DEBUG"
flag.StringVar(&configPath, "f", "kdhcpd.yaml", "path to `config file`")
flag.StringVar(&configPath, "f", "", "path to `config file`")
flag.StringVar(&logLevel, "l", logLevel, "log level")
flag.Parse()
logLevel = strings.ToUpper(logLevel)
log.Setup(logLevel, "kdhcpd")
root := &ffcli.Command{
Exec: func(ctx context.Context, args []string) error {
cfg, err := config.Load(configPath)
@@ -24,8 +30,15 @@ func main() {
log.Fatal(err)
}
log.Debugf("read configuration file with version=%d", cfg.Version)
spew.Dump(*cfg)
srv, err := server.New(cfg)
if err != nil {
log.Fatal(err)
}
defer srv.Close()
srv.Listen()
return nil
},
}