Go-Micro结合gin框架启用web服务

xiaohai 2021-05-09 22:25:40 2867人围观 标签: Go 
简介Go-Micro结合gin框架启用web服务

go-micro框架和gin框架结合

package history

import (
   "github.com/gin-gonic/gin"
 "github.com/micro/go-micro/web" )

func main() {
   routers := gin.Default()
   routers.GET("/", func(context *gin.Context) {
      context.JSON(200, map[string]interface{}{
         "name": 1,
  })
   })
   routers.GET("/version", func(context *gin.Context) {
      context.JSON(200, map[string]interface{}{
         "version": "1.0.0",
  })
   })
   server := web.NewService(
      web.Address(":8080"),
  web.Handler(routers),
  )
   server.Run()
}