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"