config

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPClientLoggerKey = "gae.service.config.http"

HTTPClientLoggerKey is a xlog key for this package

View Source
const ServiceConfigKindLoggerKey = "ent.service_config"

ServiceConfigKindLoggerKey is a logger key name for the ent

View Source
const ServiceConfigQueryLoggerKey = "ent.query.service_config"

ServiceConfigQueryLoggerKey is a logger key name for the ent

Variables

View Source
var DefaultServiceConfigKind = &ServiceConfigKind{}

DefaultServiceConfigKind is a default value of *ServiceConfigKind

Functions

func Global

func Global(key string, defaultValue string, description string)

Global register a service configuration shared in whole applications, and it can be overwritten by a service.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is a struct to access configurations represented by *ServiceConfig

func New

func New() *Config

New returns a new *Config object

func (*Config) All

func (c *Config) All(ctx context.Context) []*ServiceConfig

All returns all *ServiceConfig in app.

func (*Config) GenPageConfig

func (c *Config) GenPageConfig(ctx context.Context) *react.PageConfig

GenPageConfig returns *react.PageConfig from configuration datastore.

func (*Config) Get

func (c *Config) Get(ctx context.Context, key string) *ServiceConfig

Get gets the *ServiceConfig

func (*Config) GetBoolDefaultValue

func (c *Config) GetBoolDefaultValue(key string) bool

GetBoolDefaultValue returns the default value by `key` as bool

func (*Config) GetBoolValue

func (c *Config) GetBoolValue(ctx context.Context, key string) bool

GetBoolValue is like GetValue and return the value as bool. If invalid int value is set on `key` this will return a default value of `key`.

func (*Config) GetDefaultValue

func (c *Config) GetDefaultValue(key string) string

GetDefaultValue returns the default value by `key`

func (*Config) GetFacebookConfig

func (c *Config) GetFacebookConfig(ctx context.Context) *OAuth2Config

GetFacebookConfig returns OAuth2 config for facebook.

func (*Config) GetFloatDefaultValue

func (c *Config) GetFloatDefaultValue(key string) float64

GetFloatDefaultValue returns the default value by `key` as float64

func (*Config) GetFloatValue

func (c *Config) GetFloatValue(ctx context.Context, key string) float64

GetFloatValue is like GetValue and return the value as float64. If invalid int value is set on `key` this will return a default value of `key`.

func (*Config) GetIntDefaultValue

func (c *Config) GetIntDefaultValue(key string) int

GetIntDefaultValue returns the default value by `key` as int

func (*Config) GetIntValue

func (c *Config) GetIntValue(ctx context.Context, key string) int

GetIntValue is like GetValue and return the value as int. If invalid int value is set on `key` this will return a default value of `key`.

func (*Config) GetMessengerVerificationToken

func (c *Config) GetMessengerVerificationToken(ctx context.Context) string

GetMessengerVerificationToken returns messenger verification token string

func (*Config) GetValue

func (c *Config) GetValue(ctx context.Context, key string) string

GetValue is like Get but returns only the value as string.

func (*Config) LoadFromJSON

func (c *Config) LoadFromJSON(ctx context.Context, path string)

LoadFromJSON loads config values from a given file path

func (*Config) NewHTTPClient

func (c *Config) NewHTTPClient(ctx context.Context) *http.Client

NewHTTPClient is an http client available in this context

func (*Config) NewMessengerSender

func (c *Config) NewMessengerSender(ctx context.Context) (*messenger.Sender, error)

NewMessengerSender returns a new *messenger.Sender from server configuration

func (*Config) Register

func (c *Config) Register(key string, defaultValue string, description string)

Register registers configuration variable in application

func (*Config) Set

func (c *Config) Set(ctx context.Context, cfg *ServiceConfig)

Set sets the *ServiceConfig

func (*Config) SetValue

func (c *Config) SetValue(ctx context.Context, key string, value string)

SetValue set the new value on key

type OAuth2Config

type OAuth2Config struct {
	ClientID     string
	ClientSecret string
}

