initial commit
This commit is contained in:
commit
0e6be50e37
23 changed files with 1069 additions and 0 deletions
73
testapp/srv/main.go
Normal file
73
testapp/srv/main.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var version string
|
||||
|
||||
func get(c *http.Client, url string) (body string, err error) {
|
||||
resp, err := c.Get(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
body = string(b)
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL)
|
||||
h, err := os.Hostname()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
u, err := user.LookupId(strconv.Itoa(os.Getuid()))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
//url := "http://" + os.Getenv("DB_SERVICE_HOST") + ":" + os.Getenv("DB_SERVICE_PORT")
|
||||
//url := "http://testapp-db.default.svc.cluster.local:8080"
|
||||
c := &http.Client{Transport: &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
}).DialContext,
|
||||
}}
|
||||
dbUrl := "http://testapp-db:8080"
|
||||
dbBody, err := get(c, dbUrl)
|
||||
if err != nil {
|
||||
dbBody = err.Error()
|
||||
}
|
||||
apiUrl := "http://testapp-api:8080"
|
||||
apiBody, err := get(c, apiUrl)
|
||||
if err != nil {
|
||||
apiBody = err.Error()
|
||||
}
|
||||
fmt.Fprintf(w, "Version: %s\nHostname: %s\nUser: %s (%s) (%s)\nDB URL: %s\nDB Response: %s\nAPI URL: %s\nAPI Response: %s\n",
|
||||
version, h, u.Username, u.Uid, u.Gid,
|
||||
dbUrl, dbBody,
|
||||
apiUrl, apiBody)
|
||||
})
|
||||
s := &http.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
Addr: ":8080",
|
||||
}
|
||||
log.Fatal(s.ListenAndServe())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue