added backend

This commit is contained in:
wt committed 2025-07-09 17:46:47 +07:00
1 parent 9842ccee3d
commit 40bcd02c36
10 files changed
+340 -75

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
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))
}
}