holonet
- 19 commits
- 1 branch
- 0 tags
- updated
wip: capture env vars, init http server
SignedGitea couldn't verify the signature.
Showing 12 changed files with 167 additions and 38 deletions.
.air.tomladded
+24 −0
@@ -0,0 +1,24 @@1config_file_path = ""23[build]4 bin = "./tmp/main"5 cmd = "go build -o ./tmp/main ./cmd/holonet/"6 delay = 10007 exclude_file = []8 exclude_dir = ["tmp", "bin"]9 exclude_regex = []10 ignore = ["_test.go"]11 send_before = false12 stop_on_error = false1314[log]15 time = false1617[color]18 main = "magenta"19 runner = "yellow"20 build = "red"21 app = "green"2223[misc]24 clean_on_exit = true
.gitignore
+4 −2
@@ -34,5 +34,7 @@ go.work.sum3434# temp3535tmp363637# project binary38holonet37# project specific38# holonet39docs40bin
CHANGELOG.mddeleted
+0 −13
@@ -1,13 +0,0 @@1# Changelog23All notable changes to this project will be documented in this file.45The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).78## [Unreleased]910### Added1112- Env config with validation and defaults, structured logging13- Dev tooling: `just check` (format, lint, test)
cmd/holonet/main.goadded
+16 −0
@@ -0,0 +1,16 @@1package main23import (4 "git.danieldaum.net/daniel-daum/holonet/internal/config"56 "fmt"7)89func main() {1011 settings := config.LoadSettings()1213 fmt.Printf("HOST IS SET: %s\n", settings.HOST)14 fmt.Printf("PORT IS SET: %s\n", settings.PORT)15 fmt.Printf("ENV IS SET: %s\n", settings.ENV)16}
dockerfileadded
+12 −0
@@ -0,0 +1,12 @@1FROM golang:1.27.123WORKDIR /usr/src/app45# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change6COPY go.mod go.sum ./7RUN go mod download89COPY . .10RUN go build -v -o /usr/local/bin/app ./...1112CMD ["app"]
hello_test.godeleted
+0 −12
@@ -1,12 +0,0 @@1package main23import "testing"45func TestHello(t *testing.T) {6 got := Hello()7 want := "hello world!"89 if got != want {10 t.Errorf("got %q want %q", got, want)11 }12}
internal/config/config.goadded
+40 −0
@@ -0,0 +1,40 @@1package config23import (4 "fmt"5 "os"6)78type Settings struct {9 HOST string10 PORT string11 ENV string12}1314func LoadSettings() Settings {15 // HOST16 host, exists := os.LookupEnv("HOST")1718 if !exists {19 fmt.Println("Host was not provided, defaulting to 0.0.0.0")20 host = "0.0.0.0"21 }2223 // PORT24 port, exists := os.LookupEnv("PORT")2526 if !exists {27 fmt.Println("PORT was not provided, defaulting to 7432")28 port = "7432"29 }3031 // ENV32 env, exists := os.LookupEnv("ENV")3334 if !exists {35 fmt.Println("ENV was not provided, defaulting to development")36 env = "development"37 }3839 return Settings{HOST: host, PORT: port, ENV: env}40}
internal/config/config_test.goadded
+10 −0
@@ -0,0 +1,10 @@1package config23import "testing"45// no env vars set -> test defaults work6// env vars set -> they overwrite defaults78func TestLoadSettings(t *testing.T) {910}
internal/control/server.goadded
+24 −0
@@ -0,0 +1,24 @@1package control23import (4 "net/http"56 "git.danieldaum.net/daniel-daum/holonet/internal/config"7)89// setup control pane http server10// pull and provide configs11func holonet() *http.Server {12 config.GetConfig()1314 s := &http.Server{}1516 return s17}1819// start server20// wrap in graceful shutdown21func Serve() {2223 holonet().ListenAndServe()24}
main.godeleted
+0 −11
@@ -1,11 +0,0 @@1package main23import "fmt"45func Hello() string {6 return "hello world!"7}8func main() {910 fmt.Println(Hello())11}
mise.lock
+4 −0
@@ -17,6 +17,10 @@ backend = "core:go"1717checksum = "sha256:ee215d57e0ec269c60cc9ceca68e6bda321ba9ee5afe24f4b0988703c2d87d12"1818url = "https://dl.google.com/go/go1.27.1.darwin-arm64.tar.gz"191920[[tools."go:golang.org/x/vuln/cmd/govulncheck"]]21version = "1.7.0"22backend = "go:golang.org/x/vuln/cmd/govulncheck"232024[[tools.golangci-lint]]2125version = "2.13.2"2226backend = "aqua:golangci/golangci-lint"
mise.toml
+33 −0
@@ -1,7 +1,40 @@1# ===== TOOLS =====12[tools]23air = "1.67.4"34go = "1.27.1"5"go:golang.org/x/vuln/cmd/govulncheck" = "1.7.0"46golangci-lint = "2.13.2"578# ===== SETTINGS =====69[settings]710lockfile = true1112# ===== ENV =====13[env]14HOST="0.0.0.0"15PORT=743216ENV="development"171819# ===== TASKS =====20# start development server with air live reloading21[tasks.dev]22run = "air"2324[tasks.start]25run = "go run ./cmd/holonet/"2627[tasks.build]28run = "go build -o bin/holonet ./cmd/holonet/"2930[tasks.lint]31run = "golangci-lint run ./..."3233[tasks.test]34run = "go test ./..."3536[tasks.vuln]37run = "govulncheck ./..."3839[tasks.check]40depends = ["lint", "test", "vuln"]