From 242fa643db458663479a2fe3f1c757b5bf05cb5d Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 21 May 2026 20:51:23 +0200 Subject: Add HTTP-based hello world This demonstrates the HTTP server is working. --- main.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index f5391cf..a595ab1 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,18 @@ package main import ( + "fmt" "log" + "net/http" + "time" + + "github.com/gorilla/mux" +) + +const ( + Addr = "127.0.0.1:8000" + ReadTimeout = 15 * time.Second + WriteTimeout = 15 * time.Second ) func main() { @@ -11,4 +22,21 @@ func main() { func run() { log.Println("finserv finance server was started.") defer log.Println("finserv finance server was stopped.") + + r := mux.NewRouter() + + r.HandleFunc("/", hello) + + srv := &http.Server{ + Handler: r, + Addr: Addr, + WriteTimeout: WriteTimeout, + ReadTimeout: ReadTimeout, + } + + log.Fatal(srv.ListenAndServe()) +} + +func hello(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "Hello world!") } -- cgit v1.3