Files
wt efcb19aa2f
Build / Build (push) Successful in 32s
more optimizations
2025-07-07 22:40:06 +07:00

36 lines
874 B
Go

package api
import (
"dns_service/settings"
"dns_service/utils"
"encoding/json"
"net/http"
)
func Settings(w http.ResponseWriter, req *http.Request) {
switch req.Method {
case "GET":
respSettings, err := settings.GetSettings()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
utils.RespondWithJSON(w, respSettings, http.StatusOK)
case "POST":
var newSettings map[string]any
if err := json.NewDecoder(req.Body).Decode(&newSettings); err != nil {
http.Error(w, "invalid JSON format", http.StatusBadRequest)
return
}
respSettings, err := settings.SetSettings(newSettings)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
utils.RespondWithJSON(w, respSettings, http.StatusOK)
default:
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
}
}