1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package main
- import (
- //"io"
- "os"
- "fmt"
- "vultras.su/core/bond"
- "vultras.su/core/cli/mtool"
- "vultras.su/core/bond/methods"
- "vultras.su/core/bond/statuses"
- "vultras.su/core/bond/jsons"
- )
- type Request struct {
- UserName string `json:"user_name"`
- PhoneNumber string `json:"phone_number"`
- Email string `json:"email"`
- Inn string `json:"inn"`
- CompanyName string `json:"company_name"`
- ProductCategories string `json:"product_categories"`
- AverageAmount jsons.Int `json:"average_amount"`
- CallAt string `json:"call_at"`
- Note string `json:"note"`
- PromoTermsAccepted bool `json:"promo_terms_accepted"`
- UtmCampaign string `json:"utm_compaign"`
- UtmLabel string `json:"utm_label"`
- UtmMedium string `json:"utm_medium"`
- UtmSource string `json:"utm_source"`
- UtmTerm string `json:"utm_term"`
- }
- var rootHandler = bond.Path().Case(
- "",
- bond.Redirect("/b2b_new_clients", statuses.SeeOther),
- ).Case(
- "b2b_new_clients",
- bond.Method().Case(
- methods.Get,
- bond.StaticFile("landing.htm"),
- ),
- ).Case(
- "api",
- bond.Path().Case(
- "b2b_new_clients",
- bond.Method().Case(
- methods.Post,
- bond.Func(func(c *bond.Context){
- request := Request{}
- if !c.Scan(&request) {
- if c.ScanErr() != nil {
- fmt.Println("Scan Error:", c.ScanErr())
- return
- }
- }
- fmt.Printf("%v\n", request)
- c.Redirect("/done", statuses.Found)
- }),
- ),
- ),
- ).Case(
- "done",
- bond.StaticFile("done.htm"),
- ).Case(
- "web",
- bond.StaticDir("web"),
- )
- type ServerOptions struct {
- Addr string
- }
- var Tool = mtool.T("landing").Func(func(flags *mtool.Flags){
- opts := ServerOptions{}
- flags.StringVar(&opts.Addr, "addr", ":8080", "the address for server to serve")
- flags.Parse()
- srv := bond.Server{
- Addr: opts.Addr,
- Handler: bond.Root(rootHandler),
- }
- panic(srv.ListenAndServe())
- })
- func main() {
- Tool.Run(os.Args[1:])
- }
|