main.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package main
  2. import (
  3. //"io"
  4. "os"
  5. "fmt"
  6. "vultras.su/core/bond"
  7. "vultras.su/core/cli/mtool"
  8. "vultras.su/core/bond/methods"
  9. "vultras.su/core/bond/statuses"
  10. "vultras.su/core/bond/jsons"
  11. )
  12. type Request struct {
  13. UserName string `json:"user_name"`
  14. PhoneNumber string `json:"phone_number"`
  15. Email string `json:"email"`
  16. Inn string `json:"inn"`
  17. CompanyName string `json:"company_name"`
  18. ProductCategories string `json:"product_categories"`
  19. AverageAmount jsons.Int `json:"average_amount"`
  20. CallAt string `json:"call_at"`
  21. Note string `json:"note"`
  22. PromoTermsAccepted bool `json:"promo_terms_accepted"`
  23. UtmCampaign string `json:"utm_compaign"`
  24. UtmLabel string `json:"utm_label"`
  25. UtmMedium string `json:"utm_medium"`
  26. UtmSource string `json:"utm_source"`
  27. UtmTerm string `json:"utm_term"`
  28. }
  29. var rootHandler = bond.Path().Case(
  30. "",
  31. bond.Redirect("/b2b_new_clients", statuses.SeeOther),
  32. ).Case(
  33. "b2b_new_clients",
  34. bond.Method().Case(
  35. methods.Get,
  36. bond.StaticFile("landing.htm"),
  37. ),
  38. ).Case(
  39. "api",
  40. bond.Path().Case(
  41. "b2b_new_clients",
  42. bond.Method().Case(
  43. methods.Post,
  44. bond.Func(func(c *bond.Context){
  45. request := Request{}
  46. if !c.Scan(&request) {
  47. if c.ScanErr() != nil {
  48. fmt.Println("Scan Error:", c.ScanErr())
  49. return
  50. }
  51. }
  52. fmt.Printf("%v\n", request)
  53. c.Redirect("/done", statuses.Found)
  54. }),
  55. ),
  56. ),
  57. ).Case(
  58. "done",
  59. bond.StaticFile("done.htm"),
  60. ).Case(
  61. "web",
  62. bond.StaticDir("web"),
  63. )
  64. type ServerOptions struct {
  65. Addr string
  66. }
  67. var Tool = mtool.T("landing").Func(func(flags *mtool.Flags){
  68. opts := ServerOptions{}
  69. flags.StringVar(&opts.Addr, "addr", ":8080", "the address for server to serve")
  70. flags.Parse()
  71. srv := bond.Server{
  72. Addr: opts.Addr,
  73. Handler: bond.Root(rootHandler),
  74. }
  75. panic(srv.ListenAndServe())
  76. })
  77. func main() {
  78. Tool.Run(os.Args[1:])
  79. }