pkg/util/{ip.go,url.go}: Fix some golint issues
See, $ gometalinter --vendor --deadline 10m --disable-all --enable=golint ./... ip.go:8:6⚠️ func SplitIpPort should be SplitIPPort (golint) url.go:14:6⚠️ func NewUrlQueryReader should be NewURLQueryReader (golint) url.go:9:6⚠️ type UrlQueryReader should be URLQueryReader (golint) url.go:37:6⚠️ func JoinUrlFragments should be JoinURLFragments (golint)
This commit is contained in:
+2
-2
@@ -4,8 +4,8 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
// SplitIpPort splits the ip string and port.
|
||||
func SplitIpPort(ipStr string, portDefault string) (ip string, port string, err error) {
|
||||
// SplitIPPort splits the ip string and port.
|
||||
func SplitIPPort(ipStr string, portDefault string) (ip string, port string, err error) {
|
||||
ipAddr := net.ParseIP(ipStr)
|
||||
|
||||
if ipAddr == nil {
|
||||
|
||||
+5
-5
@@ -6,10 +6,10 @@ import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestSplitIpPort(t *testing.T) {
|
||||
func TestSplitIPPort(t *testing.T) {
|
||||
|
||||
Convey("When parsing an IPv4 without explicit port", t, func() {
|
||||
ip, port, err := SplitIpPort("1.2.3.4", "5678")
|
||||
ip, port, err := SplitIPPort("1.2.3.4", "5678")
|
||||
|
||||
So(err, ShouldEqual, nil)
|
||||
So(ip, ShouldEqual, "1.2.3.4")
|
||||
@@ -17,7 +17,7 @@ func TestSplitIpPort(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When parsing an IPv6 without explicit port", t, func() {
|
||||
ip, port, err := SplitIpPort("::1", "5678")
|
||||
ip, port, err := SplitIPPort("::1", "5678")
|
||||
|
||||
So(err, ShouldEqual, nil)
|
||||
So(ip, ShouldEqual, "::1")
|
||||
@@ -25,7 +25,7 @@ func TestSplitIpPort(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When parsing an IPv4 with explicit port", t, func() {
|
||||
ip, port, err := SplitIpPort("1.2.3.4:56", "78")
|
||||
ip, port, err := SplitIPPort("1.2.3.4:56", "78")
|
||||
|
||||
So(err, ShouldEqual, nil)
|
||||
So(ip, ShouldEqual, "1.2.3.4")
|
||||
@@ -33,7 +33,7 @@ func TestSplitIpPort(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When parsing an IPv6 with explicit port", t, func() {
|
||||
ip, port, err := SplitIpPort("[::1]:56", "78")
|
||||
ip, port, err := SplitIPPort("[::1]:56", "78")
|
||||
|
||||
So(err, ShouldEqual, nil)
|
||||
So(ip, ShouldEqual, "::1")
|
||||
|
||||
+8
-8
@@ -5,26 +5,26 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// UrlQueryReader is a URL query type.
|
||||
type UrlQueryReader struct {
|
||||
// URLQueryReader is a URL query type.
|
||||
type URLQueryReader struct {
|
||||
values url.Values
|
||||
}
|
||||
|
||||
// NewUrlQueryReader parses a raw query and returns it as a UrlQueryReader type.
|
||||
func NewUrlQueryReader(urlInfo *url.URL) (*UrlQueryReader, error) {
|
||||
// NewURLQueryReader parses a raw query and returns it as a URLQueryReader type.
|
||||
func NewURLQueryReader(urlInfo *url.URL) (*URLQueryReader, error) {
|
||||
u, err := url.ParseQuery(urlInfo.RawQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &UrlQueryReader{
|
||||
return &URLQueryReader{
|
||||
values: u,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Get parse parameters from an URL. If the parameter does not exist, it returns
|
||||
// the default value.
|
||||
func (r *UrlQueryReader) Get(name string, def string) string {
|
||||
func (r *URLQueryReader) Get(name string, def string) string {
|
||||
val := r.values[name]
|
||||
if len(val) == 0 {
|
||||
return def
|
||||
@@ -33,8 +33,8 @@ func (r *UrlQueryReader) Get(name string, def string) string {
|
||||
return val[0]
|
||||
}
|
||||
|
||||
// JoinUrlFragments joins two URL fragments into only one URL string.
|
||||
func JoinUrlFragments(a, b string) string {
|
||||
// JoinURLFragments joins two URL fragments into only one URL string.
|
||||
func JoinURLFragments(a, b string) string {
|
||||
aslash := strings.HasSuffix(a, "/")
|
||||
bslash := strings.HasPrefix(b, "/")
|
||||
|
||||
|
||||
+10
-10
@@ -1,60 +1,60 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func TestUrl(t *testing.T) {
|
||||
|
||||
Convey("When joining two urls where right hand side is empty", t, func() {
|
||||
result := JoinUrlFragments("http://localhost:8080", "")
|
||||
result := JoinURLFragments("http://localhost:8080", "")
|
||||
|
||||
So(result, ShouldEqual, "http://localhost:8080")
|
||||
})
|
||||
|
||||
Convey("When joining two urls where right hand side is empty and lefthand side has a trailing slash", t, func() {
|
||||
result := JoinUrlFragments("http://localhost:8080/", "")
|
||||
result := JoinURLFragments("http://localhost:8080/", "")
|
||||
|
||||
So(result, ShouldEqual, "http://localhost:8080/")
|
||||
})
|
||||
|
||||
Convey("When joining two urls where neither has a trailing slash", t, func() {
|
||||
result := JoinUrlFragments("http://localhost:8080", "api")
|
||||
result := JoinURLFragments("http://localhost:8080", "api")
|
||||
|
||||
So(result, ShouldEqual, "http://localhost:8080/api")
|
||||
})
|
||||
|
||||
Convey("When joining two urls where lefthand side has a trailing slash", t, func() {
|
||||
result := JoinUrlFragments("http://localhost:8080/", "api")
|
||||
result := JoinURLFragments("http://localhost:8080/", "api")
|
||||
|
||||
So(result, ShouldEqual, "http://localhost:8080/api")
|
||||
})
|
||||
|
||||
Convey("When joining two urls where righthand side has preceding slash", t, func() {
|
||||
result := JoinUrlFragments("http://localhost:8080", "/api")
|
||||
result := JoinURLFragments("http://localhost:8080", "/api")
|
||||
|
||||
So(result, ShouldEqual, "http://localhost:8080/api")
|
||||
})
|
||||
|
||||
Convey("When joining two urls where righthand side has trailing slash", t, func() {
|
||||
result := JoinUrlFragments("http://localhost:8080", "api/")
|
||||
result := JoinURLFragments("http://localhost:8080", "api/")
|
||||
|
||||
So(result, ShouldEqual, "http://localhost:8080/api/")
|
||||
})
|
||||
|
||||
Convey("When joining two urls where lefthand side has a trailing slash and righthand side has preceding slash", t, func() {
|
||||
result := JoinUrlFragments("http://localhost:8080/", "/api/")
|
||||
result := JoinURLFragments("http://localhost:8080/", "/api/")
|
||||
|
||||
So(result, ShouldEqual, "http://localhost:8080/api/")
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewUrlQueryReader(t *testing.T) {
|
||||
func TestNewURLQueryReader(t *testing.T) {
|
||||
u, _ := url.Parse("http://www.abc.com/foo?bar=baz&bar2=baz2")
|
||||
uqr, _ := NewUrlQueryReader(u)
|
||||
uqr, _ := NewURLQueryReader(u)
|
||||
|
||||
Convey("when trying to retrieve the first query value", t, func() {
|
||||
result := uqr.Get("bar", "foodef")
|
||||
|
||||
Reference in New Issue
Block a user