ACOR v1.3.0: HTTP and gRPC Server Adapters
Introduction ACOR v1.3.0 adds HTTP and gRPC server adapters. You can now easily integrate ACOR into microservice architectures or deploy it as a standalone server. This post covers the usage and deployment of both adapters. Architecture Overview v1.3.0 adds a pkg/server package that exposes the existing pkg/acor APIs over HTTP JSON and gRPC: ┌ │ └ ─ ─ ─ ─ ─ ─ ─ C ─ ─ l ─ ─ i ─ ─ e ─ ─ n ─ ─ t ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ ┘ ─ ─ ─ ─ ▶ ┌ │ │ └ ┌ │ └ ┌ │ └ ─ ─ ─ ─ ─ ─ ─ H ─ ─ ─ ─ ─ ─ T ─ ─ p ─ ─ ─ ─ T S ─ ─ k ─ ─ ─ ─ P e ─ ─ g ─ ─ R ─ ─ / r ─ ─ / ─ ─ e ─ ─ g v ┬ │ ▼ a ┬ │ ▼ d ─ ─ R e ─ ─ c ─ ─ i ─ ─ P r ─ ─ o ─ ─ s ─ ─ C ─ ─ r ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │ ┘ ┐ │ ┘ ┐ │ ┘ HTTP Server Basic Usage 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 package main import ( "log" "net/http" "github.com/skyoo2003/acor/pkg/acor" "github.com/skyoo2003/acor/pkg/server" ) func main() { ac, err := acor.Create(&acor.AhoCorasickArgs{ Addr: "localhost:6379", Name: "sample", }) if err != nil { log.Fatal(err) } defer ac.Close() httpHandler := server.NewHTTPHandler(ac) http.Handle("/", httpHandler) log.Println("HTTP server listening on :8080") log.Fatal(http.ListenAndServe(":8080", nil)) } API Endpoints Method Path Description POST /add Add keyword POST /remove Remove keyword POST /find Search text POST /find-index Search with position info POST /suggest Autocomplete suggestions POST /suggest-index Autocomplete with position info GET /info Collection info POST /flush Delete collection Request/Response Examples Add Keyword ...