当前位置: 首页>>代码示例>>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;未经允许,请勿转载。