Skip to content

Commit 2ae7865

Browse files
authored
Bump go module version to v2 (mccutchen#58)
1 parent 0b04b2e commit 2ae7865

File tree

7 files changed

+79
-43
lines changed

7 files changed

+79
-43
lines changed

README.md

+46-36
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A reasonably complete and well-tested golang port of [Kenneth Reitz][kr]'s
44
[httpbin][httpbin-org] service, with zero dependencies outside the go stdlib.
55

6-
[![GoDoc](https://godoc.org/github.com/mccutchen/go-httpbin?status.svg)](https://godoc.org/github.com/mccutchen/go-httpbin)
6+
[![GoDoc](https://godoc.org/github.com/mccutchen/go-httpbin?status.svg)](https://pkg.go.dev/github.com/mccutchen/go-httpbin)
77
[![Build Status](https://travis-ci.org/mccutchen/go-httpbin.svg?branch=master)](http://travis-ci.org/mccutchen/go-httpbin)
88
[![Coverage](https://codecov.io/gh/mccutchen/go-httpbin/branch/master/graph/badge.svg)](https://codecov.io/gh/mccutchen/go-httpbin)
99

@@ -14,81 +14,91 @@ Run as a standalone binary, configured by command line flags or environment
1414
variables:
1515

1616
```
17-
$ go-httpbin -help
17+
$ go-httpbin --help
1818
Usage of go-httpbin:
1919
-host string
2020
Host to listen on (default "0.0.0.0")
21-
-port int
22-
Port to listen on (default 8080)
2321
-https-cert-file string
24-
HTTPS certificate file
22+
HTTPS Server certificate file
2523
-https-key-file string
26-
HTTPS private key file
24+
HTTPS Server private key file
2725
-max-body-size int
28-
Maximum size of request or response, in bytes (default 1048576)
26+
Maximum size of request or response, in bytes (default 1048576)
2927
-max-duration duration
30-
Maximum duration a response may take (default 10s)
28+
Maximum duration a response may take (default 10s)
29+
-port int
30+
Port to listen on (default 8080)
31+
```
3132

3233
Examples:
33-
# Run http server
34-
$ go-httpbin -host 127.0.0.1 -port 8081
35-
36-
# Run https server
3734

38-
# Generate .crt and .key files
39-
$ openssl genrsa -out server.key 2048
40-
$ openssl ecparam -genkey -name secp384r1 -out server.key
41-
$ openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
35+
```bash
36+
# Run http server
37+
$ go-httpbin -host 127.0.0.1 -port 8081
4238

43-
$ go-httpbin -host 127.0.0.1 -port 8081 -https-cert-file ./server.crt -https-key-file ./server.key
39+
# Run https server
40+
$ openssl genrsa -out server.key 2048
41+
$ openssl ecparam -genkey -name secp384r1 -out server.key
42+
$ openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
43+
$ go-httpbin -host 127.0.0.1 -port 8081 -https-cert-file ./server.crt -https-key-file ./server.key
4444
```
4545

4646
Docker images are published to [Docker Hub][docker-hub]:
4747

48-
```
48+
```bash
4949
# Run http server
5050
$ docker run -P mccutchen/go-httpbin
5151

5252
# Run https server
5353
$ docker run -e HTTPS_CERT_FILE='/tmp/server.crt' -e HTTPS_KEY_FILE='/tmp/server.key' -p 8080:8080 -v /tmp:/tmp mccutchen/go-httpbin
5454
```
5555

56-
The `github.com/mccutchen/go-httpbin/httpbin` package can also be used as a
56+
The `github.com/mccutchen/go-httpbin/httpbin/v2` package can also be used as a
5757
library for testing an applications interactions with an upstream HTTP service,
5858
like so:
5959

6060
```go
6161
package httpbin_test
6262

6363
import (
64-
"net/http"
65-
"net/http/httptest"
66-
"testing"
67-
"time"
64+
"net/http"
65+
"net/http/httptest"
66+
"os"
67+
"testing"
68+
"time"
6869

69-
"github.com/mccutchen/go-httpbin/httpbin"
70+
"github.com/mccutchen/go-httpbin/v2/httpbin"
7071
)
7172

7273
func TestSlowResponse(t *testing.T) {
73-
svc := httpbin.New()
74-
srv := httptest.NewServer(svc.Handler())
75-
defer srv.Close()
76-
77-
client := http.Client{
78-
Timeout: time.Duration(1 * time.Second),
79-
}
80-
_, err := client.Get(srv.URL + "/delay/10")
81-
if err == nil {
82-
t.Fatal("expected timeout error")
83-
}
74+
app := httpbin.New()
75+
testServer := httptest.NewServer(app.Handler())
76+
defer testServer.Close()
77+
78+
client := http.Client{
79+
Timeout: time.Duration(1 * time.Second),
80+
}
81+
82+
_, err := client.Get(testServer.URL + "/delay/10")
83+
if !os.IsTimeout(err) {
84+
t.Fatalf("expected timeout error, got %s", err)
85+
}
8486
}
8587
```
8688

8789

8890
## Installation
8991

92+
To add go-httpbin to an existing golang project:
93+
94+
```
95+
go get -u github.com/mccutchen/go-httpbin/v2
96+
```
97+
98+
To install the `go-httpbin` binary:
99+
90100
```
91-
go get github.com/mccutchen/go-httpbin/cmd/go-httpbin
101+
go install github.com/mccutchen/go-httpbin/v2/cmd/go-httpbin
92102
```
93103

94104

cmd/go-httpbin/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import "github.com/mccutchen/go-httpbin/cmd/maincmd"
3+
import "github.com/mccutchen/go-httpbin/v2/cmd/maincmd"
44

55
func main() {
66
maincmd.Main()

cmd/go_httpbin/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import "github.com/mccutchen/go-httpbin/cmd/maincmd"
3+
import "github.com/mccutchen/go-httpbin/v2/cmd/maincmd"
44

55
func main() {
66
maincmd.Main()

cmd/maincmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"syscall"
1414
"time"
1515

16-
"github.com/mccutchen/go-httpbin/httpbin"
16+
"github.com/mccutchen/go-httpbin/v2/httpbin"
1717
)
1818

1919
const defaultHost = "0.0.0.0"

example_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package httpbin_test
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"os"
7+
"testing"
8+
"time"
9+
10+
"github.com/mccutchen/go-httpbin/v2/httpbin"
11+
)
12+
13+
func TestSlowResponse(t *testing.T) {
14+
app := httpbin.New()
15+
testServer := httptest.NewServer(app.Handler())
16+
defer testServer.Close()
17+
18+
client := http.Client{
19+
Timeout: time.Duration(1 * time.Second),
20+
}
21+
22+
_, err := client.Get(testServer.URL + "/delay/10")
23+
if !os.IsTimeout(err) {
24+
t.Fatalf("expected timeout error, got %s", err)
25+
}
26+
}

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/mccutchen/go-httpbin
1+
module github.com/mccutchen/go-httpbin/v2
22

3-
go 1.12
3+
go 1.16

httpbin/handlers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"strings"
1212
"time"
1313

14-
"github.com/mccutchen/go-httpbin/httpbin/assets"
15-
"github.com/mccutchen/go-httpbin/httpbin/digest"
14+
"github.com/mccutchen/go-httpbin/v2/httpbin/assets"
15+
"github.com/mccutchen/go-httpbin/v2/httpbin/digest"
1616
)
1717

1818
var acceptedMediaTypes = []string{

0 commit comments

Comments
 (0)