Last active
July 23, 2017 08:42
-
-
Save pjankiewicz/8c16a62b679572608381 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"net/http" | |
) | |
type storageData struct { | |
data string | |
} | |
var uploadQueue = make(chan storageData) | |
func uploader(uploadQueue chan storageData) { | |
for { | |
data := <-uploadQueue | |
insertToBucket(data) | |
} | |
} | |
func handler(w http.ResponseWriter, r *http.Request) { | |
uploadQueue <- get_data(r) | |
fmt.Fprintf(w, "Upload ok") | |
} | |
func initializeUploaders(uploadQueue chan storageData, n int) { | |
for i := 0; i < n; i++ { | |
fmt.Printf("Started uploader %d\n", i) | |
go uploader(uploadQueue) | |
} | |
} | |
func main() { | |
runtime.GOMAXPROCS(8) | |
const nUploaders = 10 | |
initializeUploaders(uploadQueue, 10) | |
http.HandleFunc("/upload", handler) | |
http.ListenAndServe(":8080", nil) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment