Skip to content

Instantly share code, notes, and snippets.

@dvirsky
Created August 5, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvirsky/65852363cd0f79b459d1 to your computer and use it in GitHub Desktop.
Save dvirsky/65852363cd0f79b459d1 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/EverythingMe/inbloom/go/inbloom"
"net/http"
)
var vocabulary = []string{"foo", "bar", "baz", "hey", "yo", "go"}
func handleWords(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
// create a filter from the data passed to us as GET/POST argument
f, err := inbloom.UnmarshalBase64(r.FormValue("filter"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// send the client back each word in the vocabulary that is not in the filter
for _, word := range vocabulary {
if !f.Contains(word) {
fmt.Fprintln(w, word)
}
}
}
func main() {
http.HandleFunc("/words", handleWords)
http.ListenAndServe(":8888", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment