File: url.go

package info (click to toggle)
golang-github-coreos-go-oidc 0.0~git20160926.0.16c5ecc-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 436 kB
  • sloc: sh: 40; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 552 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package http

import (
	"errors"
	"net/url"
)

// ParseNonEmptyURL checks that a string is a parsable URL which is also not empty
// since `url.Parse("")` does not return an error. Must contian a scheme and a host.
func ParseNonEmptyURL(u string) (*url.URL, error) {
	if u == "" {
		return nil, errors.New("url is empty")
	}

	ur, err := url.Parse(u)
	if err != nil {
		return nil, err
	}

	if ur.Scheme == "" {
		return nil, errors.New("url scheme is empty")
	}

	if ur.Host == "" {
		return nil, errors.New("url host is empty")
	}

	return ur, nil
}