Add http server
This commit is contained in:
parent
4e623989ea
commit
750c23e26e
25
httpserver/httpserver.go
Normal file
25
httpserver/httpserver.go
Normal 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)
|
||||||
|
}
|
6
main.go
6
main.go
@ -46,7 +46,8 @@ import (
|
|||||||
// "git.sangeeth.dev/gobyexample/subcmd"
|
// "git.sangeeth.dev/gobyexample/subcmd"
|
||||||
// "git.sangeeth.dev/gobyexample/env"
|
// "git.sangeeth.dev/gobyexample/env"
|
||||||
// "git.sangeeth.dev/gobyexample/logging"
|
// "git.sangeeth.dev/gobyexample/logging"
|
||||||
"git.sangeeth.dev/gobyexample/httpclient"
|
// "git.sangeeth.dev/gobyexample/httpclient"
|
||||||
|
"git.sangeeth.dev/gobyexample/httpserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -95,5 +96,6 @@ func main() {
|
|||||||
// subcmd.SubCmd()
|
// subcmd.SubCmd()
|
||||||
// env.Env()
|
// env.Env()
|
||||||
// logging.Logging()
|
// logging.Logging()
|
||||||
httpclient.HttpClient()
|
// httpclient.HttpClient()
|
||||||
|
httpserver.HttpServer()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user