Commit 20e101a4 authored by astaxie's avatar astaxie

Merge pull request #74 from matrixik/master

Clean and fix docs markdown
parents 67511dee 10417dd6
......@@ -24,12 +24,13 @@ Have this features:
[中文文档](https://github.com/astaxie/beego/tree/master/docs/zh)
## LICENSE
beego is licensed under the Apache Licence, Version 2.0
(http://www.apache.org/licenses/LICENSE-2.0.html).
## Use Case
- API documentation [gowalker](https://github.com/Unknwon/gowalker)
- CMS [toropress](https://github.com/insionng/toropress)
##What is hot update?
## What is hot update?
If you have used nginx, you may know that nginx supports hot update, which means you can update your nginx without stopping and restarting it. It serves old connections with old version, and accepts new connections with new version. Notice that hot compiling is different from hot update, where hot compiling is monitoring your source files and recompile them when the content changes, it requires stop and restart your applications, `bee start` is a tool for hot compiling.
##Is hot update necessary?
## Is hot update necessary?
Some people says that hot update is not as useful as its cool name. In my opinion, this is absolutely necessary because zero-down server is our goal for our services. Even though sometimes some errors or hardware problems may occur, but it belongs to design of high availability, don't mix them up. Service update is a known issue, so we need to fix this problem.
##How Beego support hot update?
## How Beego support hot update?
The basic principle of hot update: main process fork a process, and child process execute corresponding programs. So what happens? We know that after forked a process, main process will have all handles, data and stack, etc, but all handles are saved in `CloseOnExec`, so all copied handles will be closed when you execute it unless you clarify this, and we need child process to reuse the handle of `net.Listener`. Once a process calls exec functions, it is "dead", system replaces it with new code. The only thing it left is the process ID, which is the same number but it is a new program after executed.
Therefore, the first thing we need to do is that let child process fork main process and through `os.StartProcess` to append files that contains handle that is going to be inherited.
......@@ -15,7 +20,8 @@ The final step is that we want to serve old connections with old version of appl
Above are three problems that we need to solve, you can see my code logic for specific implementation.
##Show time
## Show time
1. Write code in your Get method:
......@@ -29,7 +35,7 @@ Above are three problems that we need to solve, you can see my code logic for sp
One execute: ` ps -ef|grep <application name>`
Another one execute:`curl "http://127.0.0.1:8080/?sleep=20"`
Another one execute: `curl "http://127.0.0.1:8080/?sleep=20"`
3. Hot update
......
#Installation
# Installation
Beego is a simple web framework, but it uses many third-party packages, so you have to install all dependency packages also.
- Before anything you do, you have to check that you installed Go in your computer, see more detail about Go installation in my book: [Chapter 1](https://github.com/Unknwon/build-web-application-with-golang_EN/blob/master/eBook/01.1.md)
......@@ -16,10 +17,10 @@ Good job, you're ready to Beego with powerful bee tools!
Beego has following dependency packages:
- Session module: [github.com/astaxie/beego/session](github.com/astaxie/beego/session)
- To support redis engine: [github.com/garyburd/redigo/redis](github.com/garyburd/redigo/redis)
- To support mysql engine: [github.com/go-sql-driver/mysql](github.com/go-sql-driver/mysql)
- To support markdown as template function: [github.com/russross/blackfriday](github.com/russross/blackfriday)
- Session module: [github.com/astaxie/beego/session](https://github.com/astaxie/beego/session)
- To support redis engine: [github.com/garyburd/redigo/redis](https://github.com/garyburd/redigo/redis)
- To support mysql engine: [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)
- To support markdown as template function: [github.com/russross/blackfriday](https://github.com/russross/blackfriday)
- [Introduction](README.md)
- [Quick start](Quickstart.md)
This diff is collapsed.
#Beego
# Beego
Beego is a lightweight, open source, non-blocking and scalable web framework for the Go programming language. It's like tornado in Python. This web framework has already been using for building web server and tools in SNDA's CDN system. Documentation and downloads available at [http://astaxie.github.com/beego](http://astaxie.github.com/beego)
It has following main features:
......@@ -19,7 +20,9 @@ The working principles of Beego as follows:
Beego is licensed under the Apache Licence, Version 2.0
(http://www.apache.org/licenses/LICENSE-2.0.html).
#Simple example
# Simple example
The following example prints string "Hello world" to your browser, it shows how easy to build a web application with Beego.
package main
......@@ -41,7 +44,9 @@ The following example prints string "Hello world" to your browser, it shows how
beego.Run()
}
#Handbook
# Handbook
- [Purposes](Why.md)
- [Installation](Install.md)
- [Quick start](Quickstart.md)
......@@ -49,5 +54,7 @@ The following example prints string "Hello world" to your browser, it shows how
- [Real world usage](Application.md)
- [Hot update](HotUpdate.md)
#Documentation
# Documentation
[Go Walker](http://gowalker.org/github.com/astaxie/beego)
##supervisord
## supervisord
1. Installation
......
# 一步一步跟我写博客
## 创建项目
## 数据库结构设计
## 控制器设计
## 模板设计
## 用户登陆退出
## 数据库操作
# Design purposes and ideas
People may ask me why I want to build a new web framework rather than use other good ones. I know there are many excellent web frameworks on the internet and almost all of them are open source, and I have my reasons to do this.
Remember when I was writing the book about how to build web applications with Go, I just wanted to tell people what were my valuable experiences with Go in web development, especially I have been working with PHP and Python for almost ten years. At first, I didn't realize that a small web framework can give great help to web developers when they are learning to build web applications in a new programming language, and it also helps people more by studying its source code. Finally, I decided to write a open source web framework called Beego as supporting materiel for my book.
......@@ -9,7 +10,7 @@ I used to use CI in PHP and tornado in Python, there are both lightweight, so th
2. Learn more about languages by studying their source code, it's not hard to read and understand them because they are both lightweight frameworks.
3. It's quite easy to make secondary development of these frameworks for specific purposes.
Those reasons are my original intention of implementing Beego, and used two chapters in my book to introduce and design this lightweight web framework in GO.
Those reasons are my original intention of implementing Beego, and used two chapters in my book to introduce and design this lightweight web framework in Go.
Then I started to design logic execution of Beego. Because Go and Python have somewhat similar, I referenced some ideas from tornado to design Beego. As you can see, there is no different between Beego and tornado in RESTful processing; they both use GET, POST or some other methods to implement RESTful. I took some ideas from [https://github.com/drone/routes](https://github.com/drone/routes) at the beginning of designing routes. It uses regular expression in route rules processing, which is an excellent idea that to make up for the default Mux router function in Go. However, I have to design my own interface in order to implement RESTful and use inherited ideas in Python.
......
......@@ -2,10 +2,12 @@
热升级是什么呢?了解nginx的同学都知道,nginx是支持热升级的,可以用老进程服务先前链接的链接,使用新进程服务新的链接,即在不停止服务的情况下完成系统的升级与运行参数修改。那么热升级和热编译是不同的概念,热编译是通过监控文件的变化重新编译,然后重启进程,例如bee start就是这样的工具
## 热升级有必要吗?
很多人认为HTTP的应用有必要支持热升级吗?那么我可以很负责的说非常有必要,不中断服务始终是我们所追求的目标,虽然很多人说可能服务器会坏掉等等,这个是属于高可用的设计范畴,不要搞混了,这个是可预知的问题,所以我们需要避免这样的升级带来的用户不可用。你还在为以前升级搞到凌晨升级而烦恼嘛?那么现在就赶紧拥抱热升级吧。
## beego如何支持热升级
热升级的原理基本上就是:主进程fork一个进程,然后子进程exec相应的程序。那么这个过程中发生了什么呢?我们知道进程fork之后会把主进程的所有句柄、数据和堆栈继承过来、但是里面所有的句柄存在一个叫做CloseOnExec,也就是执行exec的时候,copy的所有的句柄都被关闭了,除非特别申明,而我们期望的是子进程能够复用主进程的net.Listener的句柄。一个进程一旦调用exec类函数,它本身就"死亡"了,系统把代码段替换成新的程序的代码,废弃原有的数据段和堆栈段,并为新程序分配新的数据段与堆栈段,唯一留下的,就是进程号,也就是说,对系统而言,还是同一个进程,不过已经是另一个程序了。
......@@ -17,6 +19,7 @@
上面是我们需要解决的三个方面的问题,具体的实现大家可以看我实现的代码逻辑。
## 如何演示热升级
1. 编写代码,在beego应用的控制器中Get方法实现大概如下:
......
# 安装入门
beego虽然是一个简单的框架,但是其中用到了很多第三方的包,所以在你安装beego的过程中Go会自动安装其他关联的包。
- 当然第一步你需要安装Go,如何安装Go请参考我的书[第一章](https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/01.1.md)
......@@ -19,6 +20,7 @@ beego虽然是一个简单的框架,但是其中用到了很多第三方的包
> - session模块:github.com/astaxie/beego/session
> - session模块中支持redis引擎:github.com/garyburd/redigo/redis
> - session模块中支持mysql引擎:github.com/go-sql-driver/mysql
......
This diff is collapsed.
......@@ -34,6 +34,7 @@ beego是一个类似tornado的Go应用框架,采用了RESTFul的方式来实
beego.Run()
}
# beego 指南
* [为什么设计beego](Why.md)
......@@ -43,6 +44,7 @@ beego是一个类似tornado的Go应用框架,采用了RESTFul的方式来实
* [beego案例](Application.md)
* [热升级](HotUpdate.md)
# API接口
API对于我们平时开发应用非常有用,用于查询一些开发的函数,godoc做的非常好了
......
# 一步一步跟我写博客
## 创建项目
## 数据库结构设计
## 控制器设计
## 模板设计
## 用户登陆退出
## 数据库操作
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment