go-micro-demo/webService.go1

36 lines
702 B
Plaintext
Raw Normal View History

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-09-06 14:50:46 +00:00
"github.com/micro/go-micro/v5/web"
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
"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"),
)
ginRouter := gin.Default()
2024-08-24 08:56:01 +00:00
v1 := ginRouter.Group(`/v1`)
{
v1.POST(`/hello`, handler.HelloWorld)
2024-08-24 08:56:01 +00:00
}
service := web.NewService(
web.Name("hello"),
web.Handler(ginRouter),
2024-08-24 14:58:36 +00:00
// web.RegisterTTL(time.Second*5),
2024-08-24 13:02:16 +00:00
web.RegisterInterval(time.Second),
2024-08-24 08:56:01 +00:00
web.Address(":8080"),
web.Metadata(map[string]string{"protocol": "http"}),
2024-08-24 08:56:01 +00:00
web.Registry(consulReg),
2024-08-23 23:58:44 +00:00
)
service.Init()
service.Run()
}