aboutsummaryrefslogtreecommitdiff
path: root/backend/main.go
blob: f5c754cb8dfe771aabe8ec0e8e45b47ba26020aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
	"fmt"
	"io"
	"net/http"
)

func helloHandler(w http.ResponseWriter, _ *http.Request) {
	w.Write([]byte("Hello, World!"))
}

func requestServer() {
	resp, err := http.Get("http://localhost:8080")
	fmt.Println(err)
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	fmt.Printf("\nWebserver said: `%s`", string(body))
}

func main() {
	http.HandleFunc("/", helloHandler)
	go func() {
		err := http.ListenAndServe(":8080", nil)
		fmt.Println(err) // don't ignore errors
	}()

	requestServer()
}