beego 点滴
在使用beego时遇到 need a primary key field
1 确保结构中的 字段首字母大写
2 beego默认主键是id 如果主键定义的是其他字段比如userid 那么加上orm pk type User struct {
Id int `orm:"pk;column(Userid);"`
Name string
}
beego 上传文件
package main import (
"github.com/astaxie/beego"
) type UploadController struct {
beego.Controller
}
func (this *UploadController) Post() {
this.SaveToFile("uploadfile", "./static/files/",true)
this.Ctx.Redirect(, "/upload") }
/*
* fromfile input type=file name=fromfile
* tofilepath the path where the file going to save
* newfilename boolen is create new name or use original name
*/
func (c *UploadController) SaveToFile(fromfile, tofilepath string, newfilename bool) error {
file, h, err := c.Ctx.Request.FormFile(fromfile)
if err != nil {
return err
}
defer file.Close()
newname := h.Filename
if newfilename {
newname = fmt.Sprintf("%v%s", time.Now().Unix(), path.Ext(h.Filename))
}
tofilepath = path.Join(tofilepath, newname)
f, err := os.OpenFile(tofilepath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, )
if err != nil {
return err
}
defer f.Close()
io.Copy(f, file)
return nil
}
func main() {
beego.Router("/upload", &UploadController{}) beego.Run()
}
<head>
<title>上传文件</title>
</head>
<body> <form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="uploadfile" />
<input type="submit" value="upload" />
</form> </body>
</html>
beego 点滴的更多相关文章
- 【原】Go语言及Web框架Beego环境无脑搭建
本文涉及软件均以截至到2013年10月12日的最新版本为准 1. 相关软件准备: 1) go1.2rc1.windows-386.msi,对应32位windows系统安装使用 下载地址: https: ...
- go中安装Beego不成功笔记
在go.Git等等之类的相关软件安装好了之后,便可以安装Beego. 1.开始的时候是由于网络限制,不能访问Github,这个还好说找VPNFQ... 2.之后的问题,在git Bash中输入go g ...
- beego上传文件
html代码: <form id="fform" method="POST" enctype="multipart/form-data" ...
- golang开发环境配置及Beego框架安装
配置环境:Windows7推荐IDE:LiteIDEGO下载地址:http://www.golangtc.com/downloadBeego开发文档地址:http://beego.me/docs/in ...
- beego 框架入门
根据官网向导安装配置好环境和工具https://beego.me 就可以开始了,先来入门下. 1.新建项目 在项目目录下 bee new quickstart成功后就可以运行了 http serve ...
- 新篇章,Golang 和 beego 初识
beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API.Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado.sinatra ...
- iPhone应用开发 UITableView学习点滴详解
iPhone应用开发 UITableView学习点滴详解是本文要介绍的内容,内容不多,主要是以代码实现UITableView的学习点滴,我们来看内容. -.建立 UITableView DataTab ...
- Pathoto项目:AWS+golang+beego搭建
帮兄弟写了一个网站,由于要在国外使用,选择了AWS作为服务器. 不知道后面的价格如何,12个月免费的确吸引了我. 花费3天时间,从注册到服务器搭建访问,终于搞定了.下面记录一下其中容易出错的命令. 1 ...
- Beego框架使用
go get github.com/astaxie/beego vim hello.go package main import "github.com/astaxie/beego" ...
随机推荐
- 代码阅读:AFNetworking背后的思想
1.一切皆文件:流与操作封装. 2.通信会话:
- python 中if-else的多种简洁的写法
因写多了判断语句,看着短短的代码却占据来好几行,于是便搜下if-else简洁的写法,结果也是发现新大陆 4种: 第1种:__就是普通写法 a, b, c = 1, 2, 3 if a>b: c ...
- Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】
任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...
- Dos操作基础
dos命令大全 使用技巧 dos命令不区分大小写,比如C盘的Program Files,在dos命令中完全可以用"program files"代替,加上英文引号是因为名称的中间有空 ...
- 关于swing界面label和button的动态设置文字
在引入发送验证码功能后,想让button的文本动态变化,发现如下方法并不能做到: int limitSec=10; while(limitSec>0){ sendyzhm.setEnabled( ...
- jdk8新特性之双冒号 :: 用法及详解
jdk8的新特性有很多,最亮眼的当属函数式编程的语法糖,本文主要讲解下双冒号::的用法. 概念 类名::方法名,相当于对这个方法闭包的引用,类似js中的一个function.比如: Function& ...
- const、let、var的主要区别
接触ES6之后,以前定义变量的方式由var增加了let.const,平时看别人用也不知道如何区别具体差别,好好科普了一下记录下来,方便大家一起学习. var(大家最熟悉的定义方式) 1.可定义全局作用 ...
- LeetCode 中级 - 组合总和(105)
给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的数字可以无限制重复被选 ...
- SQL:登录、连接数据库基本操作
使用MySQL 登录.连接数据库 win+R打开控制台,cmd进入控制台,输入mysql -u root -p,后输入密码,进入数据库: 首先可以查看原有的数据库,输入 show databases; ...
- MySQL 5.7增强半同步测试
we've know the machenism of semi-synchronous replication in my previous article,let's do som ...