OAuth2Config is a configuration object for oauth2 clients

type ServiceConfig

type ServiceConfig struct {
	Key       string    `json:"key" ent:"id"`
	Value     string    `json:"value" ent:"form" datastore:",noindex"`
	UpdatedAt time.Time `json:"updated_at" ent:"timestamp" datastore:",noindex"`

	Description  string `json:"description" datastore:"-"`
	DefaultValue string `json:"default_value" datastore:"-"`
	GlobalValue  string `json:"global_value" datastore:"-"`
	// contains filtered or unexported fields
}

ServiceConfig is a configuration object for a service

func NewServiceConfig

func NewServiceConfig() *ServiceConfig

NewServiceConfig returns a new *ServiceConfig with default field values.

func (*ServiceConfig) NewKey

func (s *ServiceConfig) NewKey(ctx context.Context) *datastore.Key

func (*ServiceConfig) UpdateByForm

func (s *ServiceConfig) UpdateByForm(form *keyvalue.GetProxy)

UpdateByForm updates the fields by form values. All values should be validated before calling this function.

type ServiceConfigKind

type ServiceConfigKind struct {
	// contains filtered or unexported fields
}

func (*ServiceConfigKind) Delete

func (k *ServiceConfigKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)

Delete deletes the entity from datastore

func (*ServiceConfigKind) DeleteMatched

func (k *ServiceConfigKind) DeleteMatched(ctx context.Context, q *ServiceConfigQuery) (int, error)

DeleteMatched deletes the all ents that match with the query. This func modify Limit/StartKey condition in the query so that you should restore it if you want to reuse the query.

func (*ServiceConfigKind) DeleteMulti

func (k *ServiceConfigKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)

DeleteMulti do Delete with multiple keys

func (*ServiceConfigKind) EnforceNamespace

func (k *ServiceConfigKind) EnforceNamespace(ns string, b bool) *ServiceConfigKind

EnforceNamespace enforces namespace for Get/Put/Delete or not.

func (*ServiceConfigKind) Get

func (k *ServiceConfigKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *ServiceConfig, error)

Get gets the kind entity from datastore

func (*ServiceConfigKind) GetMulti

func (k *ServiceConfigKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*ServiceConfig, error)

GetMulti do Get with multiple keys. keys must be []string, []*datastore.Key, or []interface{}

func (*ServiceConfigKind) MustDelete

