mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 03:17:50 +00:00
Unexport APIOption, b.BTCIterator, API.Holder, API.Serializer, APIOption, http.Handler.API
This commit is contained in:
parent
aa1e4df101
commit
b4011778dd
3 changed files with 46 additions and 46 deletions
8
api.go
8
api.go
|
|
@ -40,10 +40,10 @@ type API struct {
|
|||
Serializer Serializer
|
||||
}
|
||||
|
||||
// APIOption is a functional option type for pilosa.API
|
||||
type APIOption func(*API) error
|
||||
// apiOption is a functional option type for pilosa.API
|
||||
type apiOption func(*API) error
|
||||
|
||||
func OptAPIServer(s *Server) APIOption {
|
||||
func OptAPIServer(s *Server) apiOption {
|
||||
return func(a *API) error {
|
||||
a.server = s
|
||||
a.holder = s.holder
|
||||
|
|
@ -54,7 +54,7 @@ func OptAPIServer(s *Server) APIOption {
|
|||
}
|
||||
|
||||
// NewAPI returns a new API instance.
|
||||
func NewAPI(opts ...APIOption) (*API, error) {
|
||||
func NewAPI(opts ...apiOption) (*API, error) {
|
||||
api := &API{}
|
||||
|
||||
for _, opt := range opts {
|
||||
|
|
|
|||
|
|
@ -172,18 +172,18 @@ func (btc *BTreeContainers) Iterator(key uint64) (citer roaring.ContainerIterato
|
|||
found = true
|
||||
}
|
||||
|
||||
return &BTCIterator{
|
||||
return &btcIterator{
|
||||
e: e,
|
||||
}, found
|
||||
}
|
||||
|
||||
type BTCIterator struct {
|
||||
type btcIterator struct {
|
||||
e *Enumerator
|
||||
key uint64
|
||||
val *roaring.Container
|
||||
}
|
||||
|
||||
func (i *BTCIterator) Next() bool {
|
||||
func (i *btcIterator) Next() bool {
|
||||
|
||||
k, v, err := i.e.Next()
|
||||
if err == io.EOF {
|
||||
|
|
@ -194,7 +194,7 @@ func (i *BTCIterator) Next() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (i *BTCIterator) Value() (uint64, *roaring.Container) {
|
||||
func (i *btcIterator) Value() (uint64, *roaring.Container) {
|
||||
if i.val == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ type Handler struct {
|
|||
// Keeps the query argument validators for each handler
|
||||
validators map[string]*queryValidationSpec
|
||||
|
||||
API *pilosa.API
|
||||
api *pilosa.API
|
||||
|
||||
AllowedOrigins []string
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ func OptHandlerAllowedOrigins(origins []string) HandlerOption {
|
|||
|
||||
func OptHandlerAPI(api *pilosa.API) HandlerOption {
|
||||
return func(h *Handler) error {
|
||||
h.API = api
|
||||
h.api = api
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ func NewHandler(opts ...HandlerOption) (*Handler, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if handler.API == nil {
|
||||
if handler.api == nil {
|
||||
return nil, errors.New("must pass OptHandlerAPI")
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
// Calculate per request StatsD metrics when the handler is fully configured.
|
||||
statsTags := make([]string, 0, 3)
|
||||
|
||||
longQueryTime := h.API.LongQueryTime()
|
||||
longQueryTime := h.api.LongQueryTime()
|
||||
if longQueryTime > 0 && dif > longQueryTime {
|
||||
h.Logger.Printf("%s %s %v", r.Method, r.URL.String(), dif)
|
||||
statsTags = append(statsTags, "slow_query")
|
||||
|
|
@ -267,7 +267,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// useragent tag identifies internal/external endpoints
|
||||
statsTags = append(statsTags, "useragent:"+r.UserAgent())
|
||||
stats := h.API.StatsWithTags(statsTags)
|
||||
stats := h.api.StatsWithTags(statsTags)
|
||||
if stats != nil {
|
||||
stats.Histogram("http."+endpointName, float64(dif), 0.1)
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ func (h *Handler) handleGetSchema(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
schema := h.API.Schema(r.Context())
|
||||
schema := h.api.Schema(r.Context())
|
||||
if err := json.NewEncoder(w).Encode(map[string]interface{}{"indexes": schema}); err != nil {
|
||||
h.Logger.Printf("write schema response error: %s", err)
|
||||
}
|
||||
|
|
@ -368,9 +368,9 @@ func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
status := getStatusResponse{
|
||||
State: h.API.State(),
|
||||
Nodes: h.API.Hosts(r.Context()),
|
||||
LocalID: h.API.Node().ID,
|
||||
State: h.api.State(),
|
||||
Nodes: h.api.Hosts(r.Context()),
|
||||
LocalID: h.api.Node().ID,
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(status); err != nil {
|
||||
h.Logger.Printf("write status response error: %s", err)
|
||||
|
|
@ -382,7 +382,7 @@ func (h *Handler) handleGetInfo(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, "JSON only acceptable response", http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
info := h.API.Info()
|
||||
info := h.api.Info()
|
||||
if err := json.NewEncoder(w).Encode(info); err != nil {
|
||||
h.Logger.Printf("write info response error: %s", err)
|
||||
}
|
||||
|
|
@ -410,7 +410,7 @@ func (h *Handler) handlePostQuery(w http.ResponseWriter, r *http.Request) {
|
|||
// TODO: Remove
|
||||
req.Index = mux.Vars(r)["index"]
|
||||
|
||||
resp, err := h.API.Query(r.Context(), req)
|
||||
resp, err := h.api.Query(r.Context(), req)
|
||||
if err != nil {
|
||||
switch errors.Cause(resp.Err) {
|
||||
case pilosa.ErrTooManyWrites:
|
||||
|
|
@ -447,7 +447,7 @@ func (h *Handler) handleGetShardsMax(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(getShardsMaxResponse{
|
||||
Standard: h.API.MaxShards(r.Context()),
|
||||
Standard: h.api.MaxShards(r.Context()),
|
||||
}); err != nil {
|
||||
h.Logger.Printf("write shards-max response error: %s", err)
|
||||
}
|
||||
|
|
@ -469,7 +469,7 @@ func (h *Handler) handleGetIndex(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
indexName := mux.Vars(r)["index"]
|
||||
for _, idx := range h.API.Schema(r.Context()) {
|
||||
for _, idx := range h.api.Schema(r.Context()) {
|
||||
if idx.Name == indexName {
|
||||
if err := json.NewEncoder(w).Encode(idx); err != nil {
|
||||
h.Logger.Printf("write response error: %s", err)
|
||||
|
|
@ -563,7 +563,7 @@ func (h *Handler) handleDeleteIndex(w http.ResponseWriter, r *http.Request) {
|
|||
indexName := mux.Vars(r)["index"]
|
||||
|
||||
resp := successResponse{}
|
||||
err := h.API.DeleteIndex(r.Context(), indexName)
|
||||
err := h.api.DeleteIndex(r.Context(), indexName)
|
||||
resp.write(w, err)
|
||||
}
|
||||
|
||||
|
|
@ -584,7 +584,7 @@ func (h *Handler) handlePostIndex(w http.ResponseWriter, r *http.Request) {
|
|||
resp.write(w, err)
|
||||
return
|
||||
}
|
||||
_, err = h.API.CreateIndex(r.Context(), indexName, req.Options)
|
||||
_, err = h.api.CreateIndex(r.Context(), indexName, req.Options)
|
||||
|
||||
resp.write(w, err)
|
||||
}
|
||||
|
|
@ -604,7 +604,7 @@ func (h *Handler) handlePostIndexAttrDiff(w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
attrs, err := h.API.IndexAttrDiff(r.Context(), indexName, req.Blocks)
|
||||
attrs, err := h.api.IndexAttrDiff(r.Context(), indexName, req.Blocks)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == pilosa.ErrIndexNotFound {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
|
|
@ -673,7 +673,7 @@ func (h *Handler) handlePostField(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
_, err = h.API.CreateField(r.Context(), indexName, fieldName, fos...)
|
||||
_, err = h.api.CreateField(r.Context(), indexName, fieldName, fos...)
|
||||
resp.write(w, err)
|
||||
}
|
||||
|
||||
|
|
@ -760,7 +760,7 @@ func (h *Handler) handleDeleteField(w http.ResponseWriter, r *http.Request) {
|
|||
fieldName := mux.Vars(r)["field"]
|
||||
|
||||
resp := successResponse{}
|
||||
err := h.API.DeleteField(r.Context(), indexName, fieldName)
|
||||
err := h.api.DeleteField(r.Context(), indexName, fieldName)
|
||||
resp.write(w, err)
|
||||
}
|
||||
|
||||
|
|
@ -780,7 +780,7 @@ func (h *Handler) handlePostFieldAttrDiff(w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
attrs, err := h.API.FieldAttrDiff(r.Context(), indexName, fieldName, req.Blocks)
|
||||
attrs, err := h.api.FieldAttrDiff(r.Context(), indexName, fieldName, req.Blocks)
|
||||
if err != nil {
|
||||
switch errors.Cause(err) {
|
||||
case pilosa.ErrFragmentNotFound:
|
||||
|
|
@ -826,7 +826,7 @@ func (h *Handler) readProtobufQueryRequest(r *http.Request) (*pilosa.QueryReques
|
|||
}
|
||||
|
||||
qreq := &pilosa.QueryRequest{}
|
||||
err = h.API.Serializer.Unmarshal(body, qreq)
|
||||
err = h.api.Serializer.Unmarshal(body, qreq)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unmarshalling query request")
|
||||
}
|
||||
|
|
@ -869,7 +869,7 @@ func (h *Handler) writeQueryResponse(w http.ResponseWriter, r *http.Request, res
|
|||
|
||||
// writeProtobufQueryResponse writes the response from the executor to w as protobuf.
|
||||
func (h *Handler) writeProtobufQueryResponse(w http.ResponseWriter, resp *pilosa.QueryResponse) error {
|
||||
if buf, err := h.API.Serializer.Marshal(resp); err != nil {
|
||||
if buf, err := h.api.Serializer.Marshal(resp); err != nil {
|
||||
return errors.Wrap(err, "marshalling")
|
||||
} else if _, err := w.Write(buf); err != nil {
|
||||
return errors.Wrap(err, "writing")
|
||||
|
|
@ -897,7 +897,7 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Get index and field type to determine how to handle the
|
||||
// import data.
|
||||
field, err := h.API.Field(r.Context(), indexName, fieldName)
|
||||
field, err := h.api.Field(r.Context(), indexName, fieldName)
|
||||
if err != nil {
|
||||
switch errors.Cause(err) {
|
||||
case pilosa.ErrIndexNotFound:
|
||||
|
|
@ -922,12 +922,12 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
|
|||
// Field type: Int
|
||||
// Marshal into request object.
|
||||
req := &pilosa.ImportValueRequest{}
|
||||
if err := h.API.Serializer.Unmarshal(body, req); err != nil {
|
||||
if err := h.api.Serializer.Unmarshal(body, req); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.API.ImportValue(r.Context(), req); err != nil {
|
||||
if err := h.api.ImportValue(r.Context(), req); err != nil {
|
||||
switch errors.Cause(err) {
|
||||
case pilosa.ErrClusterDoesNotOwnShard:
|
||||
http.Error(w, err.Error(), http.StatusPreconditionFailed)
|
||||
|
|
@ -940,12 +940,12 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
|
|||
// Field type: Set, Time
|
||||
// Marshal into request object.
|
||||
req := &pilosa.ImportRequest{}
|
||||
if err := h.API.Serializer.Unmarshal(body, req); err != nil {
|
||||
if err := h.api.Serializer.Unmarshal(body, req); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.API.Import(r.Context(), req); err != nil {
|
||||
if err := h.api.Import(r.Context(), req); err != nil {
|
||||
switch errors.Cause(err) {
|
||||
case pilosa.ErrClusterDoesNotOwnShard:
|
||||
http.Error(w, err.Error(), http.StatusPreconditionFailed)
|
||||
|
|
@ -957,7 +957,7 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Marshal response object.
|
||||
buf, e := h.API.Serializer.Marshal(&pilosa.ImportResponse{Err: ""})
|
||||
buf, e := h.api.Serializer.Marshal(&pilosa.ImportResponse{Err: ""})
|
||||
if e != nil {
|
||||
http.Error(w, fmt.Sprintf("marshal import response"), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -988,7 +988,7 @@ func (h *Handler) handleGetExportCSV(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if err = h.API.ExportCSV(r.Context(), index, field, shard, w); err != nil {
|
||||
if err = h.api.ExportCSV(r.Context(), index, field, shard, w); err != nil {
|
||||
switch errors.Cause(err) {
|
||||
case pilosa.ErrFragmentNotFound:
|
||||
break
|
||||
|
|
@ -1018,7 +1018,7 @@ func (h *Handler) handleGetFragmentNodes(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
// Retrieve fragment owner nodes.
|
||||
nodes, err := h.API.ShardNodes(r.Context(), index, shard)
|
||||
nodes, err := h.api.ShardNodes(r.Context(), index, shard)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
|
@ -1032,7 +1032,7 @@ func (h *Handler) handleGetFragmentNodes(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
// handleGetFragmentBlockData handles GET /internal/fragment/block/data requests.
|
||||
func (h *Handler) handleGetFragmentBlockData(w http.ResponseWriter, r *http.Request) {
|
||||
buf, err := h.API.FragmentBlockData(r.Context(), r.Body)
|
||||
buf, err := h.api.FragmentBlockData(r.Context(), r.Body)
|
||||
if err != nil {
|
||||
if _, ok := err.(pilosa.BadRequestError); ok {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
|
|
@ -1064,7 +1064,7 @@ func (h *Handler) handleGetFragmentBlocks(w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
blocks, err := h.API.FragmentBlocks(r.Context(), q.Get("index"), q.Get("field"), shard)
|
||||
blocks, err := h.api.FragmentBlocks(r.Context(), q.Get("index"), q.Get("field"), shard)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == pilosa.ErrFragmentNotFound {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
|
|
@ -1095,7 +1095,7 @@ func (h *Handler) handleGetVersion(w http.ResponseWriter, r *http.Request) {
|
|||
err := json.NewEncoder(w).Encode(struct {
|
||||
Version string `json:"version"`
|
||||
}{
|
||||
Version: h.API.Version(),
|
||||
Version: h.api.Version(),
|
||||
})
|
||||
if err != nil {
|
||||
h.Logger.Printf("write version response error: %s", err)
|
||||
|
|
@ -1152,7 +1152,7 @@ func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r
|
|||
return
|
||||
}
|
||||
|
||||
oldNode, newNode, err := h.API.SetCoordinator(r.Context(), req.ID)
|
||||
oldNode, newNode, err := h.api.SetCoordinator(r.Context(), req.ID)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == pilosa.ErrNodeIDNotExists {
|
||||
http.Error(w, "setting new coordinator: "+err.Error(), http.StatusNotFound)
|
||||
|
|
@ -1193,7 +1193,7 @@ func (h *Handler) handlePostClusterResizeRemoveNode(w http.ResponseWriter, r *ht
|
|||
return
|
||||
}
|
||||
|
||||
removeNode, err := h.API.RemoveNode(req.ID)
|
||||
removeNode, err := h.api.RemoveNode(req.ID)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == pilosa.ErrNodeIDNotExists {
|
||||
http.Error(w, "removing node: "+err.Error(), http.StatusNotFound)
|
||||
|
|
@ -1225,7 +1225,7 @@ func (h *Handler) handlePostClusterResizeAbort(w http.ResponseWriter, r *http.Re
|
|||
http.Error(w, "JSON only acceptable response", http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
err := h.API.ResizeAbort()
|
||||
err := h.api.ResizeAbort()
|
||||
var msg string
|
||||
if err != nil {
|
||||
switch errors.Cause(err) {
|
||||
|
|
@ -1252,7 +1252,7 @@ type clusterResizeAbortResponse struct {
|
|||
}
|
||||
|
||||
func (h *Handler) handleRecalculateCaches(w http.ResponseWriter, r *http.Request) {
|
||||
err := h.API.RecalculateCaches(r.Context())
|
||||
err := h.api.RecalculateCaches(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "recalculating caches: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -1272,7 +1272,7 @@ func (h *Handler) handlePostClusterMessage(w http.ResponseWriter, r *http.Reques
|
|||
return
|
||||
}
|
||||
|
||||
err := h.API.ClusterMessage(r.Context(), r.Body)
|
||||
err := h.api.ClusterMessage(r.Context(), r.Body)
|
||||
if err != nil {
|
||||
// TODO this was the previous behavior, but perhaps not everything is a bad request
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
|
|
@ -1291,7 +1291,7 @@ func (h *Handler) handleGetTranslateData(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
pipeR, pipeW := io.Pipe()
|
||||
|
||||
err := h.API.GetTranslateData(r.Context(), pipeW, offset)
|
||||
err := h.api.GetTranslateData(r.Context(), pipeW, offset)
|
||||
|
||||
if err != nil {
|
||||
if errors.Cause(err) == pilosa.ErrNotImplemented {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue