2024-07-06 13:32:06 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2024-07-06 13:39:34 +00:00
|
|
|
"golang_demo1/handlers"
|
2024-07-06 13:32:06 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
portPtr := flag.Int("port", 8080, "port for webserver")
|
|
|
|
flag.Parse()
|
|
|
|
port := *portPtr
|
|
|
|
|
|
|
|
fmt.Printf("Server is listening on port: %d", port)
|
|
|
|
|
|
|
|
server := http.NewServeMux()
|
2024-07-06 13:39:34 +00:00
|
|
|
server.HandleFunc("/status", handlers.StatusHandler)
|
|
|
|
server.HandleFunc("/greeting", handlers.GreetingHandler)
|
2024-07-06 13:32:06 +00:00
|
|
|
err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), server)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|