func (k *ServiceConfigKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key

MustDelete is like Delete but panic if an error occurs

func (*ServiceConfigKind) MustDeleteMulti

func (k *ServiceConfigKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key

MustDeleteMulti is like DeleteMulti but panic if an error occurs

func (*ServiceConfigKind) MustGet

func (k *ServiceConfigKind) MustGet(ctx context.Context, key interface{}) *ServiceConfig

MustGet is like Get but returns only values and panic if error happens.

func (*ServiceConfigKind) MustGetMulti

func (k *ServiceConfigKind) MustGetMulti(ctx context.Context, keys interface{}) []*ServiceConfig

MustGetMulti is like GetMulti but returns only values and panic if error happens.

func (*ServiceConfigKind) MustPut

MustPut is like Put and panic if an error occurrs.

func (*ServiceConfigKind) MustPutMulti

func (k *ServiceConfigKind) MustPutMulti(ctx context.Context, ents []*ServiceConfig) []*datastore.Key

MustPutMulti is like PutMulti but panic if an error occurs

func (*ServiceConfigKind) MustReplace

func (*ServiceConfigKind) MustReplaceMulti

func (k *ServiceConfigKind) MustReplaceMulti(ctx context.Context, ents []*ServiceConfig, replacer ServiceConfigKindReplacer) ([]*datastore.Key, []*ServiceConfig)

func (*ServiceConfigKind) Put

Put puts the entity to datastore.

func (*ServiceConfigKind) PutMulti

func (k *ServiceConfigKind) PutMulti(ctx context.Context, ents []*ServiceConfig) ([]*datastore.Key, error)

PutMulti do Put with multiple keys

func (*ServiceConfigKind) Replace

func (*ServiceConfigKind) ReplaceMulti

func (k *ServiceConfigKind) ReplaceMulti(ctx context.Context, ents []*ServiceConfig, replacer ServiceConfigKindReplacer) ([]*datastore.Key, []*ServiceConfig, error)

func (*ServiceConfigKind) UseDefaultIfNil

func (k *ServiceConfigKind) UseDefaultIfNil(b bool) *ServiceConfigKind

type ServiceConfigKindReplacer

type ServiceConfigKindReplacer interface {
	Replace(*ServiceConfig, *ServiceConfig) *ServiceConfig
}

type ServiceConfigKindReplacerFunc

type ServiceConfigKindReplacerFunc func(*ServiceConfig, *ServiceConfig) *ServiceConfig

func (ServiceConfigKindReplacerFunc) Replace

type ServiceConfigPagination

type ServiceConfigPagination struct {
	Start string           `json:"start"`
	End   string           `json:"end"`
	Count int              `json:"count,omitempty"`
	Data  []*ServiceConfig `json:"data"`
	Keys  []*datastore.Key `json:"-"`
}

type ServiceConfigQuery

type ServiceConfigQuery struct {
	// contains filtered or unexported fields
}

ServiceConfigQuery helps to build and execute a query

func NewServiceConfigQuery

func NewServiceConfigQuery() *ServiceConfigQuery

func (*ServiceConfigQuery) Ancestor

Ancestor sets the ancestor filter

func (*ServiceConfigQuery) Asc

Asc specifies ascending order on the given filed.

func (*ServiceConfigQuery) Count

func (q *ServiceConfigQuery) Count(ctx context.Context) (int, error)

Count returns the count of entities

func (*ServiceConfigQuery) Desc

Desc specifies descending order on the given filed.

func (*ServiceConfigQuery) End

Limit specifies the numbe of limit returend by this query.

func (*ServiceConfigQuery) Eq

Eq sets the "=" filter on the name field.

func (*ServiceConfigQuery) Ge

Ge sets the ">=" filter on the "name" field.

func (*ServiceConfigQuery) GetAll

GetAll returns all key and value of the query.

func (*ServiceConfigQuery) GetAllValues

func (q *ServiceConfigQuery) GetAllValues(ctx context.Context) ([]*ServiceConfig, error)

GetAllValues is like GetAll but returns only values

func (*ServiceConfigQuery) Gt

Gt sets the ">" filter on the "name" field.

func (*ServiceConfigQuery) Le

Le sets the "<=" filter on the "name" field.

func (*ServiceConfigQuery) Limit

Limit specifies the numbe of limit returend by this query.

func (*ServiceConfigQuery) Lt

Lt sets the "<" filter on the "name" field.

func (*ServiceConfigQuery) MustCount

func (q *ServiceConfigQuery) MustCount(ctx context.Context) int

MustCount returns the count of entities

func (*ServiceConfigQuery) MustGetAll

func (q *ServiceConfigQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*ServiceConfig)

MustGetAll is like GetAll but panic if an error occurrs.

func (*ServiceConfigQuery) MustGetAllValues

func (q *ServiceConfigQuery) MustGetAllValues(ctx context.Context) []*ServiceConfig

MustGetAllValues is like GetAllValues but panic if an error occurrs

func (*ServiceConfigQuery) MustRun

MustRun is like Run but panic if an error occurrs

func (*ServiceConfigQuery) Ne

Ne sets the "!=" filter on the "name" field.

func (*ServiceConfigQuery) Run

Run returns the a result as *ServiceConfigPagination object

func (*ServiceConfigQuery) Start

Limit specifies the numbe of limit returend by this query.

func (*ServiceConfigQuery) ViaKeys

ViaKeys optimize to execute keys-only query then call k.GetMulti() to fetch values. This would reduce the datastore query and maximize the memcache usage if the query called many times in a short time window.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL