goveal/api/config.go
Peter Kurfer 38471371c9
All checks were successful
agola/goveal/Test and lint The run finished successfully
refactor: migrate to Gitea server
2022-09-25 14:23:46 +02:00

36 lines
1,013 B
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 {
writer.WriteHeader(http.StatusInternalServerError)
}
}