change NewTranslateStore() to take an interface for backward compatibility

This commit is contained in:
Travis Turner 2018-08-13 12:04:22 -05:00
parent debd470211
commit d50a0e853c
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
5 changed files with 28 additions and 12 deletions

View file

@ -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{}

View file

@ -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.

View file

@ -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

View file

@ -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,

View file

@ -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{}