first commit
This commit is contained in:
26
handlers/scheduler.go
Normal file
26
handlers/scheduler.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Schedule map[string]interface{}
|
||||
|
||||
func SaveSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
var s Schedule
|
||||
json.NewDecoder(r.Body).Decode(&s)
|
||||
data, _ := json.Marshal(s)
|
||||
os.WriteFile("schedule.json", data, 0644)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := os.ReadFile("schedule.json")
|
||||
if err != nil {
|
||||
json.NewEncoder(w).Encode(Schedule{})
|
||||
return
|
||||
}
|
||||
w.Write(data)
|
||||
}
|
||||
Reference in New Issue
Block a user