mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
change NewTranslateStore() to take an interface for backward compatibility
This commit is contained in:
parent
debd470211
commit
d50a0e853c
5 changed files with 28 additions and 12 deletions
|
|
@ -48,7 +48,7 @@ type Holder struct {
|
|||
|
||||
// Key/ID translation
|
||||
translateFile *TranslateFile
|
||||
NewPrimaryTranslateStore func(*Node) TranslateStore
|
||||
NewPrimaryTranslateStore func(interface{}) TranslateStore
|
||||
|
||||
// opened channel is closed once Open() completes.
|
||||
opened chan struct{}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/pilosa/pilosa"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Ensure implementation implements inteface.
|
||||
|
|
@ -22,14 +24,28 @@ type translateStore struct {
|
|||
node *pilosa.Node
|
||||
}
|
||||
|
||||
// DEPRECATED: NewTranslateStore returns a new instance of translateStore.
|
||||
func NewTranslateStore(rawurl string) *translateStore { // nolint: unparam
|
||||
return &translateStore{node: nil}
|
||||
}
|
||||
|
||||
// NewNodeTranslateStore returns a new instance of TranslateStore based on node.
|
||||
func NewNodeTranslateStore(node *pilosa.Node) pilosa.TranslateStore {
|
||||
return &translateStore{node: node}
|
||||
// NewTranslateStore returns a new instance of TranslateStore based on node.
|
||||
// DEPRECATED: Providing a string url to this function is being deprecated. Instead,
|
||||
// provide a *pilosa.Node.
|
||||
func NewTranslateStore(node interface{}) pilosa.TranslateStore {
|
||||
var n *pilosa.Node
|
||||
switch v := node.(type) {
|
||||
case string:
|
||||
log.Printf("WARNING: providing a string url to NewTranslateStore() has been deprecated.")
|
||||
if uri, err := pilosa.NewURIFromAddress(v); err != nil {
|
||||
log.Println(errors.Wrap(err, "creating uri"))
|
||||
} else {
|
||||
n = &pilosa.Node{
|
||||
ID: v,
|
||||
URI: *uri,
|
||||
}
|
||||
}
|
||||
case *pilosa.Node:
|
||||
n = v
|
||||
default:
|
||||
log.Printf("WARNING: a *pilosa.Node is the only type supported by NewTranslateStore().")
|
||||
}
|
||||
return &translateStore{node: n}
|
||||
}
|
||||
|
||||
// TranslateColumnsToUint64 is not currently implemented.
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ func OptServerPrimaryTranslateStore(store TranslateStore) ServerOption {
|
|||
}
|
||||
}
|
||||
|
||||
func OptServerPrimaryTranslateStoreFunc(tf func(*Node) TranslateStore) ServerOption {
|
||||
func OptServerPrimaryTranslateStoreFunc(tf func(interface{}) TranslateStore) ServerOption {
|
||||
return func(s *Server) error {
|
||||
s.holder.NewPrimaryTranslateStore = tf
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ func (m *Command) SetupServer() error {
|
|||
pilosa.OptServerStatsClient(statsClient),
|
||||
pilosa.OptServerURI(uri),
|
||||
pilosa.OptServerInternalClient(http.NewInternalClientFromURI(uri, c)),
|
||||
pilosa.OptServerPrimaryTranslateStoreFunc(http.NewNodeTranslateStore),
|
||||
pilosa.OptServerPrimaryTranslateStoreFunc(http.NewTranslateStore),
|
||||
pilosa.OptServerClusterDisabled(m.Config.Cluster.Disabled, m.Config.Cluster.Hosts),
|
||||
pilosa.OptServerSerializer(proto.Serializer{}),
|
||||
coordinatorOpt,
|
||||
|
|
|
|||
|
|
@ -1083,7 +1083,7 @@ var nopTStore TranslateStore = nopTranslateStore{}
|
|||
|
||||
// newNopTranslateStore returns a translate store which does nothing. It returns a global
|
||||
// object to avoid unnecessary allocations.
|
||||
func newNopTranslateStore(*Node) TranslateStore { return nopTStore }
|
||||
func newNopTranslateStore(interface{}) TranslateStore { return nopTStore }
|
||||
|
||||
// nopTranslateStore represents a no-op implementation of the TranslateStore interface.
|
||||
type nopTranslateStore struct{}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue