forked from micro/go-micro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
152 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,60 @@ | ||
package cloudflare | ||
|
||
import ( | ||
"github.com/micro/go-micro/config/options" | ||
"context" | ||
|
||
"github.com/micro/go-micro/store" | ||
) | ||
|
||
func getOption(ctx context.Context, key string) string { | ||
if ctx == nil { | ||
return "" | ||
} | ||
val, ok := ctx.Value(key).(string) | ||
if !ok { | ||
return "" | ||
} | ||
return val | ||
} | ||
|
||
func getToken(ctx context.Context) string { | ||
return getOption(ctx, "CF_API_TOKEN") | ||
} | ||
|
||
func getAccount(ctx context.Context) string { | ||
return getOption(ctx, "CF_ACCOUNT_ID") | ||
} | ||
|
||
func getNamespace(ctx context.Context) string { | ||
return getOption(ctx, "KV_NAMESPACE_ID") | ||
} | ||
|
||
// Token sets the cloudflare api token | ||
func Token(t string) options.Option { | ||
// TODO: change to store.cf.api_token | ||
return options.WithValue("CF_API_TOKEN", t) | ||
func Token(t string) store.Option { | ||
return func(o *store.Options) { | ||
if o.Context == nil { | ||
o.Context = context.Background() | ||
} | ||
o.Context = context.WithValue(o.Context, "CF_API_TOKEN", t) | ||
} | ||
} | ||
|
||
// Account sets the cloudflare account id | ||
func Account(id string) options.Option { | ||
// TODO: change to store.cf.account_id | ||
return options.WithValue("CF_ACCOUNT_ID", id) | ||
func Account(id string) store.Option { | ||
return func(o *store.Options) { | ||
if o.Context == nil { | ||
o.Context = context.Background() | ||
} | ||
o.Context = context.WithValue(o.Context, "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) | ||
func Namespace(ns string) store.Option { | ||
return func(o *store.Options) { | ||
if o.Context == nil { | ||
o.Context = context.Background() | ||
} | ||
o.Context = context.WithValue(o.Context, "KV_NAMESPACE_ID", ns) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.