既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
gin+dchest/captcha
package main
import (
"bytes"
"fmt"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
"net/http"
"path"
"strings"
"time"
)
type CaptchaResponse struct {
CaptchaId string `json:"captchaId"` //验证码Id
ImageUrl string `json:"imageUrl"` //验证码图片url
}
func main() {
r := gin.Default()
//1.获取验证码
//http://localhost:8080/captcha
r.GET("/captcha", func(c *gin.Context) {
length := captcha.DefaultLen
captchaId := captcha.NewLen(length)
var captcha CaptchaResponse
captcha.CaptchaId = captchaId
captcha.ImageUrl = "/captcha/" + captchaId + ".png"
c.JSON(http.StatusOK, captcha)
})
//2.获取验证码图片
//http://localhost:8080/captcha/gHEIwh7nWreTFb53MkVk.png
r.GET("/captcha/:captchaId", func(c *gin.Context) {
captchaId := c.Param("captchaId")
fmt.Println("GetCaptchaPng : " + captchaId)
ServeHTTP(c.Writer, c.Request)
})
//3.验证
//http://localhost:8080/verify/dVCqYbq7r2olKZfEtTvo/647489
r.GET("/verify/:captchaId/:value", func(c *gin.Context) {
captchaId := c.Param("captchaId")
value := c.Param("value")
if captchaId == "" || value == "" {
c.String(http.StatusBadRequest, "参数错误")
}
if captcha.VerifyString(captchaId, value) {
c.JSON(http.StatusOK, "验证成功")
} else {
c.JSON(http.StatusOK, "验证失败")
}
})
r.Run()
}
func ServeHTTP(w http.ResponseWriter, r *http.Request) {
dir, file := path.Split(r.URL.Path)
ext := path.Ext(file)
id := file[:len(file)-len(ext)]
fmt.Println("file : " + file)
fmt.Println("ext : " + ext)
fmt.Println("id : " + id)
if ext == "" || id == "" {
http.NotFound(w, r)
return
}
fmt.Println("reload : " + r.FormValue("reload"))
![img](https://img-blog.csdnimg.cn/img_convert/70ef4ee0ac70a5e4978cf7f62bf0a149.png)
![img](https://img-blog.csdnimg.cn/img_convert/d67d3f6cdc41dc389e12137266f21890.png)
![img](https://img-blog.csdnimg.cn/img_convert/bd15709afa87b8bdae0154834463d207.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618658159)**
源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618658159)**