2018-07-08 13:29:25 +00:00
|
|
|
package main
|
2018-06-10 20:49:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2018-07-11 17:08:09 +00:00
|
|
|
"net/http"
|
2019-05-01 14:42:17 +00:00
|
|
|
|
2020-03-03 19:02:15 +00:00
|
|
|
"git.xdrm.io/go/tiny-url-ex/service/auth"
|
|
|
|
"git.xdrm.io/go/tiny-url-ex/service/shortener"
|
2019-05-01 14:42:17 +00:00
|
|
|
|
|
|
|
"git.xdrm.io/go/aicra"
|
|
|
|
"git.xdrm.io/go/aicra/typecheck/builtin"
|
2018-06-10 20:49:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2018-10-01 17:28:54 +00:00
|
|
|
listenTo := "127.0.0.1:4242"
|
2018-07-11 17:08:09 +00:00
|
|
|
|
2019-05-01 14:42:17 +00:00
|
|
|
// 1. build server
|
|
|
|
log.Printf("[server] building")
|
2018-10-01 17:28:54 +00:00
|
|
|
server, err := aicra.New("api.json")
|
2018-06-10 20:49:32 +00:00
|
|
|
if err != nil {
|
2019-05-01 14:42:17 +00:00
|
|
|
log.Fatalf("/!\\ cannot init server: %v\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. add type checkers
|
|
|
|
server.Checkers.Add(builtin.NewAny())
|
|
|
|
server.Checkers.Add(builtin.NewString())
|
|
|
|
server.Checkers.Add(builtin.NewFloat64())
|
|
|
|
|
2020-03-03 19:02:15 +00:00
|
|
|
// 3. init services
|
|
|
|
authService, err := auth.New()
|
2019-05-02 18:50:58 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cannot create auth service: %v", err)
|
|
|
|
}
|
2020-03-03 19:02:15 +00:00
|
|
|
shortenerService, err := shortener.New(authService)
|
2019-05-02 18:50:58 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cannot create auth service: %v", err)
|
|
|
|
}
|
2019-05-01 14:42:17 +00:00
|
|
|
|
2020-03-03 19:02:15 +00:00
|
|
|
// 4. wire services
|
2019-05-01 14:42:17 +00:00
|
|
|
shortenerService.Wire(server)
|
|
|
|
authService.Wire(server)
|
2018-06-10 20:49:32 +00:00
|
|
|
|
2020-03-03 19:02:15 +00:00
|
|
|
// 5. listen and serve
|
|
|
|
log.Printf("[server] listening %s\n\n", listenTo)
|
|
|
|
log.Fatal(http.ListenAndServe(listenTo, server.HTTP()))
|
2018-06-10 20:49:32 +00:00
|
|
|
|
|
|
|
}
|