Documentation ¶
Overview ¶
Copyright 2019-2020 Axetroy. All rights reserved. MIT license.
Copyright 2019-2020 Axetroy. All rights reserved. MIT license.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var File = router.Handler(func(c router.Context) { filename := c.Param("filename") filePath := path.Join(config2.Upload.Path, config2.Upload.File.Path, filename) if !fs.PathExists(filePath) { http.NotFound(c.Writer(), c.Request()) return } http.ServeFile(c.Writer(), c.Request(), filePath) })
View Source
var Image = router.Handler(func(c router.Context) { var ( img image.Image err error filename = c.Param("filename") file *os.File query Query ) originImagePath := path.Join(config.Upload.Path, config.Upload.Image.Path, filename) if !fs.PathExists(originImagePath) { http.NotFound(c.Writer(), c.Request()) return } defer func() { if err != nil { http.Error(c.Writer(), err.Error(), http.StatusInternalServerError) } }() if err = c.ShouldBindQuery(&query); err != nil { return } if err = validator.ValidateStruct(query); err != nil { return } defer func() { if err != nil { http.ServeFile(c.Writer(), c.Request(), originImagePath) } }() if query.Scale != nil { extname := strings.ToLower(path.Ext(filename)) if file, err = os.Open(originImagePath); err != nil { return } defer func() { if err = file.Close(); err != nil { return } }() if img, err = DecodeImage(file); err != nil { return } c.Header("Content-Type", mime.TypeByExtension(extname)) if err = EncodeImage(&img, file, c.Writer(), query); err != nil { return } return } if query.Width != nil || query.Height != nil { extname := strings.ToLower(path.Ext(filename)) if file, err = os.Open(originImagePath); err != nil { return } defer func() { if err = file.Close(); err != nil { return } }() if img, err = DecodeImage(file); err != nil { return } c.Header("Content-Type", mime.TypeByExtension(extname)) if err = EncodeImage(&img, file, c.Writer(), query); err != nil { return } return } http.ServeFile(c.Writer(), c.Request(), originImagePath) })
Functions ¶
func DecodeImage ¶ added in v0.7.0
将文件解析为 img
Types ¶
Click to show internal directories.
Click to hide internal directories.