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


Golang mux.Vars函数代码示例

本文整理汇总了Golang中github.com/coreos/flannel/Godeps/_workspace/src/github.com/gorilla/mux.Vars函数的典型用法代码示例。如果您正苦于以下问题:Golang Vars函数的具体用法?Golang Vars怎么用?Golang Vars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: handleWatchLease

// GET /{network}/leases/subnet?next=cursor
func handleWatchLease(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
	network := mux.Vars(r)["network"]
	if network == "_" {
		network = ""
	}

	sn := subnet.ParseSubnetKey(mux.Vars(r)["subnet"])
	if sn == nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprint(w, "bad subnet")
		return
	}

	cursor := getCursor(r.URL)

	wr, err := sm.WatchLease(ctx, network, *sn, cursor)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, err)
		return
	}

	switch wr.Cursor.(type) {
	case string:
	case fmt.Stringer:
		wr.Cursor = wr.Cursor.(fmt.Stringer).String()
	default:
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, fmt.Errorf("internal error: watch cursor is of unknown type"))
		return
	}

	jsonResponse(w, http.StatusOK, wr)
}
开发者ID:vanloswang,项目名称:flannel,代码行数:35,代码来源:server.go

示例2: handleRevokeLease

func handleRevokeLease(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
	network := mux.Vars(r)["network"]
	if network == "_" {
		network = ""
	}

	sn := subnet.ParseSubnetKey(mux.Vars(r)["subnet"])
	if sn == nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprint(w, "failed to parse subnet")
		return
	}

	if err := sm.RevokeLease(ctx, network, *sn); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, err)
		return
	}
}
开发者ID:vanloswang,项目名称:flannel,代码行数:19,代码来源:server.go

示例3: handleGetNetworkConfig

// GET /{network}/config
func handleGetNetworkConfig(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
	network := mux.Vars(r)["network"]
	if network == "_" {
		network = ""
	}

	c, err := sm.GetNetworkConfig(ctx, network)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, err)
		return
	}

	jsonResponse(w, http.StatusOK, c)
}
开发者ID:vanloswang,项目名称:flannel,代码行数:16,代码来源:server.go

示例4: handleAddReservation

// POST /{network}/reservations
func handleAddReservation(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
	network := mux.Vars(r)["network"]
	if network == "_" {
		network = ""
	}

	rsv := &subnet.Reservation{}
	if err := json.NewDecoder(r.Body).Decode(rsv); err != nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprint(w, "JSON decoding error: ", err)
		return
	}

	if err := sm.AddReservation(ctx, network, rsv); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, fmt.Errorf("internal error: %v", err))
		return
	}
}
开发者ID:vanloswang,项目名称:flannel,代码行数:20,代码来源:server.go

示例5: handleRenewLease

// PUT /{network}/{lease.network}
func handleRenewLease(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
	network := mux.Vars(r)["network"]
	if network == "_" {
		network = ""
	}

	lease := subnet.Lease{}
	if err := json.NewDecoder(r.Body).Decode(&lease); err != nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprint(w, "JSON decoding error: ", err)
		return
	}

	if err := sm.RenewLease(ctx, network, &lease); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, err)
		return
	}

	jsonResponse(w, http.StatusOK, lease)
}
开发者ID:vanloswang,项目名称:flannel,代码行数:22,代码来源:server.go

示例6: handleAcquireLease

// POST /{network}/leases
func handleAcquireLease(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	network := mux.Vars(r)["network"]
	if network == "_" {
		network = ""
	}

	attrs := subnet.LeaseAttrs{}
	if err := json.NewDecoder(r.Body).Decode(&attrs); err != nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprint(w, "JSON decoding error: ", err)
		return
	}

	lease, err := sm.AcquireLease(ctx, network, &attrs)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, err)
		return
	}

	jsonResponse(w, http.StatusOK, lease)
}
开发者ID:rajatchopra,项目名称:flannel,代码行数:25,代码来源:server.go


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