package main import ( "log" "net/http" "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" ) func main() { listenTo := "127.0.0.1:4242" // 1. build server log.Printf("[server] building") server, err := aicra.New("api.json") if err != nil { 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") db, err := storage.New() if err != nil { log.Fatalf("/!\\ cannot connect %v", err) } defer db.Close() // 4. init services authService, err := auth.New(db) if err != nil { log.Fatalf("cannot create auth service: %v", err) } shortenerService, err := shortener.New(db, authService) if err != nil { log.Fatalf("cannot create auth service: %v", err) } // 5. wire services shortenerService.Wire(server) authService.Wire(server) // 6. listen and serve log.Printf("[server] listening\n\n") log.Fatal(http.ListenAndServe(listenTo, server)) }