当前位置: 首页>>代码示例>>Golang>>正文


Golang Option.Scope方法代码示例

本文整理汇总了Golang中github.com/corestoreio/csfw/store/scope.Option.Scope方法的典型用法代码示例。如果您正苦于以下问题:Golang Option.Scope方法的具体用法?Golang Option.Scope怎么用?Golang Option.Scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/corestoreio/csfw/store/scope.Option的用法示例。


在下文中一共展示了Option.Scope方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewService

// NewService creates a new store Service which handles websites, groups and stores.
// A Service can only act on a certain scope (MAGE_RUN_TYPE) and scope ID (MAGE_RUN_CODE).
// Default scope.Scope is always the scope.WebsiteID constant.
// This function is mainly used when booting the app to set the environment configuration
// Also all other calls to any method receiver with nil arguments depends on the internal
// appStore which reflects the default store ID.
func NewService(so scope.Option, storage Storager, opts ...ServiceOption) (*Service, error) {
	scopeID := so.Scope()
	if scopeID == scope.DefaultID {
		scopeID = scope.WebsiteID
	}

	s := &Service{
		cr:           config.DefaultService,
		boundToScope: scopeID,
		storage:      storage,
		mu:           sync.RWMutex{},
		websiteMap:   make(map[uint64]*Website),
		groupMap:     make(map[uint64]*Group),
		storeMap:     make(map[uint64]*Store),
	}
	for _, opt := range opts {
		if opt != nil {
			opt(s)
		}
	}

	var err error
	s.appStore, err = s.findDefaultStoreByScope(s.boundToScope, so)
	if err != nil {
		if PkgLog.IsDebug() {
			PkgLog.Debug("store.Service.Init", "err", err, "ScopeOption", so)
		}
		return nil, errgo.Mask(err)
	}

	return s, nil
}
开发者ID:joao-parana,项目名称:csfw,代码行数:38,代码来源:service.go

示例2: RequestedStore

// RequestedStore see interface description Reader.RequestedStore
func (sm *Service) RequestedStore(so scope.Option) (activeStore *Store, err error) {

	activeStore, err = sm.findDefaultStoreByScope(so.Scope(), so)
	if err != nil {
		if PkgLog.IsDebug() {
			PkgLog.Debug("store.Service.RequestedStore.FindDefaultStoreByScope", "err", err, "so", so)
		}
		return nil, err
	}

	//	activeStore, err = sm.newActiveStore(activeStore) // this is the active store from a request.
	// todo rethink here if we really need a newActiveStore
	// newActiveStore creates a new Store, Website and Group pointers !!!
	//	if activeStore == nil || err != nil {
	//		// store is not active so ignore
	//		return nil, err
	//	}

	if false == activeStore.Data.IsActive {
		return nil, ErrStoreNotActive
	}

	allowStoreChange := false
	switch sm.boundToScope {
	case scope.StoreID:
		allowStoreChange = true
		break
	case scope.GroupID:
		allowStoreChange = activeStore.Data.GroupID == sm.appStore.Data.GroupID
		break
	case scope.WebsiteID:
		allowStoreChange = activeStore.Data.WebsiteID == sm.appStore.Data.WebsiteID
		break
	}

	if allowStoreChange {
		return activeStore, nil
	}
	return nil, ErrStoreChangeNotAllowed
}
开发者ID:joao-parana,项目名称:csfw,代码行数:41,代码来源:service.go

示例3: testStoreCodeFrom

func testStoreCodeFrom(t *testing.T, i int, haveErr, wantErr error, haveScope scope.Option, wantScope scope.Scope, wantCode string, wantID int64) {
	if wantErr != nil {
		assert.EqualError(t, haveErr, wantErr.Error(), "Index: %d", i)

	}
	switch sos := haveScope.Scope(); sos {
	case scope.StoreID:
		assert.Exactly(t, wantID, haveScope.Store.StoreID(), "Index: %d", i)
	case scope.GroupID:
		assert.Exactly(t, wantID, haveScope.Group.GroupID(), "Index: %d", i)
	case scope.WebsiteID:
		assert.Exactly(t, wantID, haveScope.Website.WebsiteID(), "Index: %d", i)
	case scope.DefaultID:
		assert.Nil(t, haveScope.Store, "Index: %d", i)
		assert.Nil(t, haveScope.Group, "Index: %d", i)
		assert.Nil(t, haveScope.Website, "Index: %d", i)
	default:
		t.Fatalf("Unknown scope: %d", sos)
	}
	assert.Exactly(t, wantScope, haveScope.Scope(), "Index: %d", i)
	assert.Exactly(t, wantCode, haveScope.StoreCode(), "Index: %d", i)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:22,代码来源:code_test.go

示例4: TestApplyDefault

func TestApplyDefault(t *testing.T) {
	so := scope.Option{}
	assert.NotNil(t, so)
	assert.Exactly(t, scope.DefaultID, so.Scope())
}
开发者ID:joao-parana,项目名称:csfw,代码行数:5,代码来源:option_test.go


注:本文中的github.com/corestoreio/csfw/store/scope.Option.Scope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。