本文整理汇总了Golang中github.com/Unknwon/macaron.Context.Params方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Params方法的具体用法?Golang Context.Params怎么用?Golang Context.Params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Unknwon/macaron.Context
的用法示例。
在下文中一共展示了Context.Params方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetTagsListV2Handler
func GetTagsListV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
r := new(models.Repository)
if has, _, err := r.Has(namespace, repository); err != nil || has == false {
log.Error("[REGISTRY API V2] Repository not found: %v", repository)
result, _ := json.Marshal(map[string]string{"message": "Repository not found"})
return http.StatusNotFound, result
}
data := map[string]interface{}{}
tags := []string{}
data["name"] = fmt.Sprintf("%s/%s", namespace, repository)
for _, value := range r.Tags {
t := new(models.Tag)
if err := t.GetByKey(value); err != nil {
log.Error("[REGISTRY API V2] Tag not found: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Tag not found"})
return http.StatusNotFound, result
}
tags = append(tags, t.Name)
}
data["tags"] = tags
result, _ := json.Marshal(data)
return http.StatusOK, result
}
示例2: PutRepositoryV1Handler
func PutRepositoryV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
username, _, _ := utils.DecodeBasicAuth(ctx.Req.Header.Get("Authorization"))
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
body, err := ctx.Req.Body().String()
if err != nil {
log.Error("[REGISTRY API V1] Get request body error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put V1 repository failed,request body is empty"})
return http.StatusBadRequest, result
}
r := new(models.Repository)
if err := r.Put(namespace, repository, body, ctx.Req.Header.Get("User-Agent"), setting.APIVERSION_V1); err != nil {
log.Error("[REGISTRY API V1] Put repository error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": err.Error()})
return http.StatusBadRequest, result
}
if ctx.Req.Header.Get("X-Docker-Token") == "true" {
token := fmt.Sprintf("Token signature=%v,repository=\"%v/%v\",access=%v",
utils.MD5(username),
namespace,
repository,
"write")
ctx.Resp.Header().Set("X-Docker-Token", token)
ctx.Resp.Header().Set("WWW-Authenticate", token)
}
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例3: docs
func docs(ctx *macaron.Context, locale i18n.Locale, name string) {
docRoot := models.GetDocByLocale(name, locale.Lang)
if docRoot == nil {
docRoot = models.GetDocByLocale(name, "en-US")
}
link := strings.TrimPrefix(ctx.Params("*"), "/")
link = strings.TrimSuffix(link, ".html")
link = strings.TrimSuffix(link, ".md")
ctx.Data["Link"] = "/docs/" + link
var doc *models.DocNode
if len(link) == 0 {
ctx.Redirect("/docs/intro/")
return
}
doc, _ = docRoot.GetNodeByLink(link)
if doc == nil {
doc, _ = docRoot.GetNodeByLink(link + "/")
}
if doc == nil {
ctx.Error(404)
return
}
ctx.Data["DocRoot"] = docRoot
ctx.Data["Doc"] = doc
ctx.Data["Title"] = doc.Name
ctx.Data["Data"] = doc.GetContent()
ctx.HTML(200, "document_"+name, ctx.Data)
}
示例4: PutImageLayerv1Handler
func PutImageLayerv1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
imageId := ctx.Params(":imageId")
basePath := setting.ImagePath
imagePath := fmt.Sprintf("%v/images/%v", basePath, imageId)
layerfile := fmt.Sprintf("%v/images/%v/layer", basePath, imageId)
if !utils.IsDirExist(imagePath) {
os.MkdirAll(imagePath, os.ModePerm)
}
if _, err := os.Stat(layerfile); err == nil {
os.Remove(layerfile)
}
data, _ := ioutil.ReadAll(ctx.Req.Request.Body)
if err := ioutil.WriteFile(layerfile, data, 0777); err != nil {
log.Error("[REGISTRY API V1] Put Image Layer File Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put Image Layer File Error"})
return http.StatusBadRequest, result
}
i := new(models.Image)
if err := i.PutLayer(imageId, layerfile, true, int64(len(data))); err != nil {
log.Error("[REGISTRY API V1] Put Image Layer File Data Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put Image Layer File Data Error"})
return http.StatusBadRequest, result
}
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例5: Static
func Static(ctx *macaron.Context) {
if len(ctx.Params(":all")) > 0 {
f, err := os.Open(
path.Join(
"docs",
"gitea",
"images",
ctx.Params(":all")))
defer f.Close()
if err != nil {
ctx.JSON(500, map[string]interface{}{
"error": err.Error(),
})
return
}
if _, err = io.Copy(ctx.RW(), f); err != nil {
ctx.JSON(500, map[string]interface{}{
"error": err.Error(),
})
return
}
return
}
ctx.Error(404)
}
示例6: PutImageChecksumV1Handler
func PutImageChecksumV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
imageId := ctx.Params(":imageId")
checksum := strings.Split(ctx.Req.Header.Get("X-Docker-Checksum"), ":")[1]
payload := strings.Split(ctx.Req.Header.Get("X-Docker-Checksum-Payload"), ":")[1]
log.Debug("[REGISTRY API V1] Image Checksum : %v", checksum)
log.Debug("[REGISTRY API V1] Image Payload: %v", payload)
i := new(models.Image)
if err := i.PutChecksum(imageId, checksum, true, payload); err != nil {
log.Error("[REGISTRY API V1] Put Image Checksum & Payload Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put Image Checksum & Payload Error"})
return http.StatusBadRequest, result
}
if err := i.PutAncestry(imageId); err != nil {
log.Error("[REGISTRY API V1] Put Image Ancestry Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put Image Ancestry Error"})
return http.StatusBadRequest, result
}
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例7: GetImageJSONV1Handler
func GetImageJSONV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
var jsonInfo string
var payload string
var err error
imageId := ctx.Params(":imageId")
i := new(models.Image)
if jsonInfo, err = i.GetJSON(imageId); err != nil {
log.Error("[REGISTRY API V1] Search Image JSON Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Search Image JSON Error"})
return http.StatusNotFound, result
}
if payload, err = i.GetChecksumPayload(imageId); err != nil {
log.Error("[REGISTRY API V1] Search Image Checksum Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Search Image Checksum Error"})
return http.StatusNotFound, result
}
ctx.Resp.Header().Set("X-Docker-Checksum-Payload", fmt.Sprintf("sha256:%v", payload))
ctx.Resp.Header().Set("X-Docker-Size", fmt.Sprint(i.Size))
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(jsonInfo)))
return http.StatusOK, []byte(jsonInfo)
}
示例8: PutRepositoryImagesV1Handler
func PutRepositoryImagesV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
r := new(models.Repository)
if err := r.PutImages(namespace, repository); err != nil {
log.Error("[REGISTRY API V1] Put images error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put V1 images error"})
return http.StatusBadRequest, result
}
if ctx.Req.Header.Get("X-Docker-Token") == "true" {
username, _, _ := utils.DecodeBasicAuth(ctx.Req.Header.Get("Authorization"))
token := fmt.Sprintf("Token signature=%v,repository=\"%v/%v\",access=%v",
utils.MD5(username),
namespace,
repository,
"write")
ctx.Resp.Header().Set("X-Docker-Token", token)
ctx.Resp.Header().Set("WWW-Authenticate", token)
}
result, _ := json.Marshal(map[string]string{})
return http.StatusNoContent, result
}
示例9: GetTagV1Handler
func GetTagV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
repo := new(models.Repository)
if has, _, err := repo.Has(namespace, repository); err != nil {
log.Error("[REGISTRY API V1] Read repository json error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get V1 tag failed,wrong name or repository"})
return http.StatusBadRequest, result
} else if has == false {
log.Error("[REGISTRY API V1] Read repository no found. %v/%v", namespace, repository)
result, _ := json.Marshal(map[string]string{"message": "Get V1 tag failed,read repository no found"})
return http.StatusNotFound, result
}
tag := map[string]string{}
for _, value := range repo.Tags {
t := new(models.Tag)
if err := db.Get(t, value); err != nil {
log.Error(fmt.Sprintf("[REGISTRY API V1] %s/%s Tags is not exist", namespace, repository))
result, _ := json.Marshal(map[string]string{"message": fmt.Sprintf("%s/%s Tags is not exist", namespace, repository)})
return http.StatusNotFound, result
}
tag[t.Name] = t.ImageId
}
result, _ := json.Marshal(tag)
return http.StatusOK, result
}
示例10: myCacheReadHandler
func myCacheReadHandler(ctx *macaron.Context, c cache.Cache) interface{} {
val := c.Get(ctx.Params(":key"))
if val != nil {
return val
} else {
return fmt.Sprintf("no cache with \"%s\" set", ctx.Params(":key"))
}
}
示例11: DownloadStats
func DownloadStats(ctx *macaron.Context, r *http.Request) {
org := ctx.Params(":org")
name := ctx.Params(":name")
branch := ctx.Params(":branch")
_ = branch
repo := org + "/" + name
osarch := ctx.Params(":os") + "-" + ctx.Params(":arch")
rdx.Incr("downloads:" + repo)
rdx.Incr("downloads:" + repo + ":" + osarch)
ctx.JSON(200, "update success")
}
示例12: PutManifestsV2Handler
func PutManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
agent := ctx.Req.Header.Get("User-Agent")
repo := new(models.Repository)
if err := repo.Put(namespace, repository, "", agent, setting.APIVERSION_V2); err != nil {
log.Error("[REGISTRY API V2] Save repository failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": err.Error()})
return http.StatusBadRequest, result
}
manifest, _ := ioutil.ReadAll(ctx.Req.Request.Body)
if err := modules.ParseManifest(manifest); err != nil {
log.Error("[REGISTRY API V2] Decode Manifest Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Manifest converted failed"})
return http.StatusBadRequest, result
}
digest, err := utils.DigestManifest(manifest)
if err != nil {
log.Error("[REGISTRY API V2] Get manifest digest failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get manifest digest failed"})
return http.StatusBadRequest, result
}
random := fmt.Sprintf("%s://%s/v2/%s/%s/manifests/%s",
setting.ListenMode,
setting.Domains,
namespace,
repository,
digest)
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Location", random)
result, _ := json.Marshal(map[string]string{})
return http.StatusAccepted, result
}
示例13: HeadBlobsV2Handler
func HeadBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
digest := ctx.Params(":digest")
tarsum := strings.Split(digest, ":")[1]
i := new(models.Image)
if has, _ := i.HasTarsum(tarsum); has == false {
log.Info("[REGISTRY API V2] Tarsum not found: %v", tarsum)
result, _ := json.Marshal(map[string]string{"message": "Tarsum not found"})
return http.StatusNotFound, result
}
ctx.Resp.Header().Set("Content-Type", "application/x-gzip")
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(i.Size))
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例14: Docs
func Docs(ctx *macaron.Context, locale i18n.Locale) {
docRoot := models.GetDocByLocale(
"gitea",
locale.Lang)
if docRoot == nil {
ctx.Error(404)
return
}
link := strings.TrimSuffix(
strings.TrimSuffix(
strings.TrimPrefix(
ctx.Params("*"),
"/"),
".html"),
".md")
ctx.Data["Link"] = "/docs/" + link
if len(link) == 0 {
ctx.Redirect("/docs/intro/")
return
}
doc, _ := docRoot.GetNodeByLink(link)
if doc == nil {
doc, _ = docRoot.GetNodeByLink(link + "/")
}
if doc == nil {
ctx.Error(404)
return
}
ctx.Data["DocRoot"] = docRoot
ctx.Data["Doc"] = doc
ctx.Data["Title"] = doc.Name
ctx.Data["Data"] = doc.GetContent()
ctx.HTML(200, "gitea", ctx.Data)
}
示例15: PostBlobsV2Handler
func PostBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
uuid := utils.MD5(uuid.NewV4().String())
state := utils.MD5(fmt.Sprintf("%s/%s/%s", namespace, repository, time.Now().UnixNano()/int64(time.Millisecond)))
random := fmt.Sprintf("https://%s/v2/%s/%s/blobs/uploads/%s?_state=%s",
setting.Domains,
namespace,
repository,
uuid,
state)
ctx.Resp.Header().Set("Docker-Upload-Uuid", uuid)
ctx.Resp.Header().Set("Location", random)
ctx.Resp.Header().Set("Range", "0-0")
result, _ := json.Marshal(map[string]string{})
return http.StatusAccepted, result
}