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


Golang structs.IndexedSessions類代碼示例

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


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

示例1: SessionsForNode

// SessionsForNode returns all the nodes belonging to a node
func (s *HTTPServer) SessionsForNode(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
	args := structs.NodeSpecificRequest{}
	if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
		return nil, nil
	}

	// Pull out the node name
	args.Node = strings.TrimPrefix(req.URL.Path, "/v1/session/node/")
	if args.Node == "" {
		resp.WriteHeader(400)
		resp.Write([]byte("Missing node name"))
		return nil, nil
	}

	var out structs.IndexedSessions
	defer setMeta(resp, &out.QueryMeta)
	if err := s.agent.RPC("Session.NodeSessions", &args, &out); err != nil {
		return nil, err
	}

	// Use empty list instead of nil
	if out.Sessions == nil {
		out.Sessions = make(structs.Sessions, 0)
	}
	return out.Sessions, nil
}
開發者ID:hashicorp,項目名稱:consul,代碼行數:27,代碼來源:session_endpoint.go

示例2: Renew

// Renew is used to renew the TTL on a single session
func (s *Session) Renew(args *structs.SessionSpecificRequest,
	reply *structs.IndexedSessions) error {
	if done, err := s.srv.forward("Session.Renew", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"consul", "session", "renew"}, time.Now())

	// Get the session, from local state
	state := s.srv.fsm.State()
	index, session, err := state.SessionGet(args.Session)
	if err != nil {
		return err
	}

	// Reset the session TTL timer
	reply.Index = index
	if session != nil {
		reply.Sessions = structs.Sessions{session}
		if err := s.srv.resetSessionTimer(args.Session, session); err != nil {
			s.srv.logger.Printf("[ERR] consul.session: Session renew failed: %v", err)
			return err
		}
	}
	return nil
}
開發者ID:jefferai,項目名稱:consul,代碼行數:26,代碼來源:session_endpoint.go

示例3: Get

// Get is used to retrieve a single session
func (s *Session) Get(args *structs.SessionSpecificRequest,
	reply *structs.IndexedSessions) error {
	if done, err := s.srv.forward("Session.Get", args, args, reply); done {
		return err
	}

	// Get the local state
	state := s.srv.fsm.State()
	return s.srv.blockingRPC(
		&args.QueryOptions,
		&reply.QueryMeta,
		state.GetQueryWatch("SessionGet"),
		func() error {
			index, session, err := state.SessionGet(args.Session)
			if err != nil {
				return err
			}

			reply.Index = index
			if session != nil {
				reply.Sessions = structs.Sessions{session}
			} else {
				reply.Sessions = nil
			}
			if err := s.srv.filterACL(args.Token, reply); err != nil {
				return err
			}
			return nil
		})
}
開發者ID:hashicorp,項目名稱:consul,代碼行數:31,代碼來源:session_endpoint.go

示例4: SessionList

// SessionList is used to list all the sessions
func (s *HTTPServer) SessionList(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
	args := structs.DCSpecificRequest{}
	if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
		return nil, nil
	}

	var out structs.IndexedSessions
	defer setMeta(resp, &out.QueryMeta)
	if err := s.agent.RPC("Session.List", &args, &out); err != nil {
		return nil, err
	}

	// Use empty list instead of nil
	if out.Sessions == nil {
		out.Sessions = make(structs.Sessions, 0)
	}
	return out.Sessions, nil
}
開發者ID:hashicorp,項目名稱:consul,代碼行數:19,代碼來源:session_endpoint.go

示例5: Get

// Get is used to retrieve a single session
func (s *Session) Get(args *structs.SessionSpecificRequest,
	reply *structs.IndexedSessions) error {
	if done, err := s.srv.forward("Session.Get", args, args, reply); done {
		return err
	}

	// Get the local state
	state := s.srv.fsm.State()
	return s.srv.blockingRPC(&args.QueryOptions,
		&reply.QueryMeta,
		state.QueryTables("SessionGet"),
		func() error {
			index, session, err := state.SessionGet(args.Session)
			reply.Index = index
			if session != nil {
				reply.Sessions = structs.Sessions{session}
			}
			return err
		})
}
開發者ID:askagirl,項目名稱:consul,代碼行數:21,代碼來源:session_endpoint.go

示例6: Renew

// Renew is used to renew the TTL on a single session
func (s *Session) Renew(args *structs.SessionSpecificRequest,
	reply *structs.IndexedSessions) error {
	if done, err := s.srv.forward("Session.Renew", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"consul", "session", "renew"}, time.Now())

	// Get the session, from local state.
	state := s.srv.fsm.State()
	index, session, err := state.SessionGet(args.Session)
	if err != nil {
		return err
	}

	reply.Index = index
	if session == nil {
		return nil
	}

	// Fetch the ACL token, if any, and apply the policy.
	acl, err := s.srv.resolveToken(args.Token)
	if err != nil {
		return err
	}
	if acl != nil && s.srv.config.ACLEnforceVersion8 {
		if !acl.SessionWrite(session.Node) {
			return permissionDeniedErr
		}
	}

	// Reset the session TTL timer.
	reply.Sessions = structs.Sessions{session}
	if err := s.srv.resetSessionTimer(args.Session, session); err != nil {
		s.srv.logger.Printf("[ERR] consul.session: Session renew failed: %v", err)
		return err
	}

	return nil
}
開發者ID:hashicorp,項目名稱:consul,代碼行數:40,代碼來源:session_endpoint.go


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