go on write docs
Showing
2 changed files
with
63 additions
and
0 deletions
docs/en/README.md
0 → 100644
This diff is collapsed.
Click to expand it.
| ... | @@ -2,6 +2,69 @@ | ... | @@ -2,6 +2,69 @@ |
| 2 | 你对beego一无所知?没关系,这篇文档会很好的详细介绍beego的各个方面,看这个文档之前首先确认你已经安装了beego,如果你没有安装的话,请看这篇[安装指南](Install.md) | 2 | 你对beego一无所知?没关系,这篇文档会很好的详细介绍beego的各个方面,看这个文档之前首先确认你已经安装了beego,如果你没有安装的话,请看这篇[安装指南](Install.md) |
| 3 | 3 | ||
| 4 | ## 最小应用 | 4 | ## 最小应用 |
| 5 | 一个最小最简单的应用如下代码所示: | ||
| 6 | |||
| 7 | package main | ||
| 8 | |||
| 9 | import ( | ||
| 10 | "github.com/astaxie/beego" | ||
| 11 | ) | ||
| 12 | |||
| 13 | type MainController struct { | ||
| 14 | beego.Controller | ||
| 15 | } | ||
| 16 | |||
| 17 | func (this *MainController) Get() { | ||
| 18 | this.Ctx.WriteString("hello world") | ||
| 19 | } | ||
| 20 | |||
| 21 | func main() { | ||
| 22 | beego.Router("/", &MainController{}) | ||
| 23 | beego.Run() | ||
| 24 | } | ||
| 25 | |||
| 26 | 把上面的代码保存为hello.go,然后通过命令行进行编译并执行: | ||
| 27 | |||
| 28 | $ go build main.go | ||
| 29 | $ ./hello | ||
| 30 | |||
| 31 | 这个时候你可以打开你的浏览器,通过这个地址浏览[http://127.0.0.1:8080](http://127.0.0.1:8080)返回“hello world” | ||
| 32 | |||
| 33 | 那么上面的代码到底做了些什么呢? | ||
| 34 | |||
| 35 | 1、首先我们引入了包`github.com/astaxie/beego`,beego包中会初始化一个BeeAPP的应用, | ||
| 36 | |||
| 37 | 2、定义了Controller | ||
| 38 | |||
| 39 | 3、定义了RESTFul方法 | ||
| 40 | |||
| 41 | 4、定义了main函数 | ||
| 42 | |||
| 43 | 5、Route注册路由 | ||
| 44 | |||
| 45 | 6、Run应用 | ||
| 46 | |||
| 47 | ## 新建项目 | ||
| 48 | |||
| 49 | 通过如下命令创建beego项目,首先进入gopath目录 | ||
| 50 | |||
| 51 | bee create hello | ||
| 52 | |||
| 53 | 这样就建立了一个项目hello,目录结构如下所示 | ||
| 54 | |||
| 55 | . | ||
| 56 | ├── conf | ||
| 57 | │ └── app.conf | ||
| 58 | ├── controllers | ||
| 59 | │ └── default.go | ||
| 60 | ├── main.go | ||
| 61 | ├── models | ||
| 62 | ├── static | ||
| 63 | │ ├── css | ||
| 64 | │ ├── img | ||
| 65 | │ └── js | ||
| 66 | └── views | ||
| 67 | └── index.tpl | ||
| 5 | 68 | ||
| 6 | ## 开发模式 | 69 | ## 开发模式 |
| 7 | 70 | ... | ... |
-
Please register or sign in to post a comment