Created
May 23, 2020 15:34
-
-
Save RicardoLinck/d4a6ba514cae36c09cb3d03f7f14f153 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
) | |
type externalService interface { | |
getData(r io.Reader) string | |
} | |
type externalSource struct{} | |
func (s externalSource) getData(r io.Reader) string { | |
return "test" | |
} | |
type dependencies struct { | |
externalService externalService | |
} | |
func main() { | |
d := dependencies{ | |
externalService: externalSource{}, | |
} | |
http.HandleFunc("/", d.HandleRequest) | |
http.ListenAndServe(":8080", nil) | |
} | |
func (d *dependencies) HandleRequest(rw http.ResponseWriter, r *http.Request) { | |
data := d.externalService.getData(r.Body) | |
fmt.Println(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment