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


Golang mux.Vars函数代码示例

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


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

示例1: getIntegrationPipe

func getIntegrationPipe(req Request) Response {
	workspaceID := currentWorkspaceID(req.r)
	serviceID := mux.Vars(req.r)["service"]
	if !serviceType.MatchString(serviceID) {
		return badRequest("Missing or invalid service")
	}
	pipeID := mux.Vars(req.r)["pipe"]
	if !pipeType.MatchString(pipeID) {
		return badRequest("Missing or invalid pipe")
	}

	pipe, err := loadPipe(workspaceID, serviceID, pipeID)
	if err != nil {
		return internalServerError(err.Error())
	}
	if pipe == nil {
		pipe = NewPipe(workspaceID, serviceID, pipeID)
	}

	pipe.PipeStatus, err = loadPipeStatus(workspaceID, serviceID, pipeID)
	if err != nil {
		return internalServerError(err.Error())
	}

	return ok(pipe)
}
开发者ID:refiito,项目名称:pipes-api,代码行数:26,代码来源:handlers.go

示例2: joinactivity

func (h *handler) joinactivity(w http.ResponseWriter, r *http.Request) {
	logr(w, r)
	h.m.Lock()
	defer h.m.Unlock()
	uid := mux.Vars(r)["uid"]
	u, err := h.getuserbyid(uid)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	aid := mux.Vars(r)["aid"]
	a, err := h.getactivitybyid(aid)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if len(a.Parts) >= a.Cap {
		http.Error(w, "activity already full", http.StatusBadRequest)
		return
	}
	for _, id := range a.Parts {
		if id == u.Id {
			http.Error(w, "user already part of activity", http.StatusBadRequest)
			return
		}
	}
	a.Parts = append(a.Parts, u.Id)
	doOK(w, r)
}
开发者ID:ethanyishchan,项目名称:parksandrec,代码行数:29,代码来源:main.go

示例3: ServeSubmitAnswer

func ServeSubmitAnswer(store datastores.AnswerStoreServices) m.HandlerFunc {
	return func(c *m.Context, w http.ResponseWriter, r *http.Request) {

		questionID := mux.Vars(r)["questionID"]
		isSlotAvailable, err := store.IsAnswerSlotAvailable(questionID)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		} else if !isSlotAvailable {
			http.Error(w, "Maximum capacity for answers has been reached", http.StatusForbidden)
			return
		}

		newAnswer := c.ParsedModel.(*models.Answer)
		requiredRep, err := c.RepStore.FindRep(mux.Vars(r)["category"], c.UserID)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}

		err, statusCode := store.StoreAnswer(questionID, c.UserID, newAnswer.Content, services.CalculateCurrentAnswerEligibilityRep(requiredRep))
		if err != nil {
			http.Error(w, err.Error(), statusCode)
			return
		}

		w.WriteHeader(http.StatusCreated)
	}
}
开发者ID:jmheidly,项目名称:Answer-Patch,代码行数:28,代码来源:answer.go

示例4: apiVMAddressRdns

func apiVMAddressRdns(w http.ResponseWriter, r *http.Request, userId int, requestBytes []byte) {
	vmId, err := strconv.Atoi(mux.Vars(r)["id"])
	if err != nil {
		http.Error(w, "Invalid VM ID", 400)
		return
	}
	vm := vmGetUser(userId, vmId)
	if vm == nil {
		http.Error(w, "No virtual machine with that ID", 404)
		return
	}

	var request api.VMAddressRdnsRequest
	err = json.Unmarshal(requestBytes, &request)
	if err != nil {
		http.Error(w, "Invalid json: "+err.Error(), 400)
		return
	}

	err = vm.SetRdns(mux.Vars(r)["ip"], request.Hostname)
	if err != nil {
		http.Error(w, err.Error(), 400)
	} else {
		apiResponse(w, 200, nil)
	}
}
开发者ID:yashodhank,项目名称:lobster,代码行数:26,代码来源:api.go

示例5: GetTagsHandler

func (ctx *Context) GetTagsHandler(w http.ResponseWriter, r *http.Request) {
	namespace := mux.Vars(r)["namespace"]
	repository := mux.Vars(r)["repository"]

	data := make(map[string]string)

	dir, err := ctx.storage.ListDirectory(storage.TagPath(namespace, repository))
	if err != nil {
		sendResponse(w, "Repository not found", 404, nil, false)
		return
	}

	for _, fname := range dir {
		tagName := filepath.Base(fname)
		if !strings.HasPrefix(tagName, "tag_") {
			continue
		}

		content, err := ctx.storage.GetContent(fname)
		if err != nil {
			continue
		}
		data[tagName[4:]] = string(content)
	}

	sendResponse(w, data, 200, nil, false)
}
开发者ID:jigish,项目名称:docker-simpleregistry,代码行数:27,代码来源:main.go

示例6: deleteBuildCommentHandler

func deleteBuildCommentHandler(w http.ResponseWriter, r *http.Request) {
	defer timer.New("deleteBuildCommentHandler").Stop()
	if !userHasEditRights(r) {
		util.ReportError(w, r, fmt.Errorf("User does not have edit rights."), "User does not have edit rights.")
		return
	}
	w.Header().Set("Content-Type", "application/json")
	cache, err := getCommitCache(w, r)
	if err != nil {
		return
	}
	buildId, err := strconv.ParseInt(mux.Vars(r)["buildId"], 10, 32)
	if err != nil {
		util.ReportError(w, r, err, fmt.Sprintf("Invalid build id: %v", err))
		return
	}
	commentId, err := strconv.ParseInt(mux.Vars(r)["commentId"], 10, 32)
	if err != nil {
		util.ReportError(w, r, err, fmt.Sprintf("Invalid comment id: %v", err))
		return
	}
	if err := cache.DeleteBuildComment(int(buildId), int(commentId)); err != nil {
		util.ReportError(w, r, err, fmt.Sprintf("Failed to delete comment: %v", err))
		return
	}
}
开发者ID:1394,项目名称:skia-buildbot,代码行数:26,代码来源:main.go

示例7: appGet

func appGet(h func(http.ResponseWriter, *http.Request, *schema.PodManifest, *schema.ImageManifest)) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := mux.Vars(r)["token"]

		an := mux.Vars(r)["app"]
		if an == "" {
			w.WriteHeader(http.StatusBadRequest)
			fmt.Fprint(w, "app missing")
			return
		}

		pm, im, err := pods.getManifests(token, an)
		switch {
		case err == nil:
			h(w, r, pm, im)

		case err == errPodNotFound:
			w.WriteHeader(http.StatusUnauthorized)
			fmt.Fprintln(w, err)

		default:
			w.WriteHeader(http.StatusNotFound)
			fmt.Fprintln(w, err)
		}
	}
}
开发者ID:hwinkel,项目名称:rkt,代码行数:26,代码来源:metadata_service.go

示例8: taskTimeStatisticsHandler

// taskTimeStatisticsHandler is a handler for task time aggretations.
// it essentially acts as a wrapper for task.AverageTaskTimeDifference
func (uis *UIServer) taskTimeStatisticsHandler(w http.ResponseWriter, r *http.Request) {
	field1 := mux.Vars(r)["field1"]
	field2 := mux.Vars(r)["field2"]
	groupyBy := mux.Vars(r)["group_by"]
	cutoffDaysAsString := mux.Vars(r)["cutoff_days"]
	cutoffDays, err := strconv.Atoi(cutoffDaysAsString)
	if err != nil {
		uis.LoggedError(w, r, http.StatusBadRequest, fmt.Errorf("Error converting cutoff_days to integer: %v", err))
		return
	}

	var cutoff time.Time
	// -1 is passed to represent "All Time", otherwise the number
	// is an amount of days to include in the aggregation
	if cutoffDays < 0 {
		cutoff = time.Unix(1, 0) // 1 more than 0 time to ignore unset time fields
	} else {
		cutoff = time.Now().Add(time.Duration(-1*cutoffDays) * time.Hour * 24)
	}

	timeMap, err := task.AverageTaskTimeDifference(field1, field2, groupyBy, cutoff)
	if err != nil {
		uis.LoggedError(w, r, http.StatusInternalServerError, fmt.Errorf("Error computing time stats: %v", err))
		return
	}

	var timeList []uiTaskTimeStatistic
	for id, val := range timeMap {
		timeList = append(timeList, uiTaskTimeStatistic{id, val})
	}
	uis.WriteJSON(w, http.StatusOK, timeList)
}
开发者ID:sr527,项目名称:evergreen,代码行数:34,代码来源:task_queue.go

示例9: Start

func Start() {

	r := mux.NewRouter()

	// Gitchain API
	r.Methods("POST").Path("/rpc").HandlerFunc(jsonRpcService().ServeHTTP)
	r.Methods("GET").Path("/info").HandlerFunc(info)

	// Git Server
	r.Methods("POST").Path("/{path}/git-upload-pack").HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		body, _ := ioutil.ReadAll(req.Body)
		fmt.Println(req, body)
		resp.Write([]byte(mux.Vars(req)["path"]))
	})

	r.Methods("POST").Path("/{path}/git-receive-pack").HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		fmt.Println(req)
		resp.Write([]byte(mux.Vars(req)["path"]))
	})

	r.Methods("GET").Path("/{path}/info/refs").HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		body, _ := ioutil.ReadAll(req.Body)
		fmt.Println(req, body)

		resp.Write([]byte(mux.Vars(req)["path"]))
	})

	http.Handle("/", r)

	err := http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", env.Port), nil)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:Jaspper,项目名称:gitchain,代码行数:34,代码来源:http.go

示例10: pluginUnsubsribe

func (api *Api) pluginUnsubsribe(rw http.ResponseWriter, r *http.Request, user *account.User) {
	service, err := account.FindServiceBySubdomain(mux.Vars(r)["subdomain"])
	if err != nil {
		handleError(rw, err)
		return
	}

	_, err = findTeamAndCheckUser(service.Team, user)
	if err != nil {
		handleError(rw, err)
		return
	}

	plugin, err := account.FindPluginByNameAndService(mux.Vars(r)["plugin_name"], *service)
	if err != nil {
		handleError(rw, err)
		return
	}

	if err = plugin.Delete(); err != nil {
		handleError(rw, err)
		return
	}

	Ok(rw, plugin)
}
开发者ID:sinzone,项目名称:apihub,代码行数:26,代码来源:plugins.go

