1、controller中注解说明
// Login godoc // // @Summary Login an account // @Description get string by ID // @Tags Register User // @Accept json // @Produce json // @Param username formData string true "用户名" // @Param password formData string true "用户密码" // @Success 200 {object} model.AdminUsers // @Failure 400 {string} json "{"err": err.Error()}" // @Router /api/v1/login/{username}/{password} [post] func (api *AuthController) Login(c *gin.Context) { // 初始化参数结构体 loginForm := form.LoginForm() // 绑定参数并使用验证器验证参数 if err := validator.CheckPostParams(c, &loginForm); err != nil { return } // 实际业务调用 result, err := service.NewAuthService().Login(loginForm.UserName, loginForm.PassWord) // 根据业务返回值判断业务成功 OR 失败 if err != nil { api.Err(c, err) return } //r. api.Success(c, result) }
@Summary 对应Yapi中的接口名称 @Description 对应备注 @Tags 对应分组 @Accept 请求参数类型 @Param 参数 @Router 接口地址