Initial save
This commit is contained in:
commit
4077efcca6
34
main.go
Normal file
34
main.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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
|
||||||
|
fmt.Fprintf(w, "Hello! This is server: %s\n", hostname)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Define the handler function for incoming requests
|
||||||
|
http.HandleFunc("/", handler)
|
||||||
|
|
||||||
|
// Start the HTTP server on port 8080
|
||||||
|
fmt.Println("Server listening on :8080...")
|
||||||
|
err := http.ListenAndServe(":8080", nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error:", err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user