-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
32 lines (30 loc) · 867 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
package main
import (
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
"github.com/sirupsen/logrus"
"github.com/xhynever/wallet-test/handler"
repository "github.com/xhynever/wallet-test/repository/sqlc"
"github.com/xhynever/wallet-test/services"
"github.com/xhynever/wallet-test/util"
)
func main() {
// 读配置
config := util.InitConfig()
// 初始化db
conn, err := util.InitDB()
if err != nil {
logrus.Fatal("cannot connect to db", err)
}
// 设置db连接池
conn.SetMaxOpenConns(config.PgPool)
conn.SetMaxIdleConns(config.PgPool)
//initialize store, services and server
store := repository.NewStore(conn)
services := services.NewService(store)
handlers := handler.NewHandler(services)
r := gin.Default()
// api接口,主要重心
handlers.InitRouter(r)
logrus.Fatal(r.Run(config.ServersAddress))
}