36 lines
1 KiB
Go
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)
|
|
}
|
|
}
|