Created
May 22, 2020 09:46
-
-
Save RicardoLinck/192cb3e85accf7fd86f61866bc7e4880 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
type data struct { | |
// ... | |
} | |
func handleHTTPRequest(w http.ResponseWriter, r *http.Request) { | |
// ... | |
c := make(chan data) | |
defer close(c) | |
defer r.Body.Close() | |
go saveDataFromChannel(c) | |
c <- calculateStuff(getData(r.Body)) | |
} | |
func getData(r io.Reader) data { | |
// ... | |
return data{} | |
} | |
func calculateStuff(d data) data { | |
// ... | |
return d | |
} | |
func saveDataFromChannel(c chan data) { | |
for d := range c { | |
saveToDatabase(d) | |
// ... | |
} | |
} | |
func saveToDatabase(d data) { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment