1 Star 4 Fork 0

jingshanccc / course

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
jingshanccc 提交于 2021-03-21 14:04 . [feature] #70
package main
import (
"course/config"
"course/course-srv/proto/course"
"course/file-srv/proto/file"
"course/gateway/route"
"course/middleware/redis"
"course/user-srv/proto/user"
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v2/web"
"github.com/micro/go-plugins/registry/consul/v2"
)
func main() {
defer redis.RedisClient.Close()
//initial registry
r := consul.NewRegistry(registry.Addrs(config.RegistryAddr))
client := micro.NewService(micro.Name(config.UserClientName))
//get UserService from registry
client.Init(micro.Registry(r))
userService := user.NewUserService(config.UserServiceName, client.Client())
client = micro.NewService(micro.Name(config.CourseCliName))
//get CourseService from registry
client.Init(micro.Registry(r))
courseService := course.NewCourseService(config.CourseServiceName, client.Client())
client = micro.NewService(micro.Name(config.FileClientName))
//get FileService from registry
client.Init(micro.Registry(r))
fileService := file.NewFileService(config.FileServiceName, client.Client())
//create web micro service, register in consul, use gin router to handler request
server := web.NewService(
web.Name(config.GatewayName),
web.Address(config.GatewayAddr),
web.Handler(route.NewRouter(userService, courseService, fileService)),
web.Registry(r),
)
server.Init()
server.Run()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jingshanccc/course.git
git@gitee.com:jingshanccc/course.git
jingshanccc
course
course
015e9e7708fb

搜索帮助

344bd9b3 5694891 D2dac590 5694891