golang-exercises/httpserver/main.go

28 lines
464 B
Go
Raw Permalink Normal View History

2024-04-19 07:51:21 +02:00
package main
import (
"fmt"
"log"
"net/http"
)
func getRoot(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Received connection\n")
fmt.Fprintln(w, "Hello!")
}
2024-04-20 09:29:30 +02:00
func getCMD(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Received connection!\n")
fmt.Fprintln(w, "This is a test")
}
2024-04-19 07:51:21 +02:00
func main() {
http.HandleFunc("/", getRoot)
2024-04-20 09:29:30 +02:00
http.HandleFunc("/cmd", getCMD)
2024-04-19 07:51:21 +02:00
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}