goveal/api/config.go

37 lines
1 KiB
Go
Raw Normal View History

package api
import (
2022-03-15 13:53:24 +00:00
"encoding/json"
"net/http"
"github.com/julienschmidt/httprouter"
2022-09-25 12:23:22 +00:00
"code.icb4dc0.de/prskr/goveal/config"
)
type ConfigAPI struct {
cfg *config.Components
}
2022-03-15 13:53:24 +00:00
func RegisterConfigAPI(router *httprouter.Router, cfg *config.Components) {
2021-12-22 19:27:43 +00:00
cfgAPI := &ConfigAPI{cfg: cfg}
2022-03-15 13:53:24 +00:00
router.GET("/api/v1/config/reveal", cfgAPI.RevealConfig)
router.GET("/api/v1/config/mermaid", cfgAPI.MermaidConfig)
}
2022-03-15 13:53:24 +00:00
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)
}
}
2022-03-15 13:53:24 +00:00
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 {
2023-02-28 21:03:17 +00:00
http.Error(writer, err.Error(), http.StatusInternalServerError)
2022-03-15 13:53:24 +00:00
}
}