-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (31 loc) · 881 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"github.com/cubahno/connexions/api"
"github.com/cubahno/connexions/config"
"net/http"
)
func main() {
cfg := config.NewDefaultConfig("")
cfg.App.Port = 8888
app := api.NewApp(cfg)
// add as many blueprints as needed.
_ = app.AddBluePrint(func(router *api.Router) error {
h := &ApiHandler{api.NewBaseHandler()}
router.HandleFunc("/api/v1/route-1", h.myRoute1)
router.HandleFunc("/api/v1/route-2", h.myRoute2)
return nil
})
app.Run()
}
type ApiHandler struct {
*api.BaseHandler
}
func (h *ApiHandler) myRoute1(w http.ResponseWriter, r *http.Request) {
h.JSONResponse(w).WithStatusCode(http.StatusOK).Send(&api.SimpleResponse{
Message: "hello world",
Success: true,
})
}
func (h *ApiHandler) myRoute2(w http.ResponseWriter, r *http.Request) {
h.Response(w).WithHeader("content-type", "text/plain").Send([]byte("hello world"))
}