go-micro-demo/webService.go1

36 lines
702 B
Plaintext

package main
import (
"time"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/v5/web"
"github.com/micro/plugins/v5/registry/consul"
"go-micro.dev/v5/registry"
"myschools.me/suguo/go-micro-demo/handler"
)
func main() {
consulReg := consul.NewRegistry(
registry.Addrs("127.0.0.1:8500"),
)
ginRouter := gin.Default()
v1 := ginRouter.Group(`/v1`)
{
v1.POST(`/hello`, handler.HelloWorld)
}
service := web.NewService(
web.Name("hello"),
web.Handler(ginRouter),
// web.RegisterTTL(time.Second*5),
web.RegisterInterval(time.Second),
web.Address(":8080"),
web.Metadata(map[string]string{"protocol": "http"}),
web.Registry(consulReg),
)
service.Init()
service.Run()
}