From 3d664fff67cf61481bca055d1836c503313fbe36 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Tue, 17 Mar 2026 19:03:43 -0500 Subject: [PATCH] add option to enable api server --- api.go | 7 +++++++ config.yaml | 1 + internal/config/config.go | 3 ++- schema/config.schema.json | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index a90a520..5302a36 100644 --- a/api.go +++ b/api.go @@ -15,6 +15,10 @@ import ( ) func (r *Router) startAPIServer(config config.ApiConfig) { + if !config.Enabled { + r.logger.Warn("API not enabled") + return + } r.logger.Debug("starting API server", "port", config.Port) mux := http.NewServeMux() mux.HandleFunc("/ws", r.handleWebsocket) @@ -36,6 +40,9 @@ func (r *Router) startAPIServer(config config.ApiConfig) { } func (r *Router) stopAPIServer() { + if r.apiServer == nil { + return + } r.logger.Debug("stopping API server") r.apiServerMu.Lock() defer r.apiServerMu.Unlock() diff --git a/config.yaml b/config.yaml index 71a0138..4616f69 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,5 @@ api: + enabled: true port: 8080 modules: - id: http diff --git a/internal/config/config.go b/internal/config/config.go index 6878187..7e705a2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,7 +7,8 @@ type Config struct { } type ApiConfig struct { - Port int `json:"port"` + Enabled bool `json:"enabled"` + Port int `json:"port"` } type ModuleConfig struct { Id string `json:"id"` diff --git a/schema/config.schema.json b/schema/config.schema.json index 7046004..74b9c32 100644 --- a/schema/config.schema.json +++ b/schema/config.schema.json @@ -8,6 +8,10 @@ "api": { "type": "object", "properties": { + "enabled": { + "type": "boolean", + "description": "Whether the API server is enabled" + }, "port": { "type": "integer", "description": "Port for the API server to listen on"