greet: DI

This commit is contained in:
vinchent 2024-09-17 16:12:39 +02:00
parent f573268be9
commit 5f02a8fbde
2 changed files with 36 additions and 0 deletions

17
greet/greet_test.go Normal file
View File

@ -0,0 +1,17 @@
package greet
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)
}
}

19
greet/main.go Normal file
View File

@ -0,0 +1,19 @@
package greet
import (
"fmt"
"io"
"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)))
// }