本文整理匯總了Golang中github.com/gin-gonic/gin.Context.GetQuery方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GetQuery方法的具體用法?Golang Context.GetQuery怎麽用?Golang Context.GetQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Context
的用法示例。
在下文中一共展示了Context.GetQuery方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readPodLog
func readPodLog(c *gin.Context) {
namespace := c.Param("ns")
podname := c.Param("po")
_, previous := c.GetQuery("previous")
readLog(c, namespace, podname, "", previous)
}
示例2: editReplicationController
func editReplicationController(c *gin.Context) {
namespace := c.Param("ns")
rcname := c.Param("rc")
_, delete := c.GetQuery("delete")
rc, err := kubeclient.Get().ReplicationControllers(namespace).Get(rcname)
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
b, err := json.Marshal(rc)
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
var out bytes.Buffer
err = json.Indent(&out, b, "", " ")
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
c.HTML(http.StatusOK, "replicationControllerEdit", gin.H{
"title": rcname,
"namespace": namespace,
"objname": rcname,
"json": out.String(),
"delete": strconv.FormatBool(delete),
})
}
示例3: editNode
func editNode(c *gin.Context) {
nodename := c.Param("no")
_, delete := c.GetQuery("delete")
node, err := kubeclient.Get().Nodes().Get(nodename)
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
b, err := json.Marshal(node)
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
var out bytes.Buffer
err = json.Indent(&out, b, "", " ")
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
c.HTML(http.StatusOK, "nodeEdit", gin.H{
"title": nodename,
"objname": nodename,
"json": out.String(),
"delete": strconv.FormatBool(delete),
})
}
示例4: editEndpoints
func editEndpoints(c *gin.Context) {
namespace := c.Param("ns")
epname := c.Param("ep")
_, delete := c.GetQuery("delete")
ep, err := kubeclient.Get().Endpoints(namespace).Get(epname)
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
b, err := json.Marshal(ep)
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
var out bytes.Buffer
err = json.Indent(&out, b, "", " ")
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
c.HTML(http.StatusOK, "endpointsEdit", gin.H{
"title": epname,
"namespace": namespace,
"objname": epname,
"json": out.String(),
"delete": strconv.FormatBool(delete),
})
}
示例5: apiGetSiteInfo
func apiGetSiteInfo(g *gin.Context) {
url, ok := g.GetQuery("url")
if !ok {
g.String(500, "missing parameter url")
return
}
_, inclBody := g.GetQuery("body")
cw := crawlbase.NewCrawler()
cw.Header.Add("User-Agent", userAgentHeader)
tags, _ := crawlbase.LoadTagsFromFile("tags.json")
cw.Validator.AddValidTags(tags)
page, err := cw.GetPage(url, "GET")
if err != nil {
g.String(500, err.Error())
}
// first check
if !inclBody {
page.RespInfo.Body = ""
}
g.JSON(200, page)
}
示例6: apiAddTag
func apiAddTag(g *gin.Context) {
if g.Request.Method != "POST" {
g.String(404, "not a get")
return
}
tName, _ := g.GetQuery("TagName")
aName, _ := g.GetQuery("AttributeName")
if tName == "" {
g.String(200, "TagName is empty")
return
}
tags, _ := crawlbase.LoadTagsFromFile("tags.json")
tag, ok := findTag(tags, tName)
if !ok {
tag = &htmlcheck.ValidTag{tName, []string{}, "", false}
tags = append(tags, tag)
}
ok = findString(tag.Attrs, aName)
if !ok {
tag.Attrs = append(tag.Attrs, aName)
}
//t, _ := findTag(tags, tName)
crawlbase.WriteTagsToFile(tags, "tags.json")
g.String(200, "ok")
}
示例7: readContainerLog
func readContainerLog(c *gin.Context) {
namespace := c.Param("ns")
podname := c.Param("po")
containername := c.Param("ct")
_, previous := c.GetQuery("previous")
readLog(c, namespace, podname, containername, previous)
}
示例8: IntQuery
func IntQuery(c *gin.Context, param string, defaultValue int) int {
v, ok := c.GetQuery(param)
if !ok {
return defaultValue
}
i, err := strconv.Atoi(v)
if err != nil {
return defaultValue
}
return i
}
示例9: testSite
func testSite(g *gin.Context) {
inpage, _ := g.GetQuery("inpage")
inscript, _ := g.GetQuery("inscript")
ineval, _ := g.GetQuery("ineval")
g.String(200, "<html>"+inpage+"<script>var m = '"+inscript+
"';document.write(m);document.cookie='test='+m</script>"+
"<script>eval("+ineval+")</script>"+
"<script>document.write(decodeURIComponent(document.location.hash))</script>"+
"</html>")
}
示例10: listPodsInNamespace
func listPodsInNamespace(c *gin.Context) {
namespace := c.Param("ns")
user := c.MustGet(gin.AuthUserKey).(string)
if user != "admin" && user != namespace {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": "Unauthorized"})
return
}
labelSelectorString, ok := c.GetQuery("labelSelector")
var labelSelector labels.Selector
if !ok {
labelSelector = labels.Everything()
} else {
var err error
if labelSelector, err = labels.Parse(labelSelectorString); err != nil {
c.HTML(http.StatusBadRequest, "error", gin.H{"error": err.Error()})
return
}
}
list, err := kubeclient.Get().Pods(namespace).List(labelSelector, fields.Everything())
if err != nil {
c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
return
}
pods := genPods(list)
images, statuses, hosts := page.GetPodsFilters(pods)
image, ok := c.GetQuery("image")
if ok && len(image) > 0 {
theImage := page.PodImage{Image: image, PrivateRepo: true}
pods = page.FilterPodsByImage(pods, theImage)
}
status, ok := c.GetQuery("status")
if ok && len(status) > 0 {
pods = page.FilterPodsByStatus(pods, status)
}
host, ok := c.GetQuery("host")
if ok && len(host) > 0 {
pods = page.FilterPodsByHost(pods, host)
}
sortAlgo, ok := c.GetQuery("sort")
if ok && len(sortAlgo) > 0 {
switch sortAlgo {
case "ByName":
sort.Sort(page.ByName(pods))
case "ByBirth":
sort.Sort(sort.Reverse(page.ByBirth(pods)))
default:
sort.Sort(sort.Reverse(page.ByBirth(pods)))
}
} else {
sort.Sort(sort.Reverse(page.ByBirth(pods)))
}
c.HTML(http.StatusOK, "podList", gin.H{
"title": "Sigma Pods",
"refresh": 60,
"namespace": namespace,
"queries": map[string]string{
"labelSelector": labelSelectorString,
"image": image,
"status": status,
"host": host,
"sort": sortAlgo,
},
"pods": pods,
"images": images,
"statuses": statuses,
"hosts": hosts,
})
}
示例11: conversionHandler
func conversionHandler(c *gin.Context, source converter.ConversionSource) {
// GC if converting temporary file
if source.IsLocal {
defer os.Remove(source.URI)
}
_, aggressive := c.GetQuery("aggressive")
conf := c.MustGet("config").(Config)
wq := c.MustGet("queue").(chan<- converter.Work)
s := c.MustGet("statsd").(*statsd.Client)
r, ravenOk := c.Get("sentry")
t := s.NewTiming()
awsConf := converter.AWSS3{
c.Query("aws_region"),
c.Query("aws_id"),
c.Query("aws_secret"),
c.Query("s3_bucket"),
c.Query("s3_key"),
}
var conversion converter.Converter
var work converter.Work
attempts := 0
baseConversion := converter.Conversion{}
uploadConversion := converter.UploadConversion{baseConversion, awsConf}
StartConversion:
conversion = athenapdf.AthenaPDF{uploadConversion, conf.AthenaCMD, aggressive}
if attempts != 0 {
cc := cloudconvert.Client{conf.CloudConvert.APIUrl, conf.CloudConvert.APIKey}
conversion = cloudconvert.CloudConvert{uploadConversion, cc}
}
work = converter.NewWork(wq, conversion, source)
select {
case <-c.Writer.CloseNotify():
work.Cancel()
case <-work.Uploaded():
t.Send("conversion_duration")
s.Increment("success")
c.JSON(200, gin.H{"status": "uploaded"})
case out := <-work.Success():
t.Send("conversion_duration")
s.Increment("success")
c.Data(200, "application/pdf", out)
case err := <-work.Error():
// log.Println(err)
// Log, and stats collection
if err == converter.ErrConversionTimeout {
s.Increment("conversion_timeout")
} else if _, awsError := err.(awserr.Error); awsError {
s.Increment("s3_upload_error")
if ravenOk {
r.(*raven.Client).CaptureError(err, map[string]string{"url": source.GetActualURI()})
}
} else {
s.Increment("conversion_error")
if ravenOk {
r.(*raven.Client).CaptureError(err, map[string]string{"url": source.GetActualURI()})
}
}
if attempts == 0 && conf.ConversionFallback {
s.Increment("cloudconvert")
log.Println("falling back to CloudConvert...")
attempts++
goto StartConversion
}
s.Increment("conversion_failed")
if err == converter.ErrConversionTimeout {
c.AbortWithError(http.StatusGatewayTimeout, converter.ErrConversionTimeout).SetType(gin.ErrorTypePublic)
return
}
c.Error(err)
}
}