使用命令行,运行出错,暂时无法解决
package main
import (
"flag"
"fmt"
"gitee.com/Hind3ight/easy-go-micro/go-micro/model"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/web"
"github.com/micro/go-plugins/registry/consul" // micro版本变迁
"log"
)
func main() {
consulReg := consul.NewRegistry(registry.Addrs("192.168.31.246:8500"))
r := gin.Default()
r.Handle("GET", "/news", func(c *gin.Context) {
c.String(200, "new api")
})
prodGroup := r.Group("v1")
{
prodGroup.Handle("GET", "/prods", func(c *gin.Context) {
c.JSON(200, gin.H{
"data": model.GenFakerProdList(4),
})
})
}
server := web.NewService(
web.Name("prodService"),
web.Address(flagParser()),
web.Handler(r),
web.Registry(consulReg),
)
err := server.Run()
if err != nil {
log.Fatal("Server Run error: ", err)
}
}
// simple 自定义命令行解析
func flagParser() string {
serverAddress := flag.String("server_address", ":8080", "服务端口")
flag.Parse()
fmt.Println("端口号:", *serverAddress)
return *serverAddress
}
先自己写个函数简单解决