2021-12-22 10:52:02 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2022-03-15 13:53:24 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
2021-12-22 10:52:02 +00:00
|
|
|
|
2022-09-25 12:23:22 +00:00
|
|
|
"code.icb4dc0.de/prskr/goveal/config"
|
2021-12-22 10:52:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2021-12-22 10:52:02 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
2021-12-22 10:52:02 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
writer.WriteHeader(http.StatusInternalServerError)
|
|
|
|
}
|
2021-12-22 10:52:02 +00:00
|
|
|
}
|