1 parent
952587df4f
commit
efcb19aa2f
19 files changed
+276
-189
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user