首页 > TAG信息列表 > StatusOK
Gin框架路由
Gin框架路由 一、普通路由 r.GET("/index", func(c *gin.Context) {...}) r.GET("/login", func(c *gin.Context) {...}) r.POST("/login", func(c *gin.Context) {...}) package main import ( "github.com/gin-gonic/gin" "net/httpGin - 数据响应
1. JSON g.POST("/login", func(ctx *gin.Context) { var user User if err := ctx.BindJSON(&user); err != nil { // 返回 JSON 格式数据 ctx.JSON(http.StatusBadRequest, gin.H{ "error": err.Error(), })Gin Any方法路由
package main import ( "github.com/gin-gonic/gin" "net/http" ) func main() { router := gin.Default() router.Any("/", func(ctx *gin.Context) { switch ctx.Request.Method { case http.MethodGet: ctx.JSON(http.StatusO从MINIO获取文件然后返回前台文件流
minioObject, getObjErr := minioClient.GetObject(ConfigUtil.MinioBucket, key, minio.GetObjectOptions{})if getObjErr != nil { c.JSON(http.StatusOK, gin.H{"success": false, "info": "获取文件信息异常!" + getObjErr.Error()}) return}bugin运行多个服务
gin运行多个服务 package main import ( "log" "net/http" "time" "github.com/gin-gonic/gin" "golang.org/x/sync/errgroup" ) var ( g errgroup.Group ) func router01() http.Handler { e := gin.New() e.Use(g