Add http server

This commit is contained in:
Sangeeth Sudheer 2024-05-04 22:29:15 +05:30
parent 4e623989ea
commit 750c23e26e
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 29 additions and 2 deletions

25
httpserver/httpserver.go Normal file
View File

@ -0,0 +1,25 @@
package httpserver
import (
"fmt"
"net/http"
"strings"
)
func hello(rw http.ResponseWriter, req *http.Request) {
fmt.Fprintln(rw, "Hello, world!")
}
func headers(rw http.ResponseWriter, req *http.Request) {
for k, v := range req.Header {
fmt.Fprintf(rw, "%s: %v\n", k, strings.Join(v, " "))
}
}
func HttpServer() {
http.HandleFunc("/hello", hello)
http.HandleFunc("/headers", headers)
fmt.Println("Listening on 8002")
http.ListenAndServe(":8002", nil)
}

View File

@ -46,7 +46,8 @@ import (
// "git.sangeeth.dev/gobyexample/subcmd"
// "git.sangeeth.dev/gobyexample/env"
// "git.sangeeth.dev/gobyexample/logging"
"git.sangeeth.dev/gobyexample/httpclient"
// "git.sangeeth.dev/gobyexample/httpclient"
"git.sangeeth.dev/gobyexample/httpserver"
)
func main() {
@ -95,5 +96,6 @@ func main() {
// subcmd.SubCmd()
// env.Env()
// logging.Logging()
httpclient.HttpClient()
// httpclient.HttpClient()
httpserver.HttpServer()
}