Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c4809bbe21 | |||
741a054a0c | |||
9bf5b44f24 | |||
bf0a64d4c2 |
@ -25,11 +25,13 @@
|
||||
disable = [
|
||||
"maligned",
|
||||
"lll",
|
||||
"gas",
|
||||
"gosec",
|
||||
"dupl",
|
||||
"prealloc",
|
||||
"gochecknoglobals",
|
||||
"gochecknoinits",
|
||||
"gomnd",
|
||||
"wsl",
|
||||
]
|
||||
|
||||
[issues]
|
||||
|
@ -9,10 +9,10 @@ Tiny Go webserver that prints os information and HTTP request to output
|
||||
|
||||
### Paths
|
||||
|
||||
- `/data?size=n`: creates a response with a size `n`.
|
||||
- `/data?size=n[&unit=u]`: creates a response with a size `n`. The unit of measure, if specified, accepts the following values: `KB`, `MB`, `GB`, `TB` (optional, default: bytes).
|
||||
- `/echo`: webSocket echo.
|
||||
- `/bench`: always return the same response (`1`).
|
||||
- `/`: returns the whoami information (request and network information).
|
||||
- `/[?wait=d]`: returns the whoami information (request and network information). The optional `wait` query parameter can be provided to tell the server to wait before sending the response. The duration is expected in Go's [`time.Duration`](https://golang.org/pkg/time/#ParseDuration) format (e.g. `/?wait=100ms` to wait 100 milliseconds).
|
||||
- `/api`: returns the whoami information as JSON.
|
||||
- `/health`: heath check
|
||||
- `GET`, `HEAD`, ...: returns a response with the status code defined by the `POST`
|
||||
@ -23,6 +23,7 @@ Tiny Go webserver that prints os information and HTTP request to output
|
||||
- `cert`: give me a certificate.
|
||||
- `key`: give me a key.
|
||||
- `port`: give me a port number. (default: 80)
|
||||
- `name`: give me a name. (it can be also defined with `WHOAMI_NAME` environment variable)
|
||||
|
||||
## Examples
|
||||
|
||||
@ -63,3 +64,7 @@ $ curl -v http://localhost:80/health
|
||||
< Date: Mon, 16 Sep 2019 22:52:40 GMT
|
||||
< Content-Length: 0
|
||||
```
|
||||
|
||||
```console
|
||||
docker run -d -P -v ./certs:/certs --name iamfoo containous/whoami --cert /certs/cert.cer --key /certs/key.key
|
||||
```
|
||||
|
6
app.go
6
app.go
@ -31,11 +31,13 @@ const (
|
||||
var cert string
|
||||
var key string
|
||||
var port string
|
||||
var name string
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&cert, "cert", "", "give me a certificate")
|
||||
flag.StringVar(&key, "key", "", "give me a key")
|
||||
flag.StringVar(&port, "port", "80", "give me a port number")
|
||||
flag.StringVar(&name, "name", os.Getenv("WHOAMI_NAME"), "give me a name")
|
||||
}
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
@ -149,6 +151,10 @@ func whoamiHandler(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if name != "" {
|
||||
_, _ = fmt.Fprintln(w, "Name:", name)
|
||||
}
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
_, _ = fmt.Fprintln(w, "Hostname:", hostname)
|
||||
|
||||
|
Reference in New Issue
Block a user