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


Golang Principal.Name方法代碼示例

本文整理匯總了Golang中github.com/couchbaselabs/sync_gateway/auth.Principal.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang Principal.Name方法的具體用法?Golang Principal.Name怎麽用?Golang Principal.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/couchbaselabs/sync_gateway/auth.Principal的用法示例。


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

示例1: marshalPrincipal

func marshalPrincipal(princ auth.Principal) ([]byte, error) {
	name := externalUserName(princ.Name())
	info := PrincipalJSON{
		Name:             &name,
		ExplicitChannels: princ.ExplicitChannels().AsSet(),
		Channels:         princ.Channels().AsSet(),
	}
	if user, ok := princ.(auth.User); ok {
		info.Email = user.Email()
		info.Disabled = user.Disabled()
		info.ExplicitRoleNames = user.ExplicitRoleNames()
		info.RoleNames = user.RoleNames()
	}
	return json.Marshal(info)
}
開發者ID:nvdbleek,項目名稱:sync_gateway,代碼行數:15,代碼來源:admin_api.go

示例2: putPrincipal

// Common behavior of putUser and putRole
func putPrincipal(r http.ResponseWriter, rq *http.Request, context *context, name string, princ auth.Principal) error {
	context.auth.InvalidateChannels(princ)

	if rq.Method == "POST" {
		name = princ.Name()
		if name == "" {
			return &base.HTTPError{http.StatusBadRequest, "Missing name property"}
		}
	} else if princ.Name() != name {
		return &base.HTTPError{http.StatusBadRequest, "Name mismatch (can't change name)"}
	}
	err := context.auth.Save(princ)
	if err == nil {
		r.WriteHeader(http.StatusCreated)
	}
	return err
}
開發者ID:robertkrimen,項目名稱:sync_gateway,代碼行數:18,代碼來源:authrest.go

示例3: ComputeChannelsForPrincipal

// Recomputes the set of channels a User/Role has been granted access to by sync() functions.
// This is part of the ChannelComputer interface defined by the Authenticator.
func (context *DatabaseContext) ComputeChannelsForPrincipal(princ auth.Principal) (channels.TimedSet, error) {
	key := princ.Name()
	if _, ok := princ.(auth.User); !ok {
		key = "role:" + key // Roles are identified in access view by a "role:" prefix
	}

	var vres struct {
		Rows []struct {
			Value channels.TimedSet
		}
	}

	opts := map[string]interface{}{"stale": false, "key": key}
	if verr := context.Bucket.ViewCustom("sync_gateway", "access", opts, &vres); verr != nil {
		return nil, verr
	}
	channelSet := channels.TimedSet{}
	for _, row := range vres.Rows {
		channelSet.Add(row.Value)
	}
	return channelSet, nil
}
開發者ID:racido,項目名稱:sync_gateway,代碼行數:24,代碼來源:crud.go


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