23039393 by astaxie

finish Quickstart.md

1 parent 99b09b2e
...@@ -682,8 +682,92 @@ LevelTrace、LevelDebug、LevelInfo、LevelWarning、 LevelError、LevelCritical ...@@ -682,8 +682,92 @@ LevelTrace、LevelDebug、LevelInfo、LevelWarning、 LevelError、LevelCritical
682 } 682 }
683 683
684 ## 第三方应用集成 684 ## 第三方应用集成
685 beego支持第三方应用的集成,用户可以自定义`http.Handler`,用户可以通过如下方式进行注册路由:
686
687 beego.RouterHandler("/chat/:info(.*)", sockjshandler)
688
689 sockjshandler实现了接口`http.Handler`
690
691 目前在beego的example中有支持sockjs的chat例子,示例代码如下:
692
693 package main
694
695 import (
696 "fmt"
697 "github.com/astaxie/beego"
698 "github.com/fzzy/sockjs-go/sockjs"
699 "strings"
700 )
701
702 var users *sockjs.SessionPool = sockjs.NewSessionPool()
703
704 func chatHandler(s sockjs.Session) {
705 users.Add(s)
706 defer users.Remove(s)
707
708 for {
709 m := s.Receive()
710 if m == nil {
711 break
712 }
713 fullAddr := s.Info().RemoteAddr
714 addr := fullAddr[:strings.LastIndex(fullAddr, ":")]
715 m = []byte(fmt.Sprintf("%s: %s", addr, m))
716 users.Broadcast(m)
717 }
718 }
719
720 type MainController struct {
721 beego.Controller
722 }
723
724 func (m *MainController) Get() {
725 m.TplNames = "index.html"
726 }
727
728 func main() {
729 conf := sockjs.NewConfig()
730 sockjshandler := sockjs.NewHandler("/chat", chatHandler, conf)
731 beego.Router("/", &MainController{})
732 beego.RouterHandler("/chat/:info(.*)", sockjshandler)
733 beego.Run()
734 }
735
736 通过上面的代码很简单的实现了一个多人的聊天室。上面这个只是一个sockjs的例子,我想通过大家自定义`http.Handler`,可以有很多种方式来进行扩展beego应用。
685 737
686 ## 部署编译应用 738 ## 部署编译应用
739 Go语言的应用最后编译之后是一个二进制文件,你只需要copy这个应用到服务器上,运行起来就行。beego由于带有几个静态文件、配置文件、模板文件三个目录,所以用户部署的时候需要同时copy这三个目录到相应的部署应用之下,下面以我实际的应用部署为例:
740
741 $ mkdir /opt/app/beepkg
742 $ cp beepkg /opt/app/beepkg
743 $ cp -fr views /opt/app/beepkg
744 $ cp -fr static /opt/app/beepkg
745 $ cp -fr conf /opt/app/beepkg
746
747 这样在`/opt/app/beepkg`目录下面就会显示如下的目录结构:
748
749 .
750 ├── conf
751 │ ├── app.conf
752 ├── static
753 │ ├── css
754 │ ├── img
755 │ └── js
756 └── views
757 └── index.tpl
758 ├── beepkg
759
760 这样我们就已经把我们需要的应用搬到服务器了,那么接下来就可以开始部署了,我现在服务器端用两种方式来run,
761
762 - Supervisord
763
764 安装和配置见[Supervisord](Supervisord.md)
765
766 - nohup方式
767
768 nohup ./beepkg &
769
770 个人比较推荐第一种方式,可以很好的管理起来应用
687 771
688 - [beego介绍](README.md) 772 - [beego介绍](README.md)
689 - [一步一步开发应用](Tutorial.md) 773 - [一步一步开发应用](Tutorial.md)
...\ No newline at end of file ...\ No newline at end of file
......
1 ## supervisord安装
2
3 1. setuptools安装
4
5 wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
6
7 sh setuptools-0.6c11-py2.7.egg
8
9 easy_install supervisor
10
11 echo_supervisord_conf >/etc/supervisord.conf
12
13 mkdir /etc/supervisord.conf.d
14
15 2. 修改配置/etc/supervisord.conf
16
17 [include]
18 files = /etc/supervisord.conf.d/*.conf
19
20 3. 新建管理的应用
21
22 cd /etc/supervisord.conf.d
23 vim ddq.conf
24
25 配置文件:
26
27 [program:ddq]
28 directory = /opt/app/ddq
29 command = /opt/app/ddq/ddq
30 autostart = true
31 startsecs = 5
32 user = root
33 redirect_stderr = true
34 stdout_logfile = /var/log/supervisord/shorturl.log
...\ No newline at end of file ...\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!