2023-11-22 12:53:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func handler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// Get the hostname of the server
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the hostname in the response header
|
|
|
|
w.Header().Set("Server-Hostname", hostname)
|
|
|
|
|
|
|
|
// Send a response
|
2023-11-22 15:45:57 +00:00
|
|
|
fmt.Fprintf(w, "This is server: %s\n", hostname)
|
2023-11-22 12:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Define the handler function for incoming requests
|
|
|
|
http.HandleFunc("/", handler)
|
|
|
|
|
2023-11-22 15:45:57 +00:00
|
|
|
// Start the HTTP server on port 8000
|
|
|
|
fmt.Println("Server listening on :8000...")
|
|
|
|
err := http.ListenAndServe(":8000", nil)
|
2023-11-22 12:53:44 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
}
|
|
|
|
}
|