2024-08-23 23:58:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-08-24 13:02:16 +00:00
|
|
|
"time"
|
|
|
|
|
|
2024-08-24 08:56:01 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2024-08-23 23:58:44 +00:00
|
|
|
"github.com/micro/plugins/v5/registry/consul"
|
|
|
|
|
"go-micro.dev/v5/registry"
|
2024-08-24 08:56:01 +00:00
|
|
|
"go-micro.dev/v5/web"
|
|
|
|
|
"myschools.me/suguo/go-micro-demo/handler"
|
2024-08-23 23:58:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
consulReg := consul.NewRegistry(
|
|
|
|
|
registry.Addrs("127.0.0.1:8500"),
|
|
|
|
|
)
|
2024-08-24 08:56:01 +00:00
|
|
|
ginRouter := gin.New()
|
|
|
|
|
v1 := ginRouter.Group(`/v1`)
|
|
|
|
|
{
|
|
|
|
|
v1.GET(`/hello`, handler.HelloWorld)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
service := web.NewService(
|
|
|
|
|
web.Name("hello"),
|
|
|
|
|
web.Handler(ginRouter),
|
2024-08-24 13:02:16 +00:00
|
|
|
web.RegisterTTL(time.Second*5),
|
|
|
|
|
web.RegisterInterval(time.Second),
|
2024-08-24 08:56:01 +00:00
|
|
|
web.Address(":8080"),
|
|
|
|
|
web.Registry(consulReg),
|
2024-08-23 23:58:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
service.Init()
|
|
|
|
|
service.Run()
|
|
|
|
|
}
|