You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

servertest.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. )
  7. type httphandlerrework struct {
  8. }
  9. func (h *httphandlerrework) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  10. if r.URL.Path == "/api/store" {
  11. if r.Method == http.MethodGet {
  12. h.regalReq(w, r)
  13. return
  14. }
  15. if r.Method == http.MethodPut {
  16. h.regalPut(w, r)
  17. return
  18. }
  19. }
  20. if r.URL.Path == "/api/retrieve" && r.Method == http.MethodGet {
  21. h.waitForItem(w, r)
  22. return
  23. }
  24. }
  25. func (h *httphandlerrework) regalReq(w http.ResponseWriter, r *http.Request) {
  26. //TODO: Retrieve Item from Storage
  27. w.WriteHeader(http.StatusInternalServerError)
  28. regalNum := r.URL.Query().Get("regal") // Regal
  29. floorNum := r.URL.Query().Get("floor") // Fach
  30. fmt.Fprintf(w, "POK: %d %d\n", regalNum, floorNum)
  31. fmt.Fprint(w, "NOT OK\n")
  32. }
  33. func (h *httphandlerrework) regalPut(w http.ResponseWriter, r *http.Request) {
  34. //TODO: Put Item into Storage
  35. w.WriteHeader(http.StatusInternalServerError)
  36. regalNum := r.URL.Query().Get("regal") // Regal
  37. floorNum := r.URL.Query().Get("floor") // Fach
  38. fmt.Fprintf(w, "POK: %d %d\n", regalNum, floorNum)
  39. fmt.Fprint(w, "NOT OK")
  40. }
  41. func (h *httphandlerrework) waitForItem(w http.ResponseWriter, r *http.Request) {
  42. //TODO: Move into position to accept a new item
  43. w.WriteHeader(http.StatusInternalServerError)
  44. fmt.Fprint(w, "NOT OK")
  45. }
  46. func main() {
  47. err := http.ListenAndServe("localhost:33949", &httphandlerrework{}) // set listen port
  48. if err != nil {
  49. log.Fatal("ListenAndServe: ", err)
  50. }
  51. }