本文整理汇总了Golang中github.com/fuxiaohei/GoInk.Context.StringOr方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.StringOr方法的具体用法?Golang Context.StringOr怎么用?Golang Context.StringOr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/fuxiaohei/GoInk.Context
的用法示例。
在下文中一共展示了Context.StringOr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FileUpload
func FileUpload(context *GoInk.Context) {
var req *http.Request
req = context.Request
req.ParseMultipartForm(32 << 20)
f, h, e := req.FormFile("file")
if e != nil {
Json(context, false).Set("msg", e.Error()).End()
return
}
data, _ := ioutil.ReadAll(f)
maxSize := context.App().Config().Int("app.upload_size")
defer func() {
f.Close()
data = nil
h = nil
}()
if len(data) >= maxSize {
Json(context, false).Set("msg", "文件应小于10M").End()
return
}
if !strings.Contains(context.App().Config().String("app.upload_files"), path.Ext(h.Filename)) {
Json(context, false).Set("msg", "文件只支持Office文件,图片和zip存档").End()
return
}
ff := new(model.File)
ff.Name = h.Filename
ff.Type = context.StringOr("type", "image")
ff.Size = int64(len(data))
ff.ContentType = h.Header["Content-Type"][0]
ff.Author, _ = strconv.Atoi(context.Cookie("token-user"))
ff.Url = model.CreateFilePath(context.App().Get("upload_dir"), ff)
e = ioutil.WriteFile(ff.Url, data, os.ModePerm)
if e != nil {
Json(context, false).Set("msg", e.Error()).End()
return
}
model.CreateFile(ff)
Json(context, true).Set("file", ff).End()
context.Do("attach_created", ff)
}