-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
51 lines (43 loc) · 880 Bytes
/
client.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
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"net/http"
"path/filepath"
)
func main() {
// Read CA certificate
caFile, _ := filepath.Abs("../certificate/x509/ecdsa/certs/ca.pem")
rootPem, err := ioutil.ReadFile(caFile)
if err != nil {
fmt.Printf("Err: %s\n", err)
return
}
roots := x509.NewCertPool()
if ok := roots.AppendCertsFromPEM(rootPem); !ok {
fmt.Printf("Err: failed to parse root certificate")
return
}
config := tls.Config{
RootCAs: roots,
}
tr := http.Transport{
TLSClientConfig: &config,
}
client := http.Client{
Transport: &tr,
}
res, err := client.Get("https://127.0.0.1:3000")
if err != nil {
log.Printf("[ERROR] %s", err)
}
defer res.Body.Close()
buf, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Printf("[ERROR] %s", err)
}
log.Printf("[INFO] response: %q", string(buf))
}