MCPcopy Create free account
hub / github.com/BryanMwangi/pine / main

Function main

Examples/BindExample/main.go:33–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31type Users []User
32
33func main() {
34 app := pine.New()
35 app.Get("/hello/:name", func(c *pine.Ctx) error {
36 params := new(MyParams)
37 err := c.BindParam("name", &params.Name)
38 if err != nil {
39 return c.SendStatus(http.StatusBadRequest)
40 }
41 return c.SendString("Hello " + params.Name)
42 })
43
44 app.Get("/search", func(c *pine.Ctx) error {
45 query := new(Query)
46 err := c.BindQuery("query", query)
47 if err != nil {
48 return c.SendStatus(http.StatusBadRequest)
49 }
50 return c.SendString("you searched for " + string(*query))
51 })
52
53 app.Post("/login", func(c *pine.Ctx) error {
54 user := new(User)
55 err := c.BindJSON(user)
56 if err != nil {
57 return c.SendStatus(http.StatusBadRequest)
58 }
59 return c.SendString("login in successful")
60 })
61
62 app.Post("/signUp", func(c *pine.Ctx) error {
63 request := new(Request)
64 err := c.BindJSON(request)
65 if err != nil {
66 return c.SendStatus(http.StatusBadRequest)
67 }
68 return c.SendString("User registered successfully")
69 })
70
71 app.Post("/migrate", func(c *pine.Ctx) error {
72 users := new(Users)
73 err := c.BindJSON(users)
74 if err != nil {
75 return c.SendStatus(http.StatusBadRequest)
76 }
77 return c.SendString("migration was a success!")
78 })
79 // Start the server on port 3000
80 log.Fatal(app.Start(":3001"))
81}

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
BindParamMethod · 0.80
SendStatusMethod · 0.80
SendStringMethod · 0.80
BindQueryMethod · 0.80
BindJSONMethod · 0.80
GetMethod · 0.45
PostMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected