操作图片显示 如果用的是oss存储,这style是avatar、cover可选项
(img string, style ...string)
| 595 | // 操作图片显示 |
| 596 | // 如果用的是oss存储,这style是avatar、cover可选项 |
| 597 | func ShowImg(img string, style ...string) (url string) { |
| 598 | img = strings.ReplaceAll(img, "\\", "/") |
| 599 | if strings.HasPrefix(img, "https://") || strings.HasPrefix(img, "http://") { |
| 600 | return img |
| 601 | } |
| 602 | img = "/" + strings.TrimLeft(img, "./") |
| 603 | switch StoreType { |
| 604 | case StoreOss: |
| 605 | s := "" |
| 606 | if len(style) > 0 && strings.TrimSpace(style[0]) != "" { |
| 607 | s = "/" + style[0] |
| 608 | } |
| 609 | url = strings.TrimRight(beego.AppConfig.String("oss::Domain"), "/ ") + img + s |
| 610 | case StoreLocal: |
| 611 | url = img |
| 612 | } |
| 613 | return |
| 614 | } |
| 615 | |
| 616 | // Substr returns the substr from start to length. |
| 617 | func Substr(s string, length int) string { |
no outgoing calls
no test coverage detected