File: main.go

package info (click to toggle)
golang-github-bifurcation-mint 0.0~git20200214.93c820e-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 632 kB
  • sloc: makefile: 3
file content (50 lines) | stat: -rw-r--r-- 898 bytes parent folder | download
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
package main

import (
	"flag"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"os"

	"github.com/bifurcation/mint"
)

var url string
var dontValidate bool

func main() {
	c := mint.Config{}

	url := flag.String("url", "https://localhost:4430", "URL to send request")
	flag.BoolVar(&dontValidate, "dontvalidate", false, "don't validate certs")
	flag.Parse()
	if dontValidate {
		c.InsecureSkipVerify = true
	}

	mintdial := func(network, addr string) (net.Conn, error) {
		return mint.Dial(network, addr, &c)
	}

	tr := &http.Transport{
		DialTLS:            mintdial,
		DisableCompression: true,
	}
	client := &http.Client{Transport: tr}

	response, err := client.Get(*url)
	if err != nil {
		fmt.Println("err:", err)
		return
	}
	defer response.Body.Close()

	contents, err := ioutil.ReadAll(response.Body)
	if err != nil {
		fmt.Printf("%s", err)
		os.Exit(1)
	}
	fmt.Printf("%s\n", string(contents))
}