Skip to content
Snippets Groups Projects
Unverified Commit 2ae7865c authored by Will McCutchen's avatar Will McCutchen Committed by GitHub
Browse files

Bump go module version to v2 (#58)

parent 0b04b2e5
Branches
Tags v2.2.0
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
A reasonably complete and well-tested golang port of [Kenneth Reitz][kr]'s A reasonably complete and well-tested golang port of [Kenneth Reitz][kr]'s
[httpbin][httpbin-org] service, with zero dependencies outside the go stdlib. [httpbin][httpbin-org] service, with zero dependencies outside the go stdlib.
[![GoDoc](https://godoc.org/github.com/mccutchen/go-httpbin?status.svg)](https://godoc.org/github.com/mccutchen/go-httpbin) [![GoDoc](https://godoc.org/github.com/mccutchen/go-httpbin?status.svg)](https://pkg.go.dev/github.com/mccutchen/go-httpbin)
[![Build Status](https://travis-ci.org/mccutchen/go-httpbin.svg?branch=master)](http://travis-ci.org/mccutchen/go-httpbin) [![Build Status](https://travis-ci.org/mccutchen/go-httpbin.svg?branch=master)](http://travis-ci.org/mccutchen/go-httpbin)
[![Coverage](https://codecov.io/gh/mccutchen/go-httpbin/branch/master/graph/badge.svg)](https://codecov.io/gh/mccutchen/go-httpbin) [![Coverage](https://codecov.io/gh/mccutchen/go-httpbin/branch/master/graph/badge.svg)](https://codecov.io/gh/mccutchen/go-httpbin)
...@@ -14,38 +14,38 @@ Run as a standalone binary, configured by command line flags or environment ...@@ -14,38 +14,38 @@ Run as a standalone binary, configured by command line flags or environment
variables: variables:
``` ```
$ go-httpbin -help $ go-httpbin --help
Usage of go-httpbin: Usage of go-httpbin:
-host string -host string
Host to listen on (default "0.0.0.0") Host to listen on (default "0.0.0.0")
-port int
Port to listen on (default 8080)
-https-cert-file string -https-cert-file string
HTTPS certificate file HTTPS Server certificate file
-https-key-file string -https-key-file string
HTTPS private key file HTTPS Server private key file
-max-body-size int -max-body-size int
Maximum size of request or response, in bytes (default 1048576) Maximum size of request or response, in bytes (default 1048576)
-max-duration duration -max-duration duration
Maximum duration a response may take (default 10s) Maximum duration a response may take (default 10s)
-port int
Port to listen on (default 8080)
```
Examples: Examples:
# Run http server
$ go-httpbin -host 127.0.0.1 -port 8081
# Run https server
# Generate .crt and .key files ```bash
$ openssl genrsa -out server.key 2048 # Run http server
$ openssl ecparam -genkey -name secp384r1 -out server.key $ go-httpbin -host 127.0.0.1 -port 8081
$ openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
$ go-httpbin -host 127.0.0.1 -port 8081 -https-cert-file ./server.crt -https-key-file ./server.key # Run https server
$ openssl genrsa -out server.key 2048
$ openssl ecparam -genkey -name secp384r1 -out server.key
$ openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
$ go-httpbin -host 127.0.0.1 -port 8081 -https-cert-file ./server.crt -https-key-file ./server.key
``` ```
Docker images are published to [Docker Hub][docker-hub]: Docker images are published to [Docker Hub][docker-hub]:
``` ```bash
# Run http server # Run http server
$ docker run -P mccutchen/go-httpbin $ docker run -P mccutchen/go-httpbin
...@@ -53,7 +53,7 @@ $ docker run -P mccutchen/go-httpbin ...@@ -53,7 +53,7 @@ $ docker run -P mccutchen/go-httpbin
$ 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 $ 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
``` ```
The `github.com/mccutchen/go-httpbin/httpbin` package can also be used as a The `github.com/mccutchen/go-httpbin/httpbin/v2` package can also be used as a
library for testing an applications interactions with an upstream HTTP service, library for testing an applications interactions with an upstream HTTP service,
like so: like so:
...@@ -61,34 +61,44 @@ like so: ...@@ -61,34 +61,44 @@ like so:
package httpbin_test package httpbin_test
import ( import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "os"
"time" "testing"
"time"
"github.com/mccutchen/go-httpbin/httpbin" "github.com/mccutchen/go-httpbin/v2/httpbin"
) )
func TestSlowResponse(t *testing.T) { func TestSlowResponse(t *testing.T) {
svc := httpbin.New() app := httpbin.New()
srv := httptest.NewServer(svc.Handler()) testServer := httptest.NewServer(app.Handler())
defer srv.Close() defer testServer.Close()
client := http.Client{ client := http.Client{
Timeout: time.Duration(1 * time.Second), Timeout: time.Duration(1 * time.Second),
} }
_, err := client.Get(srv.URL + "/delay/10")
if err == nil { _, err := client.Get(testServer.URL + "/delay/10")
t.Fatal("expected timeout error") if !os.IsTimeout(err) {
} t.Fatalf("expected timeout error, got %s", err)
}
} }
``` ```
## Installation ## Installation
To add go-httpbin to an existing golang project:
```
go get -u github.com/mccutchen/go-httpbin/v2
```
To install the `go-httpbin` binary:
``` ```
go get github.com/mccutchen/go-httpbin/cmd/go-httpbin go install github.com/mccutchen/go-httpbin/v2/cmd/go-httpbin
``` ```
......
package main package main
import "github.com/mccutchen/go-httpbin/cmd/maincmd" import "github.com/mccutchen/go-httpbin/v2/cmd/maincmd"
func main() { func main() {
maincmd.Main() maincmd.Main()
......
package main package main
import "github.com/mccutchen/go-httpbin/cmd/maincmd" import "github.com/mccutchen/go-httpbin/v2/cmd/maincmd"
func main() { func main() {
maincmd.Main() maincmd.Main()
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/mccutchen/go-httpbin/httpbin" "github.com/mccutchen/go-httpbin/v2/httpbin"
) )
const defaultHost = "0.0.0.0" const defaultHost = "0.0.0.0"
......
package httpbin_test
import (
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
"github.com/mccutchen/go-httpbin/v2/httpbin"
)
func TestSlowResponse(t *testing.T) {
app := httpbin.New()
testServer := httptest.NewServer(app.Handler())
defer testServer.Close()
client := http.Client{
Timeout: time.Duration(1 * time.Second),
}
_, err := client.Get(testServer.URL + "/delay/10")
if !os.IsTimeout(err) {
t.Fatalf("expected timeout error, got %s", err)
}
}
...@@ -11,8 +11,8 @@ import ( ...@@ -11,8 +11,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/mccutchen/go-httpbin/httpbin/assets" "github.com/mccutchen/go-httpbin/v2/httpbin/assets"
"github.com/mccutchen/go-httpbin/httpbin/digest" "github.com/mccutchen/go-httpbin/v2/httpbin/digest"
) )
var acceptedMediaTypes = []string{ var acceptedMediaTypes = []string{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment