本文整理汇总了Golang中github.com/corestoreio/csfw/config.Path函数的典型用法代码示例。如果您正苦于以下问题:Golang Path函数的具体用法?Golang Path怎么用?Golang Path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestPubSubBubbling
func TestPubSubBubbling(t *testing.T) {
defer errLogBuf.Reset()
testPath := "a/b/c"
m := config.NewManager()
_, err := m.Subscribe("", nil)
assert.EqualError(t, err, config.ErrPathEmpty.Error())
subID, err := m.Subscribe(testPath, &testSubscriber{
f: func(path string, sg scope.Scope, id int64) error {
assert.Equal(t, testPath, path)
if sg == scope.DefaultID {
assert.Equal(t, int64(0), id)
} else {
assert.Equal(t, int64(123), id)
}
return nil
},
})
assert.NoError(t, err)
assert.Equal(t, 1, subID, "The very first subscription ID should be 1")
assert.NoError(t, m.Write(config.Value(1), config.Path(testPath), config.Scope(scope.WebsiteID, 123)))
assert.NoError(t, m.Close())
time.Sleep(time.Millisecond * 10) // wait for goroutine to close
// send on closed channel
assert.NoError(t, m.Write(config.Value(1), config.Path(testPath+"Doh"), config.Scope(scope.WebsiteID, 3)))
assert.EqualError(t, m.Close(), config.ErrPublisherClosed.Error())
}
开发者ID:levcom,项目名称:csfw,代码行数:32,代码来源:manager_pubsub_test.go
示例2: quota
func (t *HTTPRateLimit) quota() throttled.RateQuota {
var burst, request int
var duration string
if burst, _ = t.Config.GetInt(config.Path(PathRateLimitBurst)); burst < 0 {
burst = DefaultBurst
}
if request, _ = t.Config.GetInt(config.Path(PathRateLimitRequests)); request == 0 {
request = DefaultRequests
}
if duration, _ = t.Config.GetString(config.Path(PathRateLimitDuration)); duration == "" {
duration = DefaultDuration
}
var r throttled.Rate
switch duration {
case "s": // second
r = throttled.PerSec(request)
case "i": // minute
r = throttled.PerMin(request)
case "h": // hour
r = throttled.PerHour(request)
case "d": // day
r = throttled.PerDay(request)
default:
r = throttled.PerHour(request)
}
return throttled.RateQuota{r, burst}
}
开发者ID:levcom,项目名称:csfw,代码行数:30,代码来源:http.go
示例3: ConfigString
// ConfigString tries to get a value from the scopeStore if empty
// falls back to default global scope.
// If using etcd or consul maybe this can lead to round trip times because of network access.
func (w *Website) ConfigString(path ...string) string {
val := w.cr.GetString(config.ScopeWebsite(w.WebsiteID()), config.Path(path...))
if val == "" {
val = w.cr.GetString(config.Path(path...))
}
return val
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:10,代码来源:website.go
示例4: ConfigString
// ConfigString tries to get a value from the scopeStore if empty
// falls back to default global scope.
// If using etcd or consul maybe this can lead to round trip times because of network access.
func (s *Store) ConfigString(path ...string) string {
val := s.cr.GetString(config.ScopeStore(s.StoreID()), config.Path(path...)) // TODO(cs) check for not bubbeling
if val == "" {
val = s.cr.GetString(config.Path(path...))
}
return val
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:10,代码来源:store.go
示例5: ConfigString
// ConfigString tries to get a value from the scopeStore if empty
// falls back to default global scope.
// If using etcd or consul maybe this can lead to round trip times because of network access.
func (s *Store) ConfigString(path ...string) string {
val := s.cr.GetString(config.ScopeStore(s), config.Path(path...))
if val == "" {
val = s.cr.GetString(config.Path(path...))
}
return val
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:10,代码来源:store.go
示例6: TestApplyCoreConfigData
// TestApplyCoreConfigData reads from the MySQL core_config_data table and applies
// these value to the underlying storage. tries to get back the values from the
// underlying storage
func TestApplyCoreConfigData(t *testing.T) {
defer debugLogBuf.Reset()
defer infoLogBuf.Reset()
dbc := csdb.MustConnectTest()
defer func() { assert.NoError(t, dbc.Close()) }()
sess := dbc.NewSession(nil) // nil tricks the NewSession ;-)
s := config.NewService()
defer func() { assert.NoError(t, s.Close()) }()
loadedRows, writtenRows, err := s.ApplyCoreConfigData(sess)
if err != nil {
t.Fatal(err)
}
assert.True(t, loadedRows > 9, "loadedRows %d", loadedRows)
assert.True(t, writtenRows > 9, "writtenRows %d", writtenRows)
// println("\n", debugLogBuf.String(), "\n")
// println("\n", infoLogBuf.String(), "\n")
assert.NoError(t, s.Write(config.Path("web/secure/offloader_header"), config.ScopeDefault(), config.Value("SSL_OFFLOADED")))
h, err := s.String(config.Path("web/secure/offloader_header"), config.ScopeDefault())
assert.NoError(t, err)
assert.Exactly(t, "SSL_OFFLOADED", h)
assert.Len(t, s.Storage.AllKeys(), writtenRows)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:32,代码来源:service_test.go
示例7: TestPubSubBubbling
func TestPubSubBubbling(t *testing.T) {
defer debugLogBuf.Reset()
testPath := "a/b/c"
s := config.NewService()
_, err := s.Subscribe("", nil)
assert.EqualError(t, err, config.ErrPathEmpty.Error())
subID, err := s.Subscribe(testPath, &testSubscriber{
f: func(path string, sg scope.Scope, id int64) error {
assert.Equal(t, testPath, path)
if sg == scope.DefaultID {
assert.Equal(t, int64(0), id)
} else {
assert.Equal(t, int64(123), id)
}
return nil
},
})
assert.NoError(t, err)
assert.Equal(t, 1, subID, "The very first subscription ID should be 1")
assert.NoError(t, s.Write(config.Value(1), config.Path(testPath), config.Scope(scope.WebsiteID, 123)))
assert.NoError(t, s.Close())
// send on closed channel
assert.NoError(t, s.Write(config.Value(1), config.Path(testPath+"Doh"), config.Scope(scope.WebsiteID, 3)))
assert.EqualError(t, s.Close(), config.ErrPublisherClosed.Error())
}
开发者ID:joao-parana,项目名称:csfw,代码行数:30,代码来源:service_pubsub_test.go
示例8: WithValidateBaseURL
// WithValidateBaseURL is a middleware which checks if the request base URL
// is equal to the one store in the configuration, if not
// i.e. redirect from http://example.com/store/ to http://www.example.com/store/
// @see app/code/Magento/Store/App/FrontController/Plugin/RequestPreprocessor.php
func WithValidateBaseURL(cr config.ReaderPubSuber) ctxhttp.Middleware {
// Having the GetBool command here, means you must restart the app to take
// changes in effect. @todo refactor and use pub/sub to automatically change
// the isRedirectToBase value.
checkBaseURL, err := cr.GetBool(config.Path(PathRedirectToBase)) // scope default
if config.NotKeyNotFoundError(err) && PkgLog.IsDebug() {
PkgLog.Debug("ctxhttp.WithValidateBaseUrl.GetBool", "err", err, "path", PathRedirectToBase)
}
redirectCode := http.StatusMovedPermanently
if rc, err := cr.GetInt(config.Path(PathRedirectToBase)); rc != redirectCode && false == config.NotKeyNotFoundError(err) {
redirectCode = http.StatusFound
}
return func(h ctxhttp.Handler) ctxhttp.Handler {
return ctxhttp.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
if checkBaseURL && r.Method != "POST" {
_, requestedStore, err := FromContextReader(ctx)
if err != nil {
if PkgLog.IsDebug() {
PkgLog.Debug("ctxhttp.WithValidateBaseUrl.FromContextServiceReader", "err", err, "ctx", ctx)
}
return errgo.Mask(err)
}
baseURL, err := requestedStore.BaseURL(config.URLTypeWeb, requestedStore.IsCurrentlySecure(r))
if err != nil {
if PkgLog.IsDebug() {
PkgLog.Debug("ctxhttp.WithValidateBaseUrl.requestedStore.BaseURL", "err", err, "ctx", ctx)
}
return errgo.Mask(err)
}
if err := httputils.IsBaseURLCorrect(r, &baseURL); err != nil {
if PkgLog.IsDebug() {
PkgLog.Debug("store.WithValidateBaseUrl.IsBaseUrlCorrect.error", "err", err, "baseURL", baseURL, "request", r)
}
baseURL.Path = r.URL.Path
baseURL.RawPath = r.URL.RawPath
baseURL.RawQuery = r.URL.RawQuery
baseURL.Fragment = r.URL.Fragment
http.Redirect(w, r, (&baseURL).String(), redirectCode)
return nil
}
}
return h.ServeHTTPContext(ctx, w, r)
})
}
}
开发者ID:levcom,项目名称:csfw,代码行数:57,代码来源:middleware.go
示例9: getPort
func (u *uniqueID) getPort() int {
p := u.config.GetInt(config.Path(PathSmtpPort), config.ScopeStore(u.scopeID))
if p < 1 {
p = defaultPort
}
return p
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:7,代码来源:daemon_unique_id.go
示例10: WithPasswordFromConfig
// WithPasswordFromConfig retrieves the password from the configuration with path
// as defined in constant PathJWTPassword
func WithPasswordFromConfig(cr config.Getter) Option {
pw, err := cr.String(config.Path(PathJWTPassword))
if config.NotKeyNotFoundError(err) {
pw = string(uuid.NewRandom())
}
return WithPassword([]byte(pw))
}
开发者ID:joao-parana,项目名称:csfw,代码行数:9,代码来源:options.go
示例11: getPort
func (c *emailConfig) getPort(s config.ScopeIDer) int {
p := c.Config.GetInt(config.Path(PathSmtpPort), config.ScopeStore(s))
if p < 1 {
p = defaultPort
}
return p
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:7,代码来源:daemon_dialer.go
示例12: getHost
func (c *emailConfig) getHost(s config.ScopeIDer) string {
h := c.Config.GetString(config.Path(PathSmtpHost), config.ScopeStore(s))
if h == "" {
h = defaultHost
}
return h
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:7,代码来源:daemon_dialer.go
示例13: BaseCurrencyCode
// BaseCurrencyCode retrieves application base currency code
func BaseCurrencyCode(cr config.Reader) (language.Currency, error) {
base, err := cr.GetString(config.Path(PathCurrencyBase))
if config.NotKeyNotFoundError(err) {
return language.Currency{}, err
}
return language.ParseCurrency(base)
}
开发者ID:levcom,项目名称:csfw,代码行数:8,代码来源:currency.go
示例14: getPort
func (dm *Daemon) getPort() int {
p := dm.config.GetInt(config.Path(PathSmtpPort), config.ScopeStore(dm.scopeID))
if p < 1 {
p = defaultPort
}
return p
}
开发者ID:optimuse,项目名称:csfw,代码行数:7,代码来源:daemon.go
示例15: getHost
func (dm *Daemon) getHost() string {
h := dm.config.GetString(config.Path(PathSmtpHost), config.ScopeStore(dm.scopeID))
if h == "" {
h = defaultHost
}
return h
}
开发者ID:optimuse,项目名称:csfw,代码行数:7,代码来源:daemon.go
示例16: SetMandrill
// SetMandrill sets the Mandrill API for sending emails. This function is not
// recursive and returns nil. @todo
func SetMandrill(opts ...MandrillOptions) DaemonOption {
return func(da *Daemon) DaemonOption {
// this whole func is just a quick write down. no idea if it's working
// and refactor ... 8-)
apiKey := da.Config.GetString(config.ScopeStore(da.ScopeID), config.Path(PathSmtpMandrillAPIKey))
if apiKey == "" {
da.lastErrs = append(da.lastErrs, errors.New("Mandrill API Key is empty."))
return nil
}
md, err := gochimp.NewMandrill(apiKey)
if err != nil {
da.lastErrs = append(da.lastErrs, err)
return nil
}
for _, o := range opts {
o(md)
}
da.sendFunc = func(from string, to []string, msg io.WriterTo) error {
// @todo figure out if "to" contains To, CC and BCC addresses.
addr, err := mail.ParseAddress(from)
if err != nil {
return log.Error("mail.daemon.Mandrill.ParseAddress", "err", err, "from", from, "to", to)
}
r := gochimp.Recipient{
Name: addr.Name,
Email: addr.Address,
}
var buf bytes.Buffer
if _, err := msg.WriteTo(&buf); err != nil {
return log.Error("mail.daemon.Mandrill.MessageWriteTo", "err", err, "from", from, "to", to, "msg", buf.String())
}
resp, err := md.MessageSendRaw(buf.String(), to, r, false)
if err != nil {
return log.Error("mail.daemon.Mandrill.MessageSendRaw", "err", err, "from", from, "to", to, "msg", buf.String())
}
if log.IsDebug() {
log.Debug("mail.daemon.Mandrill.MessageSendRaw", "resp", resp, "from", from, "to", to, "msg", buf.String())
}
// The last arg in MessageSendRaw means async in the Mandrill API:
// Async: enable a background sending mode that is optimized for bulk sending.
// In async mode, messages/send will immediately return a status of "queued"
// for every recipient. To handle rejections when sending in async mode, set
// up a webhook for the 'reject' event. Defaults to false for messages with
// no more than 10 recipients; messages with more than 10 recipients are
// always sent asynchronously, regardless of the value of async.
return nil
}
da.dialer = nil
return nil
}
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:62,代码来源:daemon_mandrill.go
示例17: getHost
func (u *uniqueID) getHost() string {
h := u.config.GetString(config.Path(PathSmtpHost), config.ScopeStore(u.scopeID))
if h == "" {
h = defaultHost
}
return h
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:7,代码来源:daemon_unique_id.go
示例18: IsSingleStoreMode
// IsSingleStoreMode check if Single-Store mode is enabled in configuration and from Store count < 3.
// This flag only shows that admin does not want to show certain UI components at backend (like store switchers etc)
// if Magento has only one store view but it does not check the store view collection.
func (sm *Service) IsSingleStoreMode() bool {
isEnabled, err := sm.cr.GetBool(config.Path(PathSingleStoreModeEnabled)) // default scope
if config.NotKeyNotFoundError(err) {
// TODO maybe log error here
return false
}
return sm.HasSingleStore() && isEnabled
}
开发者ID:levcom,项目名称:csfw,代码行数:11,代码来源:service.go
示例19: TestPubSubEvict
func TestPubSubEvict(t *testing.T) {
defer debugLogBuf.Reset()
levelCall := new(levelCalls)
var pErr = errors.New("WTF Eviction? Panic!")
s := config.NewService()
subID, err := s.Subscribe("x/y", &testSubscriber{
f: func(path string, sg scope.Scope, id int64) error {
assert.Contains(t, path, "x/y")
// this function gets called 3 times
levelCall.Lock()
levelCall.level2Calls++
levelCall.Unlock()
return nil
},
})
assert.NoError(t, err)
assert.Equal(t, 1, subID)
subID, err = s.Subscribe("x/y/z", &testSubscriber{
f: func(path string, sg scope.Scope, id int64) error {
levelCall.Lock()
levelCall.level3Calls++
levelCall.Unlock()
// this function gets called 1 times and then gets removed
panic(pErr)
},
})
assert.NoError(t, err)
assert.Equal(t, 2, subID)
assert.NoError(t, s.Write(config.Value(321), config.Path("x/y/z"), config.ScopeStore(123)))
assert.NoError(t, s.Write(config.Value(321), config.Path("x/y/a"), config.ScopeStore(123)))
assert.NoError(t, s.Write(config.Value(321), config.Path("x/y/z"), config.ScopeStore(123)))
assert.NoError(t, s.Close())
assert.Contains(t, debugLogBuf.String(), "config.pubSub.publish.recover.err err: WTF Eviction? Panic!")
levelCall.Lock()
assert.Equal(t, 3, levelCall.level2Calls)
assert.Equal(t, 1, levelCall.level3Calls)
levelCall.Unlock()
assert.EqualError(t, s.Close(), config.ErrPublisherClosed.Error())
}
开发者ID:joao-parana,项目名称:csfw,代码行数:46,代码来源:service_pubsub_test.go
示例20: AllowedCurrencies
// AllowedCurrencies returns all installed currencies from global scope.
func AllowedCurrencies(cr config.Reader) ([]string, error) {
installedCur, err := cr.GetString(config.Path(PathSystemCurrencyInstalled))
if config.NotKeyNotFoundError(err) {
return nil, err
}
// TODO use internal model of PathSystemCurrencyInstalled defined in package directory
return strings.Split(installedCur, ","), nil
}
开发者ID:levcom,项目名称:csfw,代码行数:9,代码来源:currency.go
注:本文中的github.com/corestoreio/csfw/config.Path函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论