示例11: VerifyTargetHandler

func VerifyTargetHandler(w http.ResponseWriter, req *http.Request) {
	if !checkAuth(req, authuser, authpassword) {
		UnauthorizedResponse(w)
		return
	}

	hostname1 := dns.Fqdn(mux.Vars(req)["hostname1"])
	hostname2 := dns.Fqdn(mux.Vars(req)["hostname2"])
	nocache := req.URL.Query().Get("nocache") != ""

	target_alias := req.URL.Query().Get("target_alias")
	if target_alias != "" {
		target_alias = dns.Fqdn(target_alias)
	}

	vr, err := VerifyTarget(hostname1, hostname2, target_alias, nocache)
	if err != nil {
		w.WriteHeader(500)
		json.NewEncoder(w).Encode(vr.Error)
		return
	}

	json.NewEncoder(w).Encode(vr)
	return
}
开发者ID:bgentry,项目名称:hk-check-dns,代码行数:25,代码来源:main.go

示例12: getTaskByName

// getTask finds a json document by using thex task that is in the plugin.
func getTaskByName(w http.ResponseWriter, r *http.Request) {
	t := plugin.GetTask(r)
	if t == nil {
		http.Error(w, "task not found", http.StatusNotFound)
		return
	}
	name := mux.Vars(r)["name"]
	taskName := mux.Vars(r)["task_name"]

	var jsonForTask TaskJSON
	err := db.FindOneQ(collection, db.Query(bson.M{VersionIdKey: t.Version, BuildIdKey: t.BuildId, NameKey: name,
		TaskNameKey: taskName}), &jsonForTask)
	if err != nil {
		if err == mgo.ErrNotFound {
			plugin.WriteJSON(w, http.StatusNotFound, nil)
			return
		}
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well
		plugin.WriteJSON(w, http.StatusOK, jsonForTask)
		return
	}
	plugin.WriteJSON(w, http.StatusOK, jsonForTask.Data)
}
开发者ID:tychoish,项目名称:evergreen,代码行数:27,代码来源:task.go

示例13: deletePipeSetup

func deletePipeSetup(req Request) Response {
	workspaceID := currentWorkspaceID(req.r)
	serviceID := mux.Vars(req.r)["service"]
	if !serviceType.MatchString(serviceID) {
		return badRequest("Missing or invalid service")
	}
	pipeID := mux.Vars(req.r)["pipe"]
	if !pipeType.MatchString(pipeID) {
		return badRequest("Missing or invalid pipe")
	}

	pipe, err := loadPipe(workspaceID, serviceID, pipeID)
	if err != nil {
		return internalServerError(err.Error())
	}
	if pipe == nil {
		return badRequest("Pipe is not configured")
	}

	if err := pipe.destroy(workspaceID); err != nil {
		return internalServerError(err.Error())
	}

	return ok(nil)
}
开发者ID:refiito,项目名称:pipes-api,代码行数:25,代码来源:handlers.go

示例14: postPipeSetup

func postPipeSetup(req Request) Response {
	workspaceID := currentWorkspaceID(req.r)
	serviceID := mux.Vars(req.r)["service"]
	if !serviceType.MatchString(serviceID) {
		return badRequest("Missing or invalid service")
	}
	pipeID := mux.Vars(req.r)["pipe"]
	if !pipeType.MatchString(pipeID) {
		return badRequest("Missing or invalid pipe")
	}

	pipe := NewPipe(workspaceID, serviceID, pipeID)
	if err := json.Unmarshal(req.body, &pipe); err != nil {
		return internalServerError(err.Error())
	}

	if errorMsg := pipe.validate(); errorMsg != "" {
		return badRequest(errorMsg)
	}

	if err := pipe.save(); err != nil {
		return internalServerError(err.Error())
	}
	return ok(nil)
}
开发者ID:refiito,项目名称:pipes-api,代码行数:25,代码来源:handlers.go

示例15: snapshotHandler

func snapshotHandler(d *Daemon, r *http.Request) Response {
	containerName := mux.Vars(r)["name"]
	c, err := newLxdContainer(containerName, d)
	if err != nil {
		return SmartError(err)
	}

	snapshotName := mux.Vars(r)["snapshotName"]
	dir := snapshotDir(c, snapshotName)

	_, err = os.Stat(dir)
	if err != nil {
		return SmartError(err)
	}

	switch r.Method {
	case "GET":
		return snapshotGet(c, snapshotName)
	case "POST":
		return snapshotPost(r, c, snapshotName)
	case "DELETE":
		return snapshotDelete(d, c, snapshotName)
	default:
		return NotFound
	}
}
开发者ID:Ramzec,项目名称:lxd,代码行数:26,代码来源:container_snapshot.go


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