30 lines
574 B
Go
30 lines
574 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
var version string
|
|
|
|
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
|
|
}
|
|
fmt.Fprintf(w, "%s (%s)\n", h, version)
|
|
})
|
|
s := &http.Server{
|
|
ReadTimeout: 5 * time.Second,
|
|
WriteTimeout: 10 * time.Second,
|
|
IdleTimeout: 120 * time.Second,
|
|
Addr: ":8080",
|
|
}
|
|
log.Fatal(s.ListenAndServe())
|
|
}
|