more data
This commit is contained in:
18
main.go
18
main.go
@@ -82,7 +82,7 @@ func (a *App) HandleSave(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func main() {
|
||||
// Create a new instance of the server
|
||||
storage, err := NewDiskStorage("data/state.json")
|
||||
storage, err := NewDiskStorage("data/state.gob")
|
||||
if err != nil {
|
||||
log.Printf("Error loading state: %v\n", err)
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /api/{id}", app.HandleGet)
|
||||
mux.HandleFunc("GET /api/{id}/add/{sku}", app.HandleAddSku)
|
||||
mux.HandleFunc("GET /remote/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||
mux.HandleFunc("GET /remote/{id}/add", func(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.PathValue("id")
|
||||
ts := time.Now().Unix()
|
||||
data, err := remotePool.Process(ToCartId(id), Message{
|
||||
@@ -117,7 +117,19 @@ func main() {
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(data)
|
||||
w.Write(data)
|
||||
})
|
||||
mux.HandleFunc("GET /remote/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.PathValue("id")
|
||||
data, err := remotePool.Get(ToCartId(id))
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(data)
|
||||
})
|
||||
mux.HandleFunc("GET /save", app.HandleSave)
|
||||
http.ListenAndServe(":8080", mux)
|
||||
|
||||
Reference in New Issue
Block a user