645bf79b by astaxie

Merge pull request #50 from Unknwon/master

complete quick start
2 parents 7b6a571f e1a4001c
...@@ -12,16 +12,16 @@ Hey, you say you've never heard about Beego and don't know how to use it? Don't ...@@ -12,16 +12,16 @@ Hey, you say you've never heard about Beego and don't know how to use it? Don't
12 - [Controller](#controller) 12 - [Controller](#controller)
13 - [Template](#template) 13 - [Template](#template)
14 - [Handle request](#handle-request) 14 - [Handle request](#handle-request)
15 - [Redirect and error](#-15) 15 - [Redirect and error](#redirect-and-error)
16 - [Handle response](#response) 16 - [Handle response](#handle-response)
17 - [Sessions](#sessions) 17 - [Sessions](#sessions)
18 - [Cache](#cache) 18 - [Cache](#cache)
19 - [Safe map](#map) 19 - [Safe map](#safe-map)
20 - [Log](#-16) 20 - [Log](#log)
21 - [Configuration](#-17) 21 - [Configuration](#configuration)
22 - [Beego arguments](#-18) 22 - [Beego arguments](#beego-arguments)
23 - [Integrated third-party applications](#-19) 23 - [Integrated third-party applications](#integrated-third-party-applications)
24 - [Deployment](#-20) 24 - [Deployment](#deployment)
25 25
26 ## Hello world 26 ## Hello world
27 This is an example of "Hello world" in Beego: 27 This is an example of "Hello world" in Beego:
...@@ -465,44 +465,44 @@ Set `content-type` to `application/xml` for output raw XML format data: ...@@ -465,44 +465,44 @@ Set `content-type` to `application/xml` for output raw XML format data:
465 this.ServeXml() 465 this.ServeXml()
466 } 466 }
467 467
468 ## 跳转和错误 468 ##Redirect and error
469 我们在做Web开发的时候,经常会遇到页面调整和错误处理,beego这这方面也进行了考虑,通过`Redirect`方法来进行跳转: 469 You can use following to redirect:
470 470
471 func (this *AddController) Get() { 471 func (this *AddController) Get() {
472 this.Redirect("/", 302) 472 this.Redirect("/", 302)
473 } 473 }
474 474
475 @todo 错误处理还需要后期改进 475 @todo Error processing need to be improved.
476 476
477 ## response处理 477 ##Handle response
478 response可能会有集中情况: 478 There are some situations that you may have in response:
479 479
480 1. 模板输出 480 1. Output template
481 481
482 模板输出上面模板介绍里面已经介绍,beego会在执行完相应的Controller里面的对应的Method之后输出到模板。 482 I've already talked about template above, Beego outputs template after corresponding method executed.
483 483
484 2. 跳转 484 2. Redirect
485 485
486 上一节介绍的跳转就是我们经常用到的页面之间的跳转 486 You can use this.Redirect("/", 302) to redirect page.
487 487
488 3. 字符串输出 488 3. Output string
489 489
490 有些时候我们只是想输出相应的一个字符串,那么我们可以通过如下的代码实现 490 Sometimes we just need to print string on the screen:
491 491
492 this.Ctx.WriteString("ok") 492 this.Ctx.WriteString("ok")
493 493
494 ## Sessions 494 ## Sessions
495 beego内置了session模块,目前session模块支持的后端引擎包括memory、file、mysql、redis四中,用户也可以根据相应的interface实现自己的引擎。 495 Beego has a built-in session module and supports four engines, including memory, file, MySQL and redis. You can implement your own engine based on the interface.
496 496
497 beego中使用session相当方便,只要在main入口函数中设置如下: 497 It's easy to use session in Beego, use following code in your main() function:
498 498
499 beego.SessionOn = true 499 beego.SessionOn = true
500 500
501 或者通过配置文件配置如下: 501 Or use configuration file:
502 502
503 sessionon = true 503 sessionon = true
504 504
505 通过这种方式就可以开启session,如何使用session,请看下面的例子: 505 The following example shows you how to use session in Beego:
506 506
507 func (this *MainController) Get() { 507 func (this *MainController) Get() {
508 v := this.GetSession("asta") 508 v := this.GetSession("asta")
...@@ -516,68 +516,67 @@ beego中使用session相当方便,åªè¦åœ¨mainå…¥å£å‡½æ•°ä¸­è®¾ç½®å¦‚下: ...@@ -516,68 +516,67 @@ beego中使用session相当方便,åªè¦åœ¨mainå…¥å£å‡½æ•°ä¸­è®¾ç½®å¦‚下:
516 this.TplNames = "index.tpl" 516 this.TplNames = "index.tpl"
517 } 517 }
518 518
519 上面的例子中我们知道session有几个方便的方法: 519 We can see that there are few convenient methods:
520 520
521 - SetSession(name string, value interface{}) 521 - SetSession(name string, value interface{})
522 - GetSession(name string) interface{} 522 - GetSession(name string) interface{}
523 - DelSession(name string) 523 - DelSession(name string)
524 524
525 session操作主要有设置session、获取session、删除session 525 There are three kinds of operation for session: set, get, and delete.
526 526
527 当然你要可以通过下面的方式自己控制相应的逻辑这些逻辑: 527 Of course you can use following code to customized session logic:
528 528
529 sess:=this.StartSession() 529 sess:=this.StartSession()
530 defer sess.SessionRelease() 530 defer sess.SessionRelease()
531 531
532 sess对象具有如下方法: 532 The sess object has following methods:
533 533
534 * sess.Set() 534 * sess.Set()
535 * sess.Get() 535 * sess.Get()
536 * sess.Delete() 536 * sess.Delete()
537 * sess.SessionID() 537 * sess.SessionID()
538 538
539 但是我还是建议大家采用SetSession、GetSession、DelSession三个方法来操作,避免自己在操作的过程中资源没释放的问题。 539 However, I recommend you to use SetSession、GetSession、DelSession these three operations in order to prevent resource leak.
540 540
541 关于Session模块使用中的一些参数设置: 541 There are some arguments you can use in session module:
542 542
543 - SessionOn 543 - SessionOn
544 544
545 设置是否开启Session,默认是false,配置文件对应的参数名:sessionon 545 Whether enable session or not, default is false, corresponding arguments in configuration file: sessionon.
546 546
547 - SessionProvider 547 - SessionProvider
548 548
549 设置Session的引擎,默认是memory,目前支持还有file、mysql、redis等,配置文件对应的参数名:sessionprovider 549 Setting session engine, default is memory, other options are file, MySQL and redis, corresponding arguments in configuration file: sessionprovider.
550 550
551 - SessionName 551 - SessionName
552 552
553 设置cookies的名字,Session默认是保存在用户的浏览器cookies里面的,默认名是beegosessionID,配置文件对应的参数名是:sessionname 553 Setting name of cookies, it saves in users' browser with name beegosessionID, corresponding arguments in configuration file: sessionname.
554 554
555 - SessionGCMaxLifetime 555 - SessionGCMaxLifetime
556 556
557 设置Session过期的时间,默认值是3600秒,配置文件对应的参数:sessiongcmaxlifetime 557 Setting session expired time, default is 3600 seconds, corresponding arguments in configuration: sessiongcmaxlifetime
558 558
559 - SessionSavePath 559 - SessionSavePath
560 560
561 设置对应file、mysql、redis引擎的保存路径或者链接地址,默认值是空,配置文件对应的参数:sessionsavepath 561 Setting save path or link address of corresponding file, MySQL and redis engines, default is empty, corresponding arguments in configuration file: sessionsavepath
562 562
563 563 When the SessionProvider is file, SessionSavePath saves file path:
564 当SessionProvider为file时,SessionSavePath是只保存文件的目录,如下所示:
565 564
566 beego.SessionProvider = "file" 565 beego.SessionProvider = "file"
567 beego.SessionSavePath = "./tmp" 566 beego.SessionSavePath = "./tmp"
568 567
569 当SessionProvider为mysql时,SessionSavePath是链接地址,采用[go-sql-driver](https://github.com/go-sql-driver/mysql),如下所示: 568 When the SessionProvider is mysql, SessionSavePath is link address, it uses driver [go-sql-driver](https://github.com/go-sql-driver/mysql):
570 569
571 beego.SessionProvider = "mysql" 570 beego.SessionProvider = "mysql"
572 beego.SessionSavePath = "username:password@protocol(address)/dbname?param=value" 571 beego.SessionSavePath = "username:password@protocol(address)/dbname?param=value"
573 572
574 当SessionProvider为redis时,SessionSavePath是redis的链接地址,采用了[redigo](https://github.com/garyburd/redigo),如下所示: 573 When the SessionProvider is redis, SessionSavePath is link address of redis, it uses driver [redigo](https://github.com/garyburd/redigo):
575 574
576 beego.SessionProvider = "redis" 575 beego.SessionProvider = "redis"
577 beego.SessionSavePath = "127.0.0.1:6379" 576 beego.SessionSavePath = "127.0.0.1:6379"
578 577
579 ## Cache设置 578 ## Cache
580 beego内置了一个cache模块,实现了类似memcache的功能,缓存数据在内存中,主要的使用方法如下: 579 Beego has a built-in cache module, it's like memcache, which caches data in memory. Here is an example of using cache module in Beego:
581 580
582 var ( 581 var (
583 urllist *beego.BeeCache 582 urllist *beego.BeeCache
...@@ -585,7 +584,7 @@ beego内置了一个cache模å—,实现了类似memcache的功能,缓存数æ ...@@ -585,7 +584,7 @@ beego内置了一个cache模å—,实现了类似memcache的功能,缓存数æ
585 584
586 func init() { 585 func init() {
587 urllist = beego.NewBeeCache() 586 urllist = beego.NewBeeCache()
588 urllist.Every = 0 //不过期 587 urllist.Every = 0 // Not expired
589 urllist.Start() 588 urllist.Start()
590 } 589 }
591 590
...@@ -613,15 +612,15 @@ beego内置了一个cache模å—,实现了类似memcache的功能,缓存数æ ...@@ -613,15 +612,15 @@ beego内置了一个cache模å—,实现了类似memcache的功能,缓存数æ
613 this.ServeJson() 612 this.ServeJson()
614 } 613 }
615 614
616 上面这个例子演示了如何使用beego的Cache模块,主要是通过`beego.NewBeeCache`初始化一个对象,然后设置过期时间,开启过期检测,在业务逻辑中就可以通过如下的接口进行增删改的操作: 615 To use cache, you need to initialize a `beego.NewBeeCache` object and set expired time, and enable expired check. Then you can use following methods to achieve other operations:
617 616
618 - Get(name string) interface{} 617 - Get(name string) interface{}
619 - Put(name string, value interface{}, expired int) error 618 - Put(name string, value interface{}, expired int) error
620 - Delete(name string) (ok bool, err error) 619 - Delete(name string) (ok bool, err error)
621 - IsExist(name string) bool 620 - IsExist(name string) bool
622 621
623 ## 安全的Map 622 ##Safe map
624 我们知道在Go语言里面map是非线程安全的,详细的[atomic_maps](http://golang.org/doc/faq#atomic_maps)。但是我们在平常的业务中经常需要用到线程安全的map,特别是在goroutine的情况下,所以beego内置了一个简单的线程安全的map: 623 We know that map is not thread safe in Go, if you don't know it, this article may be helpful for you: [atomic_maps](http://golang.org/doc/faq#atomic_maps). However, we need a kind of thread safe map in practice, especially when we are using goroutines. Therefore, Beego provides a simple built-in thread safe map implementation.
625 624
626 bm := NewBeeMap() 625 bm := NewBeeMap()
627 if !bm.Set("astaxie", 1) { 626 if !bm.Set("astaxie", 1) {
...@@ -640,19 +639,19 @@ beego内置了一个cache模å—,实现了类似memcache的功能,缓存数æ ...@@ -640,19 +639,19 @@ beego内置了一个cache模å—,实现了类似memcache的功能,缓存数æ
640 t.Error("delete err") 639 t.Error("delete err")
641 } 640 }
642 641
643 上面演示了如何使用线程安全的Map,主要的接口有: 642 This map has following interfaces:
644 643
645 - Get(k interface{}) interface{} 644 - Get(k interface{}) interface{}
646 - Set(k interface{}, v interface{}) bool 645 - Set(k interface{}, v interface{}) bool
647 - Check(k interface{}) bool 646 - Check(k interface{}) bool
648 - Delete(k interface{}) 647 - Delete(k interface{})
649 648
650 ## 日志处理 649 ##Log
651 beego默认有一个初始化的BeeLogger对象输出内容到stdout中,你可以通过如下的方式设置自己的输出: 650 Beego has a default BeeLogger object that outputs log into stdout, and you can use your own logger as well:
652 651
653 beego.SetLogger(*log.Logger) 652 beego.SetLogger(*log.Logger)
654 653
655 只要你的输出符合`*log.Logger`就可以,例如输出到文件: 654 You can output everything that implemented `*log.Logger`, for example, write to file:
656 655
657 fd,err := os.OpenFile("/var/log/beeapp/beeapp.log", os.O_RDWR|os.O_APPEND, 0644) 656 fd,err := os.OpenFile("/var/log/beeapp/beeapp.log", os.O_RDWR|os.O_APPEND, 0644)
658 if err != nil { 657 if err != nil {
...@@ -661,7 +660,8 @@ beego默认有一个åˆå§‹åŒ–çš„BeeLogger对象输出内容到stdoutä¸­ï¼Œä½ å¯ ...@@ -661,7 +660,8 @@ beego默认有一个åˆå§‹åŒ–çš„BeeLogger对象输出内容到stdout中,你å¯
661 } 660 }
662 lg := log.New(fd, "", log.Ldate|log.Ltime) 661 lg := log.New(fd, "", log.Ldate|log.Ltime)
663 beego.SetLogger(lg) 662 beego.SetLogger(lg)
664 ### 不同级别的log日志函数 663
664 ###Different levels of log
665 665
666 * Trace(v ...interface{}) 666 * Trace(v ...interface{})
667 * Debug(v ...interface{}) 667 * Debug(v ...interface{})
...@@ -670,19 +670,19 @@ beego默认有一个åˆå§‹åŒ–çš„BeeLogger对象输出内容到stdoutä¸­ï¼Œä½ å¯ ...@@ -670,19 +670,19 @@ beego默认有一个åˆå§‹åŒ–çš„BeeLogger对象输出内容到stdout中,你å¯
670 * Error(v ...interface{}) 670 * Error(v ...interface{})
671 * Critical(v ...interface{}) 671 * Critical(v ...interface{})
672 672
673 你可以通过下面的方式设置不同的日志分级: 673 You can use following code to set log level:
674 674
675 beego.SetLevel(beego.LevelError) 675 beego.SetLevel(beego.LevelError)
676 676
677 当你代码中有很多日志输出之后,如果想上线,但是你不想输出Trace、Debug、Info等信息,那么你可以设置如下: 677 Your project may have a lot of log outputs, but you don't want to output everything after your application is running on the internet, for example, you want to ignore Trace, Debug and Info level log outputs, you can use following setting:
678 678
679 beego.SetLevel(beego.LevelWarning) 679 beego.SetLevel(beego.LevelWarning)
680 680
681 这样的话就不会输出小于这个level的日志,日志的排序如下: 681 Then Beego will not output log that has lower level of LevelWarning. Here is the list of all log levels, order from lower to higher:
682 682
683 LevelTrace、LevelDebug、LevelInfo、LevelWarning、 LevelError、LevelCritical 683 LevelTrace、LevelDebug、LevelInfo、LevelWarning、 LevelError、LevelCritical
684 684
685 用户可以根据不同的级别输出不同的错误信息,如下例子所示: 685 You can use different log level to output different error messages, it's based on how critical the error you think it is:
686 686
687 ### Examples of log messages 687 ### Examples of log messages
688 - Trace 688 - Trace
...@@ -776,10 +776,8 @@ LevelTraceã€LevelDebugã€LevelInfoã€LevelWarning〠LevelErrorã€LevelCritical ...@@ -776,10 +776,8 @@ LevelTraceã€LevelDebugã€LevelInfoã€LevelWarning〠LevelErrorã€LevelCritical
776 } 776 }
777 } 777 }
778 778
779 ## 配置管理 779 ##Configuration
780 beego支持解析ini文件, beego默认会解析当前应用下的`conf/app.conf`文件 780 Beego supports to parse .ini file in path `conf/app.conf`, and you have following options:
781
782 通过这个文件你可以初始化很多beego的默认参数
783 781
784 appname = beepkg 782 appname = beepkg
785 httpaddr = "127.0.0.1" 783 httpaddr = "127.0.0.1"
...@@ -789,23 +787,23 @@ beego支æŒè§£æžini文件, beego默认会解æžå½“å‰åº”用下的`conf/app.conf ...@@ -789,23 +787,23 @@ beego支æŒè§£æžini文件, beego默认会解æžå½“å‰åº”用下的`conf/app.conf
789 autorecover = false 787 autorecover = false
790 viewspath = "myview" 788 viewspath = "myview"
791 789
792 上面这些参数会替换beego默认的一些参数。 790 If you set value in configuration file, Beego uses it to replace default value.
793 791
794 你可以在配置文件中配置应用需要用的一些配置信息,例如下面所示的数据库信息: 792 You can also have other values for your application, for example, database connection information:
795 793
796 mysqluser = "root" 794 mysqluser = "root"
797 mysqlpass = "rootpass" 795 mysqlpass = "rootpass"
798 mysqlurls = "127.0.0.1" 796 mysqlurls = "127.0.0.1"
799 mysqldb = "beego" 797 mysqldb = "beego"
800 798
801 那么你就可以通过如下的方式获取设置的配置信息: 799 Then use following code to load your settings:
802 800
803 beego.AppConfig.String("mysqluser") 801 beego.AppConfig.String("mysqluser")
804 beego.AppConfig.String("mysqlpass") 802 beego.AppConfig.String("mysqlpass")
805 beego.AppConfig.String("mysqlurls") 803 beego.AppConfig.String("mysqlurls")
806 beego.AppConfig.String("mysqldb") 804 beego.AppConfig.String("mysqldb")
807 805
808 AppConfig支持如下方法 806 AppConfig supports following methods:
809 807
810 - Bool(key string) (bool, error) 808 - Bool(key string) (bool, error)
811 - Int(key string) (int, error) 809 - Int(key string) (int, error)
...@@ -813,91 +811,92 @@ AppConfig支æŒå¦‚下方法 ...@@ -813,91 +811,92 @@ AppConfig支æŒå¦‚下方法
813 - Float(key string) (float64, error) 811 - Float(key string) (float64, error)
814 - String(key string) string 812 - String(key string) string
815 813
816 ## 系统默认参数 814 ##Beego arguments
817 beego中带有很多可配置的参数,我们来一一认识一下它们,这样有利于我们在接下来的beego开发中可以充分的发挥他们的作用: 815 Beego has many configurable arguments, let me introduce to you all of them, so you can use them for more usage in your application:
818 816
819 * BeeApp 817 * BeeApp
820 818
821 beego默认启动的一个应用器入口,在应用import beego的时候,在init中已经初始化的。 819 Entry point of Beego, it initialized in init() function when you import Beego package.
822 820
823 * AppConfig 821 * AppConfig
824 822
825 beego的配置文件解析之后的对象,也是在init的时候初始化的,里面保存有解析`conf/app.conf`下面所有的参数数据 823 It stores values from file `conf/app.conf` and initialized in init() function.
826 824
827 * HttpAddr 825 * HttpAddr
828 826
829 应用监听地址,默认为空,监听所有的网卡IP 827 Application listening address, default is empty for listening all IP.
830 828
831 * HttpPort 829 * HttpPort
832 830
833 应用监听端口,默认为8080 831 Application listening port, default is 8080.
834 832
835 * AppName 833 * AppName
836 834
837 应用名称,默认是beego 835 Application name, default is "beego".
838 836
839 * RunMode 837 * RunMode
840 838
841 应用的模式,默认是dev,为开发模式,在开发模式下出错会提示友好的出错页面,如前面错误描述中所述。 839 Application mode, default is "dev" develop mode and gives friendly error messages.
842 840
843 * AutoRender 841 * AutoRender
844 842
845 是否模板自动渲染,默认值为true,对于API类型的应用,应用需要把该选项设置为false,不需要渲染模板。 843 This value indicates whether auto-render or not, default is true, you should set to false for API usage applications.
846 844
847 * RecoverPanic 845 * RecoverPanic
848 846
849 是否异常恢复,默认值为true,即当应用出现异常的情况,通过recover恢复回来,而不会导致应用异常退出。 847 This value indicates whether recover from panic or not, default is true, and program will not exit when error occurs.
850 848
851 * PprofOn 849 * PprofOn
852 850
853 是否启用pprof,默认是false,当开启之后,用户可以通过如下地址查看相应的goroutine执行情况 851 This value indicates whether enable pprof or not, default is false, and you can use following address to see goroutine execution status once you enable this feature.
854 852
855 /debug/pprof 853 /debug/pprof
856 /debug/pprof/cmdline 854 /debug/pprof/cmdline
857 /debug/pprof/profile 855 /debug/pprof/profile
858 /debug/pprof/symbol 856 /debug/pprof/symbol
859 关于pprof的信息,请参考官方的描述[pprof](http://golang.org/pkg/net/http/pprof/) 857
858 For more information about pprof, please read [pprof](http://golang.org/pkg/net/http/pprof/)
860 859
861 * ViewsPath 860 * ViewsPath
862 861
863 模板路径,默认值是views 862 Template path, default is "views".
864 863
865 * SessionOn 864 * SessionOn
866 865
867 session是否开启,默认是false 866 This value indicate whether enable session or not, default is false.
868 867
869 * SessionProvider 868 * SessionProvider
870 869
871 session的引擎,默认是memory 870 Session engine, default is memory.
872 871
873 * SessionName 872 * SessionName
874 873
875 存在客户端的cookie名称,默认值是beegosessionID 874 Name for cookie that save in client browser, default is "beegosessionID".
876 875
877 * SessionGCMaxLifetime 876 * SessionGCMaxLifetime
878 877
879 session过期时间,默认值是3600秒 878 Session expired time, default is 3600 seconds.
880 879
881 * SessionSavePath 880 * SessionSavePath
882 881
883 session保存路径,默认是空 882 Save path of session, default is empty.
884 883
885 * UseFcgi 884 * UseFcgi
886 885
887 是否启用fastcgi,默认是false 886 This value indicates whether enable fastcgi or not, default is false.
888 887
889 * MaxMemory 888 * MaxMemory
890 889
891 文件上传默认内存缓存大小,默认值是`1 << 26`(64M) 890 Maximum memory size for file upload, default is `1 << 26`(64M).
892 891
893 ## 第三方应用集成 892 ##Integrated third-party applications
894 beego支持第三方应用的集成,用户可以自定义`http.Handler`,用户可以通过如下方式进行注册路由: 893 Beego supports to integrate third-party application, you can customized `http.Handler` as follows:
895 894
896 beego.RouterHandler("/chat/:info(.*)", sockjshandler) 895 beego.RouterHandler("/chat/:info(.*)", sockjshandler)
897 896
898 sockjshandler实现了接口`http.Handler` 897 sockjshandler implemented interface `http.Handler`.
899 898
900 目前在beego的example中有支持sockjs的chat例子,示例代码如下: 899 Beego has an example for supporting chat of sockjs, here is the code:
901 900
902 package main 901 package main
903 902
...@@ -942,10 +941,10 @@ sockjshandler实现了接å£`http.Handler`。 ...@@ -942,10 +941,10 @@ sockjshandler实现了接å£`http.Handler`。
942 beego.Run() 941 beego.Run()
943 } 942 }
944 943
945 通过上面的代码很简单的实现了一个多人的聊天室。上面这个只是一个sockjs的例子,我想通过大家自定义`http.Handler`,可以有很多种方式来进行扩展beego应用。 944 The above example implemented a simple chat room for sockjs, and you can use `http.Handler` for more extensions.
946 945
947 ## 部署编译应用 946 ##Deployment
948 Go语言的应用最后编译之后是一个二进制文件,你只需要copy这个应用到服务器上,运行起来就行。beego由于带有几个静态文件、配置文件、模板文件三个目录,所以用户部署的时候需要同时copy这三个目录到相应的部署应用之下,下面以我实际的应用部署为例: 947 Go compiles program to binary file, you only need to copy this binary to your server and run it. Because Beego uses MVC model, so you may have folders for static files, configuration files and template files, so you have to copy those files as well. Here is a real example for deployment.
949 948
950 $ mkdir /opt/app/beepkg 949 $ mkdir /opt/app/beepkg
951 $ cp beepkg /opt/app/beepkg 950 $ cp beepkg /opt/app/beepkg
...@@ -953,7 +952,7 @@ Go语言的应用最åŽç¼–è¯‘ä¹‹åŽæ˜¯ä¸€ä¸ªäºŒè¿›åˆ¶æ–‡ä»¶ï¼Œä½ åªéœ€è¦copyè¿ ...@@ -953,7 +952,7 @@ Go语言的应用最åŽç¼–è¯‘ä¹‹åŽæ˜¯ä¸€ä¸ªäºŒè¿›åˆ¶æ–‡ä»¶ï¼Œä½ åªéœ€è¦copyè¿
953 $ cp -fr static /opt/app/beepkg 952 $ cp -fr static /opt/app/beepkg
954 $ cp -fr conf /opt/app/beepkg 953 $ cp -fr conf /opt/app/beepkg
955 954
956 这样在`/opt/app/beepkg`目录下面就会显示如下的目录结构: 955 Here is the directory structure pf `/opt/app/beepkg`.
957 956
958 . 957 .
959 ├── conf 958 ├── conf
...@@ -966,17 +965,15 @@ Go语言的应用最åŽç¼–è¯‘ä¹‹åŽæ˜¯ä¸€ä¸ªäºŒè¿›åˆ¶æ–‡ä»¶ï¼Œä½ åªéœ€è¦copyè¿ ...@@ -966,17 +965,15 @@ Go语言的应用最åŽç¼–è¯‘ä¹‹åŽæ˜¯ä¸€ä¸ªäºŒè¿›åˆ¶æ–‡ä»¶ï¼Œä½ åªéœ€è¦copyè¿
966 └── index.tpl 965 └── index.tpl
967 ├── beepkg 966 ├── beepkg
968 967
969 这样我们就已经把我们需要的应用搬到服务器了,那么接下来就可以开始部署了,我现在服务器端用两种方式来run, 968 Now you can run your application in server, here are two good ways to manage your applications, and I recommend the first one.
970 969
971 - Supervisord 970 - Supervisord
972 971
973 安装和配置见[Supervisord](Supervisord.md) 972 More information: [Supervisord](Supervisord.md)
974 973
975 - nohup方式 974 - nohup
976 975
977 nohup ./beepkg & 976 nohup ./beepkg &
978 977
979 个人比较推荐第一种方式,可以很好的管理起来应用
980
981 - [Introduction](README.md) 978 - [Introduction](README.md)
982 - [Step by step](Tutorial.md) 979 - [Step by step](Tutorial.md)
...\ No newline at end of file ...\ No newline at end of file
......
1 ##supervisord
2
3 1. Installation
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. Configure /etc/supervisord.conf
16
17 [include]
18 files = /etc/supervisord.conf.d/*.conf
19
20 3. Add new application
21
22 cd /etc/supervisord.conf.d
23 vim beepkg.conf
24
25 Configuration file:
26
27 [program:beepkg]
28 directory = /opt/app/beepkg
29 command = /opt/app/beepkg/beepkg
30 autostart = true
31 startsecs = 5
32 user = root
33 redirect_stderr = true
34 stdout_logfile = /var/log/supervisord/beepkg.log
...\ No newline at end of file ...\ No newline at end of file
1 # 一步一步跟我写博客
2
3 ## 创建项目
4
5 ## 数据库结构设计
6
7 ## 控制器设计
8
9 ## 模板设计
10
11 ## 用户登陆退出
12
13 ## 数据库操作
...\ 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!