Skip to content

Instantly share code, notes, and snippets.

@pjankiewicz
Last active July 23, 2017 08:42
Show Gist options
  • Save pjankiewicz/8c16a62b679572608381 to your computer and use it in GitHub Desktop.
Save pjankiewicz/8c16a62b679572608381 to your computer and use it in GitHub Desktop.
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