add function +func IsValidURL(url string) bool {
This commit is contained in:
parent
b9756ed8c4
commit
9302c14a6c
5
go.mod
5
go.mod
|
@ -2,4 +2,7 @@ module sneak.berlin/go/util
|
|||
|
||||
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
2
go.sum
|
@ -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/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE=
|
||||
|
|
5
util.go
5
util.go
|
@ -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()))
|
||||
|
|
Loading…
Reference in New Issue