forked from SkycoinProject/dmsg-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmsg-http.go
More file actions
34 lines (30 loc) · 899 Bytes
/
dmsg-http.go
File metadata and controls
34 lines (30 loc) · 899 Bytes
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
package dmsghttp
import (
"net/http"
"time"
"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/dmsg/disc"
)
// DefaultDMSGClient creates http Client using default discovery service
func DefaultDMSGClient(pubKey cipher.PubKey, secKey cipher.SecKey) *http.Client {
// TODO check is there better way to handle pub and sec key
return DMSGClient(DefaultDiscoveryURL, pubKey, secKey)
}
// DMSGClient creates http Client using provided discovery service and public / secret keypair
func DMSGClient(dicoveryAddress string, pubKey cipher.PubKey, secKey cipher.SecKey) *http.Client {
transport := DMSGTransport{
Discovery: disc.NewHTTP(dicoveryAddress),
PubKey: pubKey,
SecKey: secKey,
}
timeout, err := time.ParseDuration("30s")
if err != nil {
//TODO add log
timeout = time.Minute
}
return &http.Client{
Transport: transport,
Jar: nil,
Timeout: timeout,
}
}