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.

59 lines
1.0 KiB

4 years ago
  1. package WorstCaptcha
  2. import (
  3. "github.com/gorilla/mux"
  4. "net/http"
  5. "encoding/json"
  6. )
  7. var GlobalDb Db
  8. type Route struct {
  9. Name string
  10. Method string
  11. Pattern string
  12. Handler http.HandlerFunc
  13. }
  14. type Routes []Route
  15. func NewRouter(db Db) *mux.Router {
  16. router := mux.NewRouter().StrictSlash(true)
  17. GlobalDb = db
  18. for _, route := range routes {
  19. router.
  20. Methods(route.Method).
  21. Path(route.Pattern).
  22. Name(route.Name).
  23. Handler(route.Handler)
  24. }
  25. return router
  26. }
  27. var routes = Routes{
  28. Route{
  29. Name: "RequestCaptcha",
  30. Method: "GET",
  31. Pattern: "/v1/captcha/",
  32. Handler: RequestCaptcha,
  33. },
  34. }
  35. type ResponseCaptcha struct {
  36. ImageLocation string `json:"image_location"`
  37. ResponseLocation string `json:"response_location"`
  38. }
  39. func RequestCaptcha(w http.ResponseWriter, r *http.Request) {
  40. response := ResponseCaptcha{"aoeu", "asdf"}
  41. // fmt.Println(GlobalDb)
  42. w.Header().Set("Content-Type", "application/json; charset=UTF-8")
  43. w.WriteHeader(http.StatusOK)
  44. json.NewEncoder(w).Encode(response)
  45. }