Created
August 5, 2015 13:18
-
-
Save dvirsky/65852363cd0f79b459d1 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
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