Messing around with get methods and working with byte slices
This commit is contained in:
parent
fd0565c300
commit
c383e98bb8
7
main.go
7
main.go
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -13,6 +14,7 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Println("Hi, ", r.Header)
|
fmt.Println("Hi, ", r.Header)
|
||||||
|
w.Write([]byte("Hi there!"))
|
||||||
})
|
})
|
||||||
|
|
||||||
http_server := &http.Server{
|
http_server := &http.Server{
|
||||||
|
|
@ -26,6 +28,11 @@ func main() {
|
||||||
log.Fatal(http_server.ListenAndServe())
|
log.Fatal(http_server.ListenAndServe())
|
||||||
}()
|
}()
|
||||||
fmt.Println("Server started! Listening in on ", http_server.Addr)
|
fmt.Println("Server started! Listening in on ", http_server.Addr)
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
resp, _ := http.Get("http://127.0.0.1:8080/foo")
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
fmt.Println(string(body))
|
||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue