Validate URL with standard package in GO

Yep, url.ParseRequestURI returns an error if the URL is not valid, not an absolute url, etc etc. url.Parse returns valid on almost anything…

import "net/url"

...


u, err := url.ParseRequestURI("http://google.com/")
if err != nil {
   panic(err)
}

The above example will not fail, but these will:

u, err := url.ParseRequestURI("http//google.com")

u, err := url.ParseRequestURI("google.com")

u, err := url.ParseRequestURI("/foo/bar")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)