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
|
|
|
|
|
|
|
"git.xdrm.io/example/aicra/service/auth"
|
|
|
|
"git.xdrm.io/example/aicra/service/shortener"
|
|
|
|
|
|
|
|
"git.xdrm.io/example/aicra/storage"
|
|
|
|
"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())
|
|
|
|
|
|
|
|
// 3. storage connect
|
|
|
|
log.Printf("[storage] connecting")
|
|
|
|
storageClient, err := storage.New()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("/!\\ cannot connect %v", err)
|
2018-06-10 20:49:32 +00:00
|
|
|
}
|
2019-05-01 14:42:17 +00:00
|
|
|
defer storageClient.Close()
|
|
|
|
|
|
|
|
// 4. init services
|
|
|
|
authService := auth.New(storageClient)
|
|
|
|
shortenerService := shortener.New(storageClient, authService)
|
|
|
|
|
|
|
|
// 5. wire services
|
|
|
|
shortenerService.Wire(server)
|
|
|
|
authService.Wire(server)
|
2018-06-10 20:49:32 +00:00
|
|
|
|
2019-05-01 14:42:17 +00:00
|
|
|
// 6. listen and serve
|
|
|
|
log.Printf("[server] listening")
|
2018-10-01 17:28:54 +00:00
|
|
|
err = http.ListenAndServe(listenTo, server)
|
2018-06-10 20:49:32 +00:00
|
|
|
if err != nil {
|
2019-05-01 14:42:17 +00:00
|
|
|
log.Fatalf("/!\\ cannot listen: %v\n", err)
|
2018-06-10 20:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|