Golang Context.Status Examples

Golang Context.Status - 19 examples found. These are the top rated real world Golang examples of github.com/gin-gonic/gin.Context.Status extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
// http://127.0.0.1:6789/pure/22.jpg
func imageHandler(context *gin.Context) {
	imgPath := context.Param("path")
	size := context.Query("s")

	if doSkip(imgPath, context) {
		context.Status(http.StatusOK)
		return
	}

	if size != "" {
		imgPath = imgPath + "?s=" + size
	} else {
		if isSpider(context) {
			imgPath = imgPath + "?s=" + util.ExtImgSize
		} else {
			if !util.ReferAllow(context.Request.Referer()) {
				if util.DoAd(context) {
					adImgPath := util.GetRandomAdPath()
					if adImgPath != "" {
						imgPath = adImgPath
					}
				} else {
					imgPath = imgPath + "?s=" + util.ExtImgSize
				}
			}
		}
	}

	rspImg(util.RedirectUrl+imgPath, context)
	return
}
Example #2
0
func rpcEndpoint(c *gin.Context) {
	op := c.MustGet("nuget.op").(string)
	query := c.MustGet("nuget.search").(*NuGetQuery)

	oplog := log.WithFields(log.Fields{
		"op":    op,
		"query": query,
	})

	switch op {
	case "$metadata":
		c.Data(200, XmlMimeType, []byte(NuGetMetadata))
		break
	case "Packages":
		data := c.MustGet("nuget.op.data").(*PackagesCommand)
		Packages(c, data, query, oplog.WithField("data", data))
	case "FindPackagesById":
		data := c.MustGet("nuget.op.data").(*FindPackagesByIdCommand)
		FindPackagesById(c, data, query, oplog.WithField("data", data))
	case "Search":
		data := c.MustGet("nuget.op.data").(*SearchCommand)
		Search(c, data, query, oplog.WithField("data", data))
	case "GetUpdates":
		data := c.MustGet("nuget.op.data").(*GetUpdatesCommand)
		GetUpdates(c, data, query, oplog.WithField("data", data))
	default:
		c.Status(400)
	}
}
Example #3
0
func DeleteRepoPackage(c *gin.Context) {
	repo := session.Repo(c)
	pkgname := c.Param("package")
	arch := c.Param("arch")

	if !util.StrContains(arch, repo.Archs) {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}

	pkg, err := repo.Package(pkgname, arch, true)
	if err != nil {
		log.Errorf("Failed to get repo package '%s': %s", pkgname, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	if pkg == nil {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}

	err = repo.Remove([]string{pkgname}, arch)
	if err != nil {
		log.Errorf("Failed to remove repo package '%s': %s", pkgname, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.Status(http.StatusOK)
}
Example #4
0
func FindPackagesById(c *gin.Context, d *FindPackagesByIdCommand, q *NuGetQuery, logger *log.Entry) {
	logger.Info("FindPackagesById")

	var match *rekt.Entry
	for _, pkg := range registry.Packages {
		if pkg.Title == d.Id && (q.Filter != "IsLatestVersion" || pkg.IsLatestVersion) {
			match = pkg
		}
	}

	feed := &rekt.Feed{
		Id:      "https://www.example.com/api/v2/FindPackagesById",
		Title:   "FindPackagesById",
		Updated: time.Now(),
		Entries: []*rekt.Entry{match},
	}

	atom, err := feed.ToAtom()
	if err != nil {
		c.Status(500)
		return
	}

	c.Data(200, AtomMimeType, atom)
	return
}
Example #5
0
// 原图本地获取或者跳转到img服务器
func rspImg(imgPath string, context *gin.Context) {
	imgUrl, err := url.Parse(imgPath)
	if err != nil || imgUrl == nil {
		context.Status(http.StatusNotFound)
		return
	}

	if len(imgUrl.Host) > 0 {
		context.Redirect(http.StatusFound, imgPath)
		return
	}

	// cache
	cacheBuff := util.FindInCache(imgUrl.String())
	if len(cacheBuff) > 0 {
		rspCacheControl(cacheBuff, context)
		return
	}

	buff := &bytes.Buffer{}
	thumbImg := getThumbnailImg(imgUrl)
	if thumbImg == nil {
		context.Status(http.StatusNotFound)
		return
	}

	jpeg.Encode(buff, thumbImg, nil)
	rspCacheControl(buff.Bytes(), context)
}
Example #6
0
func (as ApiService) serviceList(c *gin.Context) {
	fmt.Println("testando redirect")
	services := as.balancer.GetServices()
	if len(services) == 0 {
		c.Status(http.StatusNoContent)
		return
	}
	c.JSON(http.StatusOK, services)
}