本文整理汇总了Golang中github.com/daemonl/go_gsd/shared.IRequest.URLMatch方法的典型用法代码示例。如果您正苦于以下问题:Golang IRequest.URLMatch方法的具体用法?Golang IRequest.URLMatch怎么用?Golang IRequest.URLMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/daemonl/go_gsd/shared.IRequest
的用法示例。
在下文中一共展示了IRequest.URLMatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Upload
func (h *FileHandler) Upload(request shared.IRequest) error {
var functionName string
var fileCollection string
var collectionRef string
var collectionId uint64
err := request.URLMatch(&functionName, &fileCollection, &collectionRef, &collectionId)
if err != nil {
return err
}
_, r := request.GetRaw()
if r.Method != "POST" && r.Method != "PUT" {
request.WriteString("Must post a file (1)")
return nil
}
mpr, err := r.MultipartReader()
if err != nil {
return err
}
var part *multipart.Part
for {
thisPart, err := mpr.NextPart()
if err != nil {
break
}
if thisPart.FormName() == "attachment" {
part = thisPart
break
}
}
if part == nil {
request.WriteString("Must post a file (2)")
return nil
}
origName := part.FileName()
randBytes := make([]byte, 22, 22)
_, _ = rand.Reader.Read(randBytes)
fileName := hex.EncodeToString(randBytes)
bucket, err := h.getBucket()
if err != nil {
return err
}
upload, err := ioutil.ReadAll(part)
if err != nil {
return err
}
err = bucket.Put(h.Path+fileName, upload, "application/octet-stream", s3.Private)
if err != nil {
return err
}
log.Println("File Written")
dbEntry := map[string]interface{}{
collectionRef: collectionId,
"file": fileName,
"filename": origName,
}
err = h.writeDatabaseEntry(request, dbEntry, fileCollection)
if err != nil {
return err
}
request.WriteString(`
<script type='text/javascript'>
window.top.file_done()
</script>
Uploaded Successfully.
`)
return nil
}