Files
kls/main.go
Kyle Isom d3c174d9b0 Support $PORT env var for MCP agent port allocation
MCP agent sets $PORT for containers with route declarations.
$PORT takes precedence over HTTP_PORT from config, matching the mcdsl
convention used by all other platform services.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 18:07:49 -07:00

43 lines
905 B
Go

package main
import (
"context"
"flag"
"log"
"net"
"net/http"
"os"
"git.wntrmute.dev/kyle/goutils/config"
"git.wntrmute.dev/kyle/goutils/die"
"git.wntrmute.dev/kyle/kls/links"
)
var defaultConfigFile = config.DefaultConfigPath("kls", "kls.conf")
func main() {
cfgFile := flag.String("f", defaultConfigFile, "`path` to config file")
flag.Parse()
err := config.LoadFile(*cfgFile)
die.If(err)
ctx := context.Background()
db, err := links.Connect(ctx)
die.If(err)
srv := &server{db: db}
http.Handle("/", srv)
// $PORT is set by the MCP agent for containers with route declarations.
// It takes precedence over config, matching the mcdsl convention.
port := os.Getenv("PORT")
if port == "" {
port = config.GetDefault("HTTP_PORT", "8000")
}
addr := net.JoinHostPort(config.Get("HTTP_ADDR"), port)
log.Print("listening on ", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}