本文整理汇总了Golang中github.com/daemonl/go_gsd/shared.IRequest.GetRaw方法的典型用法代码示例。如果您正苦于以下问题:Golang IRequest.GetRaw方法的具体用法?Golang IRequest.GetRaw怎么用?Golang IRequest.GetRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/daemonl/go_gsd/shared.IRequest
的用法示例。
在下文中一共展示了IRequest.GetRaw方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Handle
func (h *RawFileHandler) Handle(req shared.IRequest) (shared.IResponse, error) {
w, _ := req.GetRaw()
file, err := os.Open(h.WebRoot + "/" + h.Filename)
if err != nil {
fmt.Fprintln(w, err.Error())
w.WriteHeader(http.StatusInternalServerError)
return nil, nil
}
defer file.Close()
io.Copy(w, file)
return nil, nil
}
示例2: Handle
func (wh *wrappedHandler) Handle(request shared.IRequest) (shared.IResponse, error) {
requestData := wh.handler.RequestDataPlaceholder()
_, r := request.GetRaw()
// Decode request body JSON to object
dec := json.NewDecoder(r.Body)
err := dec.Decode(requestData)
if err != nil {
return nil, err
}
// Do the request
return wh.handler.Handle(request, requestData)
}
示例3: 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
}