wangshan 6 miesięcy temu
rodzic
commit
b39c723b5f
1 zmienionych plików z 7 dodań i 8 usunięć
  1. 7 8
      gocaptcha/start.go

+ 7 - 8
gocaptcha/start.go

@@ -23,7 +23,7 @@ var TextCharacters = []rune("ACDEFGHJKLMNPQRSTUVWXY2456789")
 
 // 初始化字体文件
 func InitCaptcha() {
-	err := SetFontPath("./fonts/")
+	err := SetFontPath("app.yhyue.com/moapp/jybase/gocaptcha/fonts/")
 	if err != nil {
 		log.Println(err)
 	}
@@ -51,7 +51,7 @@ func RandLightColor(n int) color.RGBA {
 	return color.RGBA{R: uint8(red), G: uint8(green), B: uint8(blue), A: a}
 }
 
-func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *http.Request) (err error) {
+func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *http.Request) {
 	code := RandText(4)
 	log.Println(code)
 	cacheKey := fmt.Sprintf("captcha_times_%s", sess.Id())
@@ -93,17 +93,16 @@ func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *
 			DrawText(NewTwistTextDrawer(66, 18, 0.04), code).
 			DrawBlur(NewGaussianBlur(), 2, 0.44)
 	}
+	if captchaImage.Error != nil {
+		log.Println(captchaImage.Error)
+		return
+	}
 	if times == 0 {
 		ttl = 24 * 60 * 60
 	}
 	//计次
 	times++
 	redis.Put("other", cacheKey, times, int(ttl))
-	if captchaImage.Error != nil {
-		log.Println(captchaImage.Error)
-		err = captchaImage.Error
-		return
-	}
 	sess.Set(checkCode, code)
-	return captchaImage.Encode(w, ImageFormatJpeg)
+	_ = captchaImage.Encode(w, ImageFormatJpeg)
 }