Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Go Httpbin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Nix
Go Httpbin
Commits
682c4dbe
Commit
682c4dbe
authored
7 years ago
by
Will McCutchen
Browse files
Options
Downloads
Patches
Plain Diff
Just take a -port arg instead of a -listen address
This will simplify deployment on some platforms (e.g. heroku)
parent
ff41abb0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+2
-14
2 additions, 14 deletions
README.md
cmd/go-httpbin/main.go
+14
-6
14 additions, 6 deletions
cmd/go-httpbin/main.go
with
16 additions
and
20 deletions
README.md
+
2
−
14
View file @
682c4dbe
...
...
@@ -15,12 +15,12 @@ variables:
```
$ go-httpbin -help
Usage of ./dist/go-httpbin:
-listen string
Listen address (default ":8080")
-max-duration duration
Maximum duration a response may take (default 10s)
-max-memory int
Maximum size of request or response, in bytes (default 1048576)
-port int
Port to listen on (default 8080)
```
## Installation
...
...
@@ -37,22 +37,10 @@ go get github.com/mccutchen/go-httpbin/...
## Development
### Building
```
make
```
### Testing
```
make test
make testcover
```
### Running
```
make run
```
...
...
This diff is collapsed.
Click to expand it.
cmd/go-httpbin/main.go
+
14
−
6
View file @
682c4dbe
...
...
@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"strconv"
...
...
@@ -12,16 +13,16 @@ import (
"github.com/mccutchen/go-httpbin/httpbin"
)
const
default
ListenAddr
=
":
8080
"
const
default
Port
=
8080
var
(
listenAddr
str
in
g
port
in
t
maxMemory
int64
maxDuration
time
.
Duration
)
func
main
()
{
flag
.
StringVar
(
&
listenAddr
,
"listen"
,
":8080"
,
"Listen address
"
)
flag
.
IntVar
(
&
port
,
"port"
,
defaultPort
,
"Port to listen on
"
)
flag
.
Int64Var
(
&
maxMemory
,
"max-memory"
,
httpbin
.
DefaultMaxMemory
,
"Maximum size of request or response, in bytes"
)
flag
.
DurationVar
(
&
maxDuration
,
"max-duration"
,
httpbin
.
DefaultMaxDuration
,
"Maximum duration a response may take"
)
flag
.
Parse
()
...
...
@@ -46,14 +47,21 @@ func main() {
os
.
Exit
(
1
)
}
}
if
listenAddr
==
defaultListenAddr
&&
os
.
Getenv
(
"LISTEN"
)
!=
""
{
listenAddr
=
os
.
Getenv
(
"LISTEN"
)
if
port
==
defaultPort
&&
os
.
Getenv
(
"PORT"
)
!=
""
{
port
,
err
=
strconv
.
Atoi
(
os
.
Getenv
(
"PORT"
))
if
err
!=
nil
{
fmt
.
Printf
(
"invalid value %#v for env var PORT: %s
\n
"
,
os
.
Getenv
(
"PORT"
),
err
)
flag
.
Usage
()
os
.
Exit
(
1
)
}
}
h
:=
httpbin
.
NewHTTPBinWithOptions
(
&
httpbin
.
Options
{
MaxMemory
:
maxMemory
,
MaxDuration
:
maxDuration
,
})
log
.
Printf
(
"listening on %s"
,
listenAddr
)
listenAddr
:=
net
.
JoinHostPort
(
"0.0.0.0"
,
strconv
.
Itoa
(
port
))
log
.
Printf
(
"listening on port %s"
,
listenAddr
)
log
.
Fatal
(
http
.
ListenAndServe
(
listenAddr
,
h
.
Handler
()))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment