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


Golang SnapshotRequest.AllowStale方法代码示例

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


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

示例1: Snapshot

// Snapshot handles requests to take and restore snapshots. This uses a special
// mechanism to make the RPC since we potentially stream large amounts of data
// as part of these requests.
func (s *HTTPServer) Snapshot(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
	var args structs.SnapshotRequest
	s.parseDC(req, &args.Datacenter)
	s.parseToken(req, &args.Token)
	if _, ok := req.URL.Query()["stale"]; ok {
		args.AllowStale = true
	}

	switch req.Method {
	case "GET":
		args.Op = structs.SnapshotSave

		// Headers need to go out before we stream the body.
		replyFn := func(reply *structs.SnapshotResponse) error {
			setMeta(resp, &reply.QueryMeta)
			return nil
		}

		// Don't bother sending any request body through since it will
		// be ignored.
		var null bytes.Buffer
		if err := s.agent.SnapshotRPC(&args, &null, resp, replyFn); err != nil {
			return nil, err
		}
		return nil, nil

	case "PUT":
		args.Op = structs.SnapshotRestore
		if err := s.agent.SnapshotRPC(&args, req.Body, resp, nil); err != nil {
			return nil, err
		}
		return nil, nil

	default:
		resp.WriteHeader(http.StatusMethodNotAllowed)
		return nil, nil
	}
}
开发者ID:pulcy,项目名称:vault-monkey,代码行数:41,代码来源:snapshot_endpoint.go


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