mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 12:55:29 +00:00
add option to enable api server
This commit is contained in:
7
api.go
7
api.go
@@ -15,6 +15,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (r *Router) startAPIServer(config config.ApiConfig) {
|
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)
|
r.logger.Debug("starting API server", "port", config.Port)
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/ws", r.handleWebsocket)
|
mux.HandleFunc("/ws", r.handleWebsocket)
|
||||||
@@ -36,6 +40,9 @@ func (r *Router) startAPIServer(config config.ApiConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) stopAPIServer() {
|
func (r *Router) stopAPIServer() {
|
||||||
|
if r.apiServer == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
r.logger.Debug("stopping API server")
|
r.logger.Debug("stopping API server")
|
||||||
r.apiServerMu.Lock()
|
r.apiServerMu.Lock()
|
||||||
defer r.apiServerMu.Unlock()
|
defer r.apiServerMu.Unlock()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
api:
|
api:
|
||||||
|
enabled: true
|
||||||
port: 8080
|
port: 8080
|
||||||
modules:
|
modules:
|
||||||
- id: http
|
- id: http
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ApiConfig struct {
|
type ApiConfig struct {
|
||||||
Port int `json:"port"`
|
Enabled bool `json:"enabled"`
|
||||||
|
Port int `json:"port"`
|
||||||
}
|
}
|
||||||
type ModuleConfig struct {
|
type ModuleConfig struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
"api": {
|
"api": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"enabled": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether the API server is enabled"
|
||||||
|
},
|
||||||
"port": {
|
"port": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Port for the API server to listen on"
|
"description": "Port for the API server to listen on"
|
||||||
|
|||||||
Reference in New Issue
Block a user