forked from vladimirvivien/gowfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.go
57 lines (46 loc) · 1.25 KB
/
configuration.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
package gowfs
import "fmt"
import "errors"
import "time"
import "net/url"
import "os/user"
const WebHdfsVer string = "/webhdfs/v1"
type Configuration struct {
Addr string // host:port
UseHTTPS bool
BasePath string // initial base path to be appended
User string // user.name to use to connect
ConnectionTimeout time.Duration
DisableKeepAlives bool
DisableCompression bool
ResponseHeaderTimeout time.Duration
MaxIdleConnsPerHost int
}
func NewConfiguration() *Configuration {
return &Configuration{
ConnectionTimeout: time.Second * 17,
DisableKeepAlives: false,
DisableCompression: true,
ResponseHeaderTimeout: time.Second * 17,
}
}
func (conf *Configuration) GetNameNodeUrl() (*url.URL, error) {
if &conf.Addr == nil {
return nil, errors.New("Configuration namenode address not set.")
}
scheme := "http"
if conf.UseHTTPS {
scheme = "https"
}
urlStr := fmt.Sprintf("%s://%s%s%s", scheme, conf.Addr, WebHdfsVer, conf.BasePath)
if &conf.User == nil || len(conf.User) == 0 {
u, _ := user.Current()
conf.User = u.Username
}
urlStr = urlStr + "?user.name=" + conf.User
u, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
return u, nil
}