Skip to content

Instantly share code, notes, and snippets.

@RicardoLinck
Created May 23, 2020 15:34
Show Gist options
  • Save RicardoLinck/d4a6ba514cae36c09cb3d03f7f14f153 to your computer and use it in GitHub Desktop.
Save RicardoLinck/d4a6ba514cae36c09cb3d03f7f14f153 to your computer and use it in GitHub Desktop.
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