Web 服务

This commit is contained in:
奶爸
2019-12-08 16:59:58 +08:00
parent 5a21ce6ca6
commit d8c4364653
33 changed files with 1112 additions and 21 deletions

View File

@@ -1,27 +1,36 @@
package main
import (
"net"
"time"
"google.golang.org/grpc"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/patrickmn/go-cache"
pb "github.com/p14yground/nezha/proto"
"github.com/p14yground/nezha/service/handler"
"github.com/p14yground/nezha/cmd/dashboard/controller"
"github.com/p14yground/nezha/cmd/dashboard/rpc"
"github.com/p14yground/nezha/model"
"github.com/p14yground/nezha/service/dao"
)
func main() {
server := grpc.NewServer()
pb.RegisterNezhaServiceServer(server, &handler.NezhaHandler{
Auth: &handler.AuthHandler{
AppKey: "naiba",
AppSecret: "123456",
},
})
lis, err := net.Listen("tcp", ":5555")
func init() {
var err error
dao.Conf, err = model.ReadInConfig("data/config.yaml")
if err != nil {
panic(err)
}
server.Serve(lis)
dao.Admin = &model.User{
Login: dao.Conf.GitHub.Admin,
}
dao.DB, err = gorm.Open("sqlite3", "data/sqlite.db")
if err != nil {
panic(err)
}
dao.Cache = cache.New(5*time.Minute, 10*time.Minute)
}
func main() {
go controller.ServeWeb()
go rpc.ServeRPC()
select {}
}