当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.StringOr方法代码示例

本文整理汇总了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)
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:40,代码来源:upload.go


注:本文中的github.com/fuxiaohei/GoInk.Context.StringOr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。