當前位置: 首頁>>代碼示例>>Golang>>正文


Golang facade.Context類代碼示例

本文整理匯總了Golang中github.com/juju/juju/apiserver/facade.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewAllWatcher

// NewAllWatcher returns a new API server endpoint for interacting
// with a watcher created by the WatchAll and WatchAllModels API calls.
func NewAllWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()

	// HasPermission should not be replaced by auth.AuthClient() even if, at first sight, they seem
	// equivalent because this allows us to remove login permission for a user
	// (a permission that is given by default).
	isAuthorized, err := auth.HasPermission(permission.LoginAccess, context.State().ControllerTag())
	if err != nil {
		return nil, errors.Trace(err)
	}
	if !isAuthorized {
		return nil, common.ErrPerm
	}
	watcher, ok := resources.Get(id).(*state.Multiwatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &SrvAllWatcher{
		watcher:   watcher,
		id:        id,
		resources: resources,
	}, nil
}
開發者ID:bac,項目名稱:juju,代碼行數:27,代碼來源:watcher.go

示例2: newFilesystemAttachmentsWatcher

func newFilesystemAttachmentsWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()
	st := context.State()
	return newMachineStorageIdsWatcher(
		st, resources, auth, id, storagecommon.ParseFilesystemAttachmentIds,
	)
}
開發者ID:bac,項目名稱:juju,代碼行數:9,代碼來源:watcher.go

示例3: newMigrationStatusWatcher

func newMigrationStatusWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()
	st := context.State()

	if !(auth.AuthMachineAgent() || auth.AuthUnitAgent()) {
		return nil, common.ErrPerm
	}
	w, ok := resources.Get(id).(state.NotifyWatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &srvMigrationStatusWatcher{
		watcher:   w,
		id:        id,
		resources: resources,
		st:        getMigrationBackend(st),
	}, nil
}
開發者ID:bac,項目名稱:juju,代碼行數:20,代碼來源:watcher.go

示例4: newEntitiesWatcher

func newEntitiesWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()

	if !isAgent(auth) {
		return nil, common.ErrPerm
	}
	watcher, ok := resources.Get(id).(EntitiesWatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &srvEntitiesWatcher{
		resources: resources,
		id:        id,
		watcher:   watcher,
	}, nil
}
開發者ID:bac,項目名稱:juju,代碼行數:18,代碼來源:watcher.go

示例5: newRelationUnitsWatcher

func newRelationUnitsWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()

	if !isAgent(auth) {
		return nil, common.ErrPerm
	}
	watcher, ok := resources.Get(id).(state.RelationUnitsWatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &srvRelationUnitsWatcher{
		watcher:   watcher,
		id:        id,
		resources: resources,
	}, nil
}
開發者ID:bac,項目名稱:juju,代碼行數:18,代碼來源:watcher.go


注:本文中的github.com/juju/juju/apiserver/facade.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。