-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (39 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"flag"
"io"
"log"
"net/http"
"os"
"os/exec"
)
var (
addr string
port string
hostname string
out string
s string
)
// Probe acks back details about the container
func Probe(w http.ResponseWriter, req *http.Request) {
log.Printf("variable is: %v", s)
io.WriteString(w, s)
}
func main() {
flag.Parse()
//Gather the details the response will contain
hostname, _ := os.Hostname()
s = "Hello from container: " + hostname + "\n"
cmd := "ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{ print $1}'"
out, err := exec.Command("sh", "-c", cmd).Output()
s += "Local IP of container: " + string(out) + "\n"
if err != nil {
log.Printf("Failed to execute command: %s", cmd)
}
http.HandleFunc("/", Probe)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
func init() {
flag.StringVar(&port, "port", "9000", "Specify the port number the server will listen on.")
flag.StringVar(&addr, "addr", "127.0.0.1", "Specify the address the server will listen on.")
}