routes.go 501 B

12345678910111213141516171819202122232425262728293031
  1. package api
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. type Route struct {
  7. Name string
  8. Method string
  9. Pattern string
  10. HandlerFunc http.HandlerFunc
  11. }
  12. type Routes []Route
  13. var routes = Routes{
  14. Route{
  15. "SayHello",
  16. "GET",
  17. "/hello",
  18. func(writer http.ResponseWriter, request *http.Request) {
  19. writer.Header().Set("Content-Type", "application/json; charset=UTF-8")
  20. dict := map[string]string{
  21. "message": "hello world!",
  22. }
  23. data, _ := json.Marshal(dict)
  24. writer.Write(data)
  25. },
  26. },
  27. }