Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
9378a1e1d2 | |||
1ef68230de | |||
b112c2640e | |||
90425015d5 | |||
c4809bbe21 | |||
741a054a0c | |||
9bf5b44f24 | |||
bf0a64d4c2 |
@ -25,11 +25,15 @@
|
|||||||
disable = [
|
disable = [
|
||||||
"maligned",
|
"maligned",
|
||||||
"lll",
|
"lll",
|
||||||
"gas",
|
"gosec",
|
||||||
"dupl",
|
"dupl",
|
||||||
"prealloc",
|
"prealloc",
|
||||||
"gochecknoglobals",
|
"gochecknoglobals",
|
||||||
"gochecknoinits",
|
"gochecknoinits",
|
||||||
|
"gomnd",
|
||||||
|
"wsl",
|
||||||
|
"goerr113",
|
||||||
|
"testpackage",
|
||||||
]
|
]
|
||||||
|
|
||||||
[issues]
|
[issues]
|
||||||
|
1
LICENSE
1
LICENSE
@ -187,6 +187,7 @@
|
|||||||
identification within third-party archives.
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright [2015-2018] [Containous]
|
Copyright [2015-2018] [Containous]
|
||||||
|
Copyright [2020] [Traefik Labs]
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
4
Makefile
4
Makefile
@ -11,10 +11,10 @@ build:
|
|||||||
CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o whoami
|
CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o whoami
|
||||||
|
|
||||||
image:
|
image:
|
||||||
docker build -t containous/whoami .
|
docker build -t traefik/whoami .
|
||||||
|
|
||||||
check:
|
check:
|
||||||
golangci-lint run
|
golangci-lint run
|
||||||
|
|
||||||
publish-images:
|
publish-images:
|
||||||
seihon publish -v "$(TAG_NAME)" -v "latest" --image-name containous/whoami --dry-run=false
|
seihon publish -v "$(TAG_NAME)" -v "latest" --image-name traefik/whoami --dry-run=false
|
||||||
|
15
README.md
15
README.md
@ -1,7 +1,7 @@
|
|||||||
# whoami
|
# whoami
|
||||||
|
|
||||||
[](https://hub.docker.com/r/containous/whoami/)
|
[](https://hub.docker.com/r/traefik/whoami/)
|
||||||
[](https://travis-ci.com/containous/whoami)
|
[](https://travis-ci.com/traefik/whoami)
|
||||||
|
|
||||||
Tiny Go webserver that prints os information and HTTP request to output
|
Tiny Go webserver that prints os information and HTTP request to output
|
||||||
|
|
||||||
@ -9,10 +9,10 @@ Tiny Go webserver that prints os information and HTTP request to output
|
|||||||
|
|
||||||
### Paths
|
### 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.
|
- `/echo`: webSocket echo.
|
||||||
- `/bench`: always return the same response (`1`).
|
- `/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.
|
- `/api`: returns the whoami information as JSON.
|
||||||
- `/health`: heath check
|
- `/health`: heath check
|
||||||
- `GET`, `HEAD`, ...: returns a response with the status code defined by the `POST`
|
- `GET`, `HEAD`, ...: returns a response with the status code defined by the `POST`
|
||||||
@ -23,11 +23,12 @@ Tiny Go webserver that prints os information and HTTP request to output
|
|||||||
- `cert`: give me a certificate.
|
- `cert`: give me a certificate.
|
||||||
- `key`: give me a key.
|
- `key`: give me a key.
|
||||||
- `port`: give me a port number. (default: 80)
|
- `port`: give me a port number. (default: 80)
|
||||||
|
- `name`: give me a name. (it can be also defined with `WHOAMI_NAME` environment variable)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ docker run -d -P --name iamfoo containous/whoami
|
$ docker run -d -P --name iamfoo traefik/whoami
|
||||||
|
|
||||||
$ docker inspect --format '{{ .NetworkSettings.Ports }}' iamfoo
|
$ docker inspect --format '{{ .NetworkSettings.Ports }}' iamfoo
|
||||||
map[80/tcp:[{0.0.0.0 32769}]]
|
map[80/tcp:[{0.0.0.0 32769}]]
|
||||||
@ -63,3 +64,7 @@ $ curl -v http://localhost:80/health
|
|||||||
< Date: Mon, 16 Sep 2019 22:52:40 GMT
|
< Date: Mon, 16 Sep 2019 22:52:40 GMT
|
||||||
< Content-Length: 0
|
< Content-Length: 0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```console
|
||||||
|
docker run -d -P -v ./certs:/certs --name iamfoo traefik/whoami --cert /certs/cert.cer --key /certs/key.key
|
||||||
|
```
|
||||||
|
10
app.go
10
app.go
@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Units
|
// Units.
|
||||||
const (
|
const (
|
||||||
_ = iota
|
_ = iota
|
||||||
KB int64 = 1 << (10 * iota)
|
KB int64 = 1 << (10 * iota)
|
||||||
@ -31,11 +31,13 @@ const (
|
|||||||
var cert string
|
var cert string
|
||||||
var key string
|
var key string
|
||||||
var port string
|
var port string
|
||||||
|
var name string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&cert, "cert", "", "give me a certificate")
|
flag.StringVar(&cert, "cert", "", "give me a certificate")
|
||||||
flag.StringVar(&key, "key", "", "give me a key")
|
flag.StringVar(&key, "key", "", "give me a key")
|
||||||
flag.StringVar(&port, "port", "80", "give me a port number")
|
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{
|
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()
|
hostname, _ := os.Hostname()
|
||||||
_, _ = fmt.Fprintln(w, "Hostname:", hostname)
|
_, _ = fmt.Fprintln(w, "Hostname:", hostname)
|
||||||
|
|
||||||
@ -185,6 +191,7 @@ func apiHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Method string `json:"method,omitempty"`
|
Method string `json:"method,omitempty"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
}{
|
}{
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
IP: []string{},
|
IP: []string{},
|
||||||
@ -192,6 +199,7 @@ func apiHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
URL: req.URL.RequestURI(),
|
URL: req.URL.RequestURI(),
|
||||||
Host: req.Host,
|
Host: req.Host,
|
||||||
Method: req.Method,
|
Method: req.Method,
|
||||||
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaces, _ := net.Interfaces()
|
ifaces, _ := net.Interfaces()
|
||||||
|
4
go.mod
4
go.mod
@ -1,5 +1,5 @@
|
|||||||
module github.com/containous/whoami
|
module github.com/traefik/whoami
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require github.com/gorilla/websocket v1.4.1
|
require github.com/gorilla/websocket v1.4.2
|
||||||
|
4
go.sum
4
go.sum
@ -1,2 +1,2 @@
|
|||||||
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
Reference in New Issue
Block a user