diff --git a/url.go b/url.go index c667e7c..f699868 100644 --- a/url.go +++ b/url.go @@ -13,6 +13,8 @@ import ( ikurl "github.com/imagekit-developer/imagekit-go/url" ) +const DEFAULT_TIMESTAMP = 9999999999 + // Url generates url from UrlParam func (ik *ImageKit) Url(params ikurl.UrlParam) (string, error) { var resultUrl string @@ -81,18 +83,29 @@ func (ik *ImageKit) Url(params ikurl.UrlParam) (string, error) { now = params.UnixTime() } - var expires = strconv.FormatInt(now+int64(params.ExpireSeconds), 10) + var expires string + if params.ExpireSeconds > 0 { + expires = strconv.FormatInt(now+int64(params.ExpireSeconds), 10) + } else { + expires = strconv.Itoa(DEFAULT_TIMESTAMP) + } var path = strings.Replace(resultUrl, endpoint, "", 1) - path = path + expires mac := hmac.New(sha1.New, []byte(ik.Config.Cloud.PrivateKey)) mac.Write([]byte(path)) signature := hex.EncodeToString(mac.Sum(nil)) - if strings.Index(resultUrl, "?") > -1 { - resultUrl = resultUrl + "&" + fmt.Sprintf("ik-t=%s&ik-s=%s", expires, signature) + if params.ExpireSeconds > 0 && params.ExpireSeconds != DEFAULT_TIMESTAMP { + resultUrl = resultUrl + "&" + fmt.Sprintf("ik-t=%s&ik-s=%s", expires, signature) + } else { + resultUrl = resultUrl + "&" + fmt.Sprintf("ik-s=%s", signature) + } } else { - resultUrl = resultUrl + "?" + fmt.Sprintf("ik-t=%s&ik-s=%s", expires, signature) + if params.ExpireSeconds > 0 && params.ExpireSeconds != DEFAULT_TIMESTAMP { + resultUrl = resultUrl + "?" + fmt.Sprintf("ik-t=%s&ik-s=%s", expires, signature) + } else { + resultUrl = resultUrl + "?" + fmt.Sprintf("ik-s=%s", signature) + } } }