-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (47 loc) · 1.41 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"strings"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
_ "github.com/mattn/go-sqlite3"
"github.com/optiopay/kafka/v2"
"github.com/spf13/viper"
"github.com/xiaof-github/kafdrop-go/kafgo"
_ "github.com/xiaof-github/kafdrop-go/routers"
)
func main() {
viper.SetConfigName("app")
viper.AddConfigPath("conf")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
addr := viper.GetString("kafka.addr")
addrs := strings.Split(addr, ",")
fmt.Println(addrs)
fmt.Println(kafgo.OFFSET_INIT)
// connect to kafka cluster
broker, err := kafka.Dial(addrs, kafka.NewBrokerConf("test"))
if err != nil {
panic(err)
}
defer broker.Close()
kafgo.Broker = broker
//注册sqlite3
orm.RegisterDataBase("default", "sqlite3", "go-admin.db")
//同步 ORM 对象和数据库
//这时, 在你重启应用的时候, beego 便会自动帮你创建数据库表。
orm.Debug = true
orm.RunSyncdb("default", false, true)
//增加拦截器。
var filterAdmin = func(ctx *context.Context) {
url := ctx.Input.URL()
logs.Info("##### filter url : %s", url)
//TODO 如果判断用户未登录。
}
beego.InsertFilter("/admin/*", beego.BeforeExec, filterAdmin)
beego.Run()
}