36 lines
641 B
Go
36 lines
641 B
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"myschools.me/suguo/go-micro-demo/model"
|
|
)
|
|
|
|
func HelloWorld(c *gin.Context) {
|
|
c.JSON(200, gin.H{
|
|
"data": "hello world" + time.Now().String(),
|
|
})
|
|
}
|
|
|
|
func HelloSay(c *gin.Context) {
|
|
req := &model.HelloRequest{}
|
|
if err := c.ShouldBindJSON(req); err != nil {
|
|
c.Status(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
data := make([]*model.HelloModel, 0)
|
|
for i := 0; i < int(req.Times%10); i++ {
|
|
data = append(data, &model.HelloModel{
|
|
Id: int32(i),
|
|
Name: fmt.Sprintf("hello %d", i),
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, &model.HelloResponse{
|
|
Data: data,
|
|
})
|
|
}
|