add function +func IsValidURL(url string) bool {

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

5
go.mod
View File

@ -2,4 +2,7 @@ module sneak.berlin/go/util
go 1.14 go 1.14
require github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4 require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4
)

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4 h1:60gBOooTSmNtrqNaRvrDbi8VAne0REaek2agjnITKSw= github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4 h1:60gBOooTSmNtrqNaRvrDbi8VAne0REaek2agjnITKSw=
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE= github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE=

View File

@ -8,6 +8,7 @@ import (
"regexp" "regexp"
"time" "time"
"github.com/asaskevich/govalidator"
"github.com/hako/durafmt" "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 // Does anyone else use uints for things that are always >=0 like counts and
func TimeDiffAbsSeconds(first time.Time, second time.Time) uint { func TimeDiffAbsSeconds(first time.Time, second time.Time) uint {
return uint(math.Abs(first.Sub(second).Truncate(time.Second).Seconds())) return uint(math.Abs(first.Sub(second).Truncate(time.Second).Seconds()))