forked from snowflakedb/gosnowflake
/
util.go
63 lines (55 loc) · 1.3 KB
/
util.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017 Snowflake Computing Inc. All right reserved.
package gosnowflake
import (
"database/sql/driver"
"fmt"
"net/url"
"time"
)
// integer min
func intMin(a, b int) int {
if a < b {
return a
}
return b
}
// integer max
func intMax(a, b int) int {
if a > b {
return a
}
return b
}
// time.Duration max
func durationMax(d1, d2 time.Duration) time.Duration {
if d1-d2 > 0 {
return d1
}
return d2
}
// time.Duration min
func durationMin(d1, d2 time.Duration) time.Duration {
if d1-d2 < 0 {
return d1
}
return d2
}
// toNamedValues converts a slice of driver.Value to a slice of driver.NamedValue for Go 1.8 SQL package
func toNamedValues(values []driver.Value) []driver.NamedValue {
namedValues := make([]driver.NamedValue, len(values))
for idx, value := range values {
namedValues[idx] = driver.NamedValue{Name: "", Ordinal: idx + 1, Value: value}
}
return namedValues
}
//proxyURL constructs a URL string including proxy info. No https proxy is supported.
func proxyURL(host string, port int, user string, password string) (*url.URL, error) {
if host != "" && port != 0 {
proxyAuth := ""
if user != "" || password != "" {
proxyAuth = fmt.Sprintf("%s:%s@", user, password)
}
return url.Parse(fmt.Sprintf("http://%v%v:%v", proxyAuth, host, port))
}
return nil, nil
}