greet: DI
This commit is contained in:
parent
f573268be9
commit
5f02a8fbde
17
greet/greet_test.go
Normal file
17
greet/greet_test.go
Normal 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
19
greet/main.go
Normal 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)))
|
||||
// }
|
Loading…
Reference in New Issue
Block a user