This commit is contained in:
Michael Thomson 2024-05-25 11:50:11 -04:00
parent de9c6f7429
commit 96a19ac142
No known key found for this signature in database
2 changed files with 38 additions and 0 deletions

20
di/greet.go Normal file
View File

@ -0,0 +1,20 @@
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func Greet(writer io.Writer, name string) {
fmt.Fprintf(writer, "Hello, %s", name)
}
func MyGreeterHandler(w http.ResponseWriter, r *http.Request) {
Greet(w, "world")
}
func main() {
log.Fatal(http.ListenAndServe(":5001", http.HandlerFunc(MyGreeterHandler)))
}

18
di/greet_test.go Normal file
View File

@ -0,0 +1,18 @@
package main
import (
"bytes"
"testing"
)
func TestGreet(t *testing.T) {
buffer := bytes.Buffer{}
Greet(&buffer, "Chris")
got := buffer.String()
want := "Hello, Chris"
if got != want {
t.Errorf("got %q want %q", got, want)
}
}