fonchain-fiee/pkg/service/redirect/redirect.go

34 lines
675 B
Go
Raw Normal View History

2025-02-20 08:24:49 +00:00
package redirect
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
2025-02-20 08:38:16 +00:00
// ToRedirectRealUrl 重定向到指定位置
2025-02-20 08:24:49 +00:00
func ToRedirectRealUrl(c *gin.Context) {
realUrl := c.Query("base_redirect_url")
if realUrl == "" {
service.Error(c, errors.New("not real url"))
return
}
c.Redirect(http.StatusMovedPermanently, realUrl)
}
2025-02-20 08:38:16 +00:00
// ToRedirectRealUrlAdnRand 重定向到指定位置
2025-02-20 08:24:49 +00:00
func ToRedirectRealUrlAdnRand(c *gin.Context) {
realUrl := c.Query("base_redirect_url")
if realUrl == "" {
service.Error(c, errors.New("not real url"))
return
}
2025-02-20 08:38:16 +00:00
c.Redirect(http.StatusMovedPermanently, realUrl+fmt.Sprintf("?time=%d", time.Now().Unix()))
2025-02-20 08:24:49 +00:00
}