goveal/api/config.go
Peter Kurfer f4509111b1
Some checks are pending
continuous-integration/drone/push Build is running
chore: upgrade to Go 1.20
2023-02-28 22:04:23 +01:00

36 lines
1 KiB
Go

package api
import (
"encoding/json"
"net/http"
"github.com/julienschmidt/httprouter"
"code.icb4dc0.de/prskr/goveal/config"
)
type ConfigAPI struct {
cfg *config.Components
}
func RegisterConfigAPI(router *httprouter.Router, cfg *config.Components) {
cfgAPI := &ConfigAPI{cfg: cfg}
router.GET("/api/v1/config/reveal", cfgAPI.RevealConfig)
router.GET("/api/v1/config/mermaid", cfgAPI.MermaidConfig)
}
func (a *ConfigAPI) RevealConfig(writer http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
writer.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(writer)
if err := enc.Encode(a.cfg.Reveal); err != nil {
writer.WriteHeader(http.StatusInternalServerError)
}
}
func (a *ConfigAPI) MermaidConfig(writer http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
writer.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(writer)
if err := enc.Encode(a.cfg.Mermaid); err != nil {
http.Error(writer, err.Error(), http.StatusInternalServerError)
}
}