Update options usage in store/api

This commit is contained in:
Asim Aslam
2019-10-23 22:31:36 +01:00
parent 3fc04f4dff
commit d65658c890
5 changed files with 57 additions and 36 deletions

View File

@@ -32,7 +32,7 @@ type workersKV struct {
// Options expects CF_API_TOKEN to a cloudflare API token scoped to Workers KV,
// CF_ACCOUNT_ID to contain a string with your cloudflare account ID and
// KV_NAMESPACE_ID to contain the namespace UUID for your KV storage.
func New(opts ...options.Option) (store.Store, error) {
func NewStore(opts ...options.Option) (store.Store, error) {
// Validate Options
options := options.NewOptions(opts...)
apiToken, ok := options.Values().Get("CF_API_TOKEN")

View File

@@ -7,7 +7,6 @@ import (
"testing"
"time"
"github.com/micro/go-micro/config/options"
"github.com/micro/go-micro/store"
)
@@ -21,10 +20,10 @@ func TestCloudflare(t *testing.T) {
randomK := strconv.Itoa(rand.Int())
randomV := strconv.Itoa(rand.Int())
wkv, err := New(
options.WithValue("CF_API_TOKEN", apiToken),
options.WithValue("CF_ACCOUNT_ID", accountID),
options.WithValue("KV_NAMESPACE_ID", kvID),
wkv, err := NewStore(
ApiToken(apiToken),
AccountID(accountID),
Namespace(kvID),
)
if err != nil {

View File

@@ -0,0 +1,23 @@
package cloudflare
import (
"github.com/micro/go-micro/config/options"
)
// Token sets the cloudflare api token
func ApiToken(t string) options.Option {
// TODO: change to store.cf.api_token
return options.WithValue("CF_API_TOKEN", t)
}
// AccountID sets the cloudflare account id
func AccountID(id string) options.Option {
// TODO: change to store.cf.account_id
return options.WithValue("CF_ACCOUNT_ID", id)
}
// Namespace sets the KV namespace
func Namespace(ns string) options.Option {
// TODO: change to store.cf.namespace
return options.WithValue("KV_NAMESPACE_ID", ns)
}