Exemple #1
0
func getThumbnailImg(imgUrl *url.URL) image.Image {
	srcImg, err := util.LoadImage(imgUrl.Path)
	if err != nil {
		util.Logln("[GIN] LoadImage error:" + err.Error())
		return nil
	}

	imgValues, _ := url.ParseQuery(imgUrl.RawQuery)
	size := imgValues.Get("s")
	if size == "" {
		return srcImg
	} else {
		dstWidth, dstHeight := util.ParseImgArg(size)
		if dstHeight == 0 && dstWidth == 0 {
			return srcImg
		}

		var thumbImg image.Image
		if dstHeight == 0 || dstWidth == 0 {
			thumbImg = util.ThumbnailSimple(dstWidth, dstHeight, srcImg)
		} else {
			thumbImg = util.ThumbnailCrop(dstWidth, dstHeight, srcImg)
		}

		go util.WriteCache(imgUrl.String(), thumbImg)
		return thumbImg
	}
}
Exemple #2
0
func main() {
	defer func() {
		if err := recover(); err != nil {
			util.Logln(fmt.Sprintf("recover:%v", err))
		}
	}()

	gin.SetMode(gin.ReleaseMode)

	router := gin.New()
	router.Use(util.Counter(), gin.LoggerWithWriter(util.GetLogBuf()), gin.Recovery())
	router.GET("/*path", imageHandler)
	router.Run(":" + util.ServePort)
}
Exemple #3
0
func isSpider(context *gin.Context) bool {
	req := context.Request
	if req == nil {
		return true
	}

	ua := req.UserAgent()
	for _, spider := range util.Spiders {
		if strings.Contains(ua, spider) {
			util.Logln("[GIN] spider skip:" + ua)
			return true
		}
	}
	return false
}