27 lines
533 B
Go
27 lines
533 B
Go
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)
|
|
}
|