develop Easy to configure Loose coupling Well documented RESTFul router Namespace Testable Auto API documents beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 3 of 44 02/09/2014 12:21
Separation: Separate policy from mechanism; separate interfaces from engines Composition: Design programs to be connected to other programs The important rule less is more beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 4 of 44 02/09/2014 12:21
the very best of what we have seen in other web frameworks: Flask, Rails, Sinatra providing powerful tools fast, fast, fast beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 8 of 44 02/09/2014 12:21
`{"interval":60}`) err = c.Put("nums", 12, 0) if err != nil { log.Fatal("err") } v := c.Get("nums") log.Println(v) c.Incr("nums") v = c.Get("nums") log.Println(v) c.Decr("nums") v = c.Get("nums") log.Println(v) c.Delete("nums") if c.IsExist("nums") { log.Fatal("delete err") } } Run beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 12 of 44 02/09/2014 12:21
response. Input: get input data. Implemented many useful methods by Request Query,Cookie,Ip,Refer,Header,Session,IsWebsocket... Output: The encapsulation for Response Header,Body,Cookie,Json,Jsonp,Xml,Download... Usage: The Ctx encapsulated in Controller is *context.Context object type Some struct { beego.Controller } func (this *Some) Get() { name := this.Ctx.Input.Query("name") m := models.GetUser(name) this.Ctx.Output.Json(m) } beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 15 of 44 02/09/2014 12:21
smtp Different output writers:Console, File, SMTP, Conn High perfomence easy configuration and rapid deployment Automatic log filtering based on log levels on a per-output basis File logging with rotation (size, linecount, daily) Global variables and functions for easy usage in standalone apps beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 18 of 44 02/09/2014 12:21
"") log.EnableFuncCallDepth(true) // turn on the file & line log.Trace("trace %s %s", "param1", "param2") log.Debug("debug") log.Info("info") log.Warn("warning") log.Error("error") log.Critical("critical") time.Sleep(1 * 1e9) // why ? } Run beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 19 of 44 02/09/2014 12:21
and drivers MySQL:github.com/go-sql-driver/mysql PostgreSQL:github.com/lib/pq Sqlite3:github.com/mattn/go-sqlite3 Define model by struct: type User struct { Id int Name string `orm:"size(100)"` } beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 20 of 44 02/09/2014 12:21
Supporting all the Go's type Using simple CRUD style Auto creating tables. Auto Join association tables Crossing databse compatibility check Can use raw SQL for querying and mapping Fully coverd test cases to keep the ORM stable and robust beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 21 of 44 02/09/2014 12:21
Birthday time.Time Age int64 Name string CreatedAt time.Time `orm:"auto_now_add;type(datetime)"` UpdatedAt time.Time `orm:"auto_now;type(datetime)"` } func init() { orm.RegisterModel(new(User)) orm.RegisterDataBase("default", "mysql", "root:@/test?charset=utf8&loc=Asia%2FShanghai") } Run beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 22 of 44 02/09/2014 12:21
o := orm.NewOrm() user := new(User) user.Name = "astaxie" fmt.Println(o.Insert(user)) fmt.Println(user) user.Name = "asta" fmt.Println(o.Update(user)) fmt.Println(user) fmt.Println(o.Read(user)) fmt.Println(user) fmt.Println(o.Delete(user)) fmt.Println(user) } Run beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 23 of 44 02/09/2014 12:21
between different requests. you can use many session providers, including cookie, memory, file, redis, memcache, PostgreSQL, MySQL, and couchbase. initialize the seesion Manager: func init() { globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "gclifetime":3600, "cookieLifeTime": 3600}`) go globalSessions.GC() } After Session enabled: ss:= globalSessions.SessionStart(w, r) ss.GetSession(key) ss.SetSession(key, value) ss.Delete(key) ss.SessionID() beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 24 of 44 02/09/2014 12:21
using Go. type User struct { Name string Age int } func main() { u := User{"man", 40} valid := validation.Validation{} valid.Required(u.Name, "name") valid.MaxSize(u.Name, 15, "nameMax") valid.Range(u.Age, 0, 140, "age") if valid.HasErrors() { for _, err := range valid.Errors { log.Println(err.Key, err.Message) } } if v := valid.Max(u.Age, 140, "age"); !v.Ok { log.Println(v.Error.Key, v.Error.Message) } } Run beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 27 of 44 02/09/2014 12:21
string `valid:"Required;Match(/^(test)?\\w*@;com$/)"` Age int `valid:"Required;Range(1, 140)"` } func main() { valid := validation.Validation{} u := user{Name: "test", Age: 40} b, err := valid.Valid(u) if err != nil { // handle error } if !b { // validation does not pass // blabla... } } Run beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 28 of 44 02/09/2014 12:21
API AUTH. import( "github.com/astaxie/beego" "github.com/astaxie/beego/plugins/apiauth" ) func main(){ // apiauth every request beego.InsertFilter("*", beego.BeforeRouter,apiauth.APIBaiscAuth("appid","appkey")) beego.Run() } more documents: http://godoc.org/github.com/astaxie/beego/plugins/apiauth beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 31 of 44 02/09/2014 12:21
) func main(){ // authenticate every request beego.InsertFilter("*", beego.BeforeRouter,auth.Basic("username","secretpassword")) beego.Run() } more documents: http://godoc.org/github.com/astaxie/beego/plugins/auth beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 32 of 44 02/09/2014 12:21
main(){ beego_gorelic.InitNewrelicAgent() beego.Run() } more documents: https://github.com/yvasiyarov/beego_gorelic beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 34 of 44 02/09/2014 12:21
other modules: i18n social-auth beego compress beego admin beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 40 of 44 02/09/2014 12:21
(http://www.sitepoint.com/go-building- web-applications-beego-part-2/) Web Application Using Beego and Mgo www.goinggo.net/2013/12/sample-web-application-using-beego-and.html (http://www.goinggo.net /2013/12/sample-web-application-using-beego-and.html) Go Advent Day 5 - An introduction to beego blog.gopheracademy.com/day-05-beego (http://blog.gopheracademy.com/day-05-beego) QCon 2013 Build high performance API with Beego djt.qq.com/ppt/236 beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 41 of 44 02/09/2014 12:21
Store Server github.com/typecho-app-store/typecho-app-store (https://github.com/typecho-app-store/typecho-app-store) beego-mgo github.com/goinggo/beego-mgo (https://github.com/goinggo/beego-mgo) beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 43 of 44 02/09/2014 12:21
astaxie Head of Platform Engineering at Zalora http://github.com/astaxie (http://github.com/astaxie) http://twitter.com/astaxie (http://twitter.com/astaxie) http://sg.linkedin.com/pub/asta-xie/57/59/ba2/ (http://sg.linkedin.com/pub/asta-xie/57/59/ba2/) beego: A Go Framework for Combination http://10.1.32.252:3999/Go/beego.slide 44 of 44 02/09/2014 12:21