Files
dashboard/backend/api/services.go
T
2025-07-09 17:46:47 +07:00

33 lines
578 B
Go

package api
import (
"fmt"
"io"
"net/http"
"os"
)
func ReadServicesFile() string {
data, e := os.ReadFile(os.Getenv("SERVICES_FILE"))
if e != nil {
panic(e)
}
return string(data)
}
func Services(w http.ResponseWriter, req *http.Request) {
switch req.Method {
case "GET":
fmt.Fprintf(w, "%s", ReadServicesFile())
case "POST":
data, err := io.ReadAll(req.Body)
if err != nil {
fmt.Fprintf(w, "Error to read body: %v", err)
return
}
fmt.Println(string(data))
os.WriteFile(os.Getenv("SERVICES_FILE"), data, 4755)
fmt.Fprint(w, string(data))
}
}