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


Golang Context.Query方法代码示例

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


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

示例1: handleProfile

func handleProfile(ctx *macaron.Context) string {
	switch ctx.Query("op") {
	case "startcpu":
		if err := StartCPUProfile(); err != nil {
			return err.Error()
		}
	case "stopcpu":
		if err := StopCPUProfile(); err != nil {
			return err.Error()
		}
	case "mem":
		dumpMemProf()
	case "gc":
		var buf bytes.Buffer
		DumpGCSummary(&buf)
		return string(buf.Bytes())
	default:
		return fmt.Sprintf(`<p>Available operations:</p>
<ol>
	<li><a href="%s?op=startcpu">Start CPU profile</a></li>
	<li><a href="%s?op=stopcpu">Stop CPU profile</a></li>
	<li><a href="%s?op=mem">Dump memory profile</a></li>
	<li><a href="%s?op=gc">Dump GC summary</a></li>
</ol>`, opt.ProfileURLPrefix, opt.ProfileURLPrefix, opt.ProfileURLPrefix, opt.ProfileURLPrefix)
	}
	ctx.Redirect(opt.ProfileURLPrefix)
	return ""
}
开发者ID:reduxdj,项目名称:grafana,代码行数:28,代码来源:profile.go

示例2: DoPupDetail

func DoPupDetail(ctx *macaron.Context) {
	id := ctx.Query("Id")
	pup := findPup(id)
	if pup != nil {
		ctx.Data["IsPup"] = true
		ctx.Data["Pup"] = pup
		ctx.HTML(200, "showDetail")
	}
}
开发者ID:zileyuan,项目名称:hidog,代码行数:9,代码来源:controller.go

示例3: DoDogDetail

func DoDogDetail(ctx *macaron.Context) {
	id := ctx.Query("Id")
	dog := findDog(id)
	if dog != nil {
		ctx.Data["IsDog"] = true
		ctx.Data["Dog"] = dog
		ctx.HTML(200, "showDetail")
	}
}
开发者ID:zileyuan,项目名称:hidog,代码行数:9,代码来源:controller.go

示例4: SignedInID

// SignedInID returns the id of signed in user.
func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
	if !models.HasEngine {
		return 0
	}

	// Check access token.
	if IsAPIPath(ctx.Req.URL.Path) {
		tokenSHA := ctx.Query("token")
		if len(tokenSHA) == 0 {
			// Well, check with header again.
			auHead := ctx.Req.Header.Get("Authorization")
			if len(auHead) > 0 {
				auths := strings.Fields(auHead)
				if len(auths) == 2 && auths[0] == "token" {
					tokenSHA = auths[1]
				}
			}
		}

		// Let's see if token is valid.
		if len(tokenSHA) > 0 {
			t, err := models.GetAccessTokenBySHA(tokenSHA)
			if err != nil {
				if models.IsErrAccessTokenNotExist(err) {
					log.Error(4, "GetAccessTokenBySHA: %v", err)
				}
				return 0
			}
			t.Updated = time.Now()
			if err = models.UpdateAccessToekn(t); err != nil {
				log.Error(4, "UpdateAccessToekn: %v", err)
			}
			return t.UID
		}
	}

	uid := sess.Get("uid")
	if uid == nil {
		return 0
	}
	if id, ok := uid.(int64); ok {
		if _, err := models.GetUserByID(id); err != nil {
			if !models.IsErrUserNotExist(err) {
				log.Error(4, "GetUserById: %v", err)
			}
			return 0
		}
		return id
	}
	return 0
}
开发者ID:nafrente,项目名称:gogs,代码行数:52,代码来源:auth.go

示例5: login

func login(ctx *macaron.Context, s session.Store, opt *Options) {
	next := extractPath(ctx.Query(KEY_NEXT_PAGE))
	if s.Get(KEY_TOKEN) == nil {
		// User is not logged in.
		if next == "" {
			next = AppSubUrl + "/"
		}
		// println(111, opt.AuthCodeURL(next, "", ""))
		ctx.Redirect(opt.AuthCodeURL(next, "", ""))
		return
	}
	// No need to login, redirect to the next page.
	ctx.Redirect(next)
}
开发者ID:maxwhale,项目名称:docker-gogs-centos,代码行数:14,代码来源:social.go

示例6: OnSignin

func OnSignin(ctx *macaron.Context, f *session.Flash) {
	userName := ctx.Query("username")
	Password := ctx.Query("password")

	c := db.C("Account")
	account := Account{}
	err := c.Find(bson.M{"UserName": userName, "Password": Password}).One(&account)
	if err != nil {
		ctx.Data["Title"] = "出错啦!"
		ctx.Data["Info"] = "您的账户或密码错误,登录失败啦!"
		ctx.HTML(200, "info")
	}
	ctx.Data["Admin"] = account.Role == 1
	ctx.Data["Comments"] = getComments()
	ctx.HTML(200, "profile")
}
开发者ID:zileyuan,项目名称:hidog,代码行数:16,代码来源:controller.go

示例7: handleOAuth2Callback

func handleOAuth2Callback(ctx *macaron.Context, s session.Store, opt *Options) {
	next := extractPath(ctx.Query("state"))
	code := ctx.Query("code")
	t, err := opt.NewTransportFromCode(code)
	if err != nil {
		// Pass the error message, or allow dev to provide its own
		// error handler.
		println(err.Error())
		ctx.Redirect(PathError)
		return
	}
	// Store the credentials in the session.
	val, _ := json.Marshal(t.Token())
	s.Set(KEY_TOKEN, val)
	ctx.Redirect(next)
}
开发者ID:maxwhale,项目名称:docker-gogs-centos,代码行数:16,代码来源:social.go

示例8: PutBlobsV2Handler

func PutBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	desc := ctx.Params(":uuid")
	uuid := strings.Split(desc, "?")[0]

	digest := ctx.Query("digest")
	tarsum := strings.Split(digest, ":")[1]

	imagePathTmp := fmt.Sprintf("%v/%v", setting.ImagePath, uuid)
	layerfileTmp := fmt.Sprintf("%v/%v/layer", setting.ImagePath, uuid)
	imagePath := fmt.Sprintf("%v/tarsum/%v", setting.ImagePath, tarsum)
	layerfile := fmt.Sprintf("%v/tarsum/%v/layer", setting.ImagePath, tarsum)
	layerlen, err := modules.CopyImgLayer(imagePathTmp, layerfileTmp, imagePath, layerfile, ctx.Req.Request.Body)
	if err != nil {
		log.Error("[REGISTRY API V2] Save layerfile failed: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Save layerfile failed"})
		return http.StatusBadRequest, result
	}

	//saving specific tarsum every times is in order to split the same tarsum in HEAD handler
	i := new(models.Image)
	i.Path, i.Size = layerfile, int64(layerlen)
	if err := i.PutTarsum(tarsum); err != nil {
		log.Error("[REGISTRY API V2] Save tarsum failed: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Save tarsum failed"})
		return http.StatusBadRequest, result
	}

	random := fmt.Sprintf("%s://%s/v2/%s/%s/blobs/%s",
		setting.ListenMode,
		setting.Domains,
		ctx.Params(":namespace"),
		ctx.Params(":repository"),
		digest)

	ctx.Resp.Header().Set("Docker-Content-Digest", digest)
	ctx.Resp.Header().Set("Location", random)

	result, _ := json.Marshal(map[string]string{})
	return http.StatusCreated, result
}
开发者ID:haoyuist,项目名称:dockyard,代码行数:42,代码来源:blob.go

示例9: OnComment

func OnComment(ctx *macaron.Context) {
	title := ctx.Query("title")
	content := ctx.Query("content")

	c := db.C("Comment")
	comment := Comment{}
	comment.Id = bson.NewObjectId()
	comment.Title = title
	comment.Content = content
	comment.DateTime = time.Now()
	err := c.Insert(comment)
	if err != nil {
		panic(err)
	}
	//	resp := response.NewText("oMl6fs9C4x583NvZJfTcJxqvcomw", "", comment.DateTime, "["+comment.Title+"]"+comment.Content)
	//	mp.WriteRawResponse(ctx.Resp, nil, resp)
	ctx.Data["Title"] = "成功啦!"
	ctx.Data["Info"] = "您的留言已经第一时间发送出去啦!"
	ctx.HTML(200, "info")
}
开发者ID:zileyuan,项目名称:hidog,代码行数:20,代码来源:controller.go

示例10: queryHandler

func queryHandler(ctx *macaron.Context) {
	fmt.Println(ctx.Query("uid"))
	fmt.Println(ctx.QueryInt("uid"))
	fmt.Println(ctx.QueryInt64("uid"))
}
开发者ID:Zcgong,项目名称:go-rock-libraries-showcases,代码行数:5,代码来源:context.go

示例11: logout

func logout(ctx *macaron.Context, s session.Store) {
	next := extractPath(ctx.Query(KEY_NEXT_PAGE))
	s.Delete(KEY_TOKEN)
	ctx.Redirect(next)
}
开发者ID:maxwhale,项目名称:docker-gogs-centos,代码行数:5,代码来源:social.go


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