gin plugin for go-chassis
in chassis.yaml, add following
---
servicecomb:
protocols:
gin:
listenAddress: 127.0.0.1:5001
in main.go, add following
package main
import (
"github.com/gin-gonic/gin"
"github.com/go-chassis/go-chassis/v2"
"github.com/go-chassis/openlog"
_ "github.com/daqingshu/go-chassis-gin"
)
type RestFulHello struct {
}
// Root Root
func (r *RestFulHello) Hello(c *gin.Context) {
c.Writer.WriteString(fmt.Sprintf("hello %s", c.Request.RemoteAddr))
}
//URLPatterns helps to respond for corresponding API calls
func (r *RestFulHello) URLPatterns(router *gin.RouterGroup) {
router.GET("/hello", r.Hello)
}
func main() {
chassis.RegisterSchema("gin", &RestFulHello{})
if err := chassis.Init(); err != nil {
openlog.Fatal("Init failed." + err.Error())
return
}
chassis.Run()
}
then, visit http://127.0.0.1:5001/hello