1
0
forked from sneak/util

add function +func IsValidURL(url string) bool {

This commit is contained in:
2024-06-01 15:37:51 -07:00
parent b9756ed8c4
commit 9302c14a6c
3 changed files with 11 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import (
"regexp"
"time"
"github.com/asaskevich/govalidator"
"github.com/hako/durafmt"
)
@@ -24,6 +25,10 @@ func TimeDiffHuman(first time.Time, second time.Time) string {
}
}
func IsValidURL(url string) bool {
return govalidator.IsURL(url) && (govalidator.IsRequestURL(url) || govalidator.IsRequestURI(url))
}
// Does anyone else use uints for things that are always >=0 like counts and
func TimeDiffAbsSeconds(first time.Time, second time.Time) uint {
return uint(math.Abs(first.Sub(second).Truncate(time.Second).Seconds()))