beego

package module
v2.0.2-sonek Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

Beego Build Status GoDoc Foundation Go Report Card

Beego is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services.

It is inspired by Tornado, Sinatra and Flask. beego has some Go-specific features such as interfaces and struct embedding.

architecture

Beego is compos of four parts:

  1. Base modules: including log module, config module, governor module;
  2. Task: is used for running timed tasks or periodic tasks;
  3. Client: including ORM module, httplib module, cache module;
  4. Server: including web module. We will support gRPC in the future;

Please use RELEASE version, or master branch which contains the latest bug fix

Quick Start

Official website

Example

If you could not open official website, go to beedoc

Web Application

Http Request

Create hello directory, cd hello directory
mkdir hello
cd hello
Init module
go mod init
Download and install
go get github.com/Sonek-HoangBui/beego/v2@v2.0.0
Create file hello.go
package main

import "github.com/Sonek-HoangBui/beego/v2/server/web"

func main() {
	web.Run()
}
Build and run
go build hello.go
./hello
Go to http://localhost:8080

Congratulations! You've just built your first beego app.

Features

Modules

Community

License

beego source code is licensed under the Apache Licence, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).

Documentation

Index

Constants

View Source
const (
	// VERSION represent beego web framework version.
	VERSION = "2.0.0"
)

Variables

View Source
var (
	BuildVersion     string
	BuildGitRevision string
	BuildStatus      string
	BuildTag         string
	BuildTime        string

	GoVersion string

	GitBranch string
)

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
used to keep compatible with v1.x
used to keep compatible with v1.x
cache
Package cache provide a Cache interface and some implement engine Usage: import( "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
Package cache provide a Cache interface and some implement engine Usage: import( "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
cache/memcache
Package memcache for cache provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/memcache" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
Package memcache for cache provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/memcache" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
cache/redis
Package redis for cache provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/redis" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
Package redis for cache provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/redis" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
config
Package config is used to parse config.
Package config is used to parse config.
config/env
Package env is used to parse environment.
Package env is used to parse environment.
config/xml
Package xml for config provider.
Package xml for config provider.
config/yaml
Package yaml for config provider depend on github.com/beego/goyaml2 go install github.com/beego/goyaml2 Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/core/config/yaml" "github.com/Sonek-HoangBui/beego/v2/core/config" ) cnf, err := config.NewConfig("yaml", "config.yaml") More docs http://beego.me/docs/module/config.md
Package yaml for config provider depend on github.com/beego/goyaml2 go install github.com/beego/goyaml2 Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/core/config/yaml" "github.com/Sonek-HoangBui/beego/v2/core/config" ) cnf, err := config.NewConfig("yaml", "config.yaml") More docs http://beego.me/docs/module/config.md
context
Package context provide the context utils Usage: import "github.com/Sonek-HoangBui/beego/v2/server/web/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
Package context provide the context utils Usage: import "github.com/Sonek-HoangBui/beego/v2/server/web/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
grace
Package grace use to hot reload Description: http://grisha.org/blog/2014/06/03/graceful-restart-in-golang/ Usage: import( "log" "net/http" "os" "github.com/Sonek-HoangBui/beego/v2/server/web/grace" ) func handler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("WORLD!")) } func main() { mux := http.NewServeMux() mux.HandleFunc("/hello", handler) err := grace.ListenAndServe("localhost:8080", mux) if err != nil { log.Println(err) } log.Println("Server on 8080 stopped") os.Exit(0) }
Package grace use to hot reload Description: http://grisha.org/blog/2014/06/03/graceful-restart-in-golang/ Usage: import( "log" "net/http" "os" "github.com/Sonek-HoangBui/beego/v2/server/web/grace" ) func handler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("WORLD!")) } func main() { mux := http.NewServeMux() mux.HandleFunc("/hello", handler) err := grace.ListenAndServe("localhost:8080", mux) if err != nil { log.Println(err) } log.Println("Server on 8080 stopped") os.Exit(0) }
httplib
Package httplib is used as http.Client Usage: import "github.com/Sonek-HoangBui/beego/v2/client/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
Package httplib is used as http.Client Usage: import "github.com/Sonek-HoangBui/beego/v2/client/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
logs
Package logs provide a general log interface Usage: import "github.com/Sonek-HoangBui/beego/v2/core/logs" log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel Use it like this: log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md
Package logs provide a general log interface Usage: import "github.com/Sonek-HoangBui/beego/v2/core/logs" log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel Use it like this: log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md
migration
Package migration enables you to generate migrations back and forth.
Package migration enables you to generate migrations back and forth.
orm
Package orm provide ORM for MySQL/PostgreSQL/sqlite Simple Usage package main import ( "fmt" "github.com/Sonek-HoangBui/beego/v2/client/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) // Model Struct type User struct { Id int `orm:"auto"` Name string `orm:"size(100)"` } func init() { orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) } func main() { o := orm.NewOrm() user := User{Name: "slene"} // insert id, err := o.Insert(&user) // update user.Name = "astaxie" num, err := o.Update(&user) // read one u := User{Id: user.Id} err = o.Read(&u) // delete num, err = o.Delete(&u) } more docs: http://beego.me/docs/mvc/model/overview.md
Package orm provide ORM for MySQL/PostgreSQL/sqlite Simple Usage package main import ( "fmt" "github.com/Sonek-HoangBui/beego/v2/client/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) // Model Struct type User struct { Id int `orm:"auto"` Name string `orm:"size(100)"` } func init() { orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) } func main() { o := orm.NewOrm() user := User{Name: "slene"} // insert id, err := o.Insert(&user) // update user.Name = "astaxie" num, err := o.Update(&user) // read one u := User{Id: user.Id} err = o.Read(&u) // delete num, err = o.Delete(&u) } more docs: http://beego.me/docs/mvc/model/overview.md
plugins/apiauth
Package apiauth provides handlers to enable apiauth support.
Package apiauth provides handlers to enable apiauth support.
plugins/auth
Package auth provides handlers to enable basic auth support.
Package auth provides handlers to enable basic auth support.
plugins/authz
Package authz provides handlers to enable ACL, RBAC, ABAC authorization support.
Package authz provides handlers to enable ACL, RBAC, ABAC authorization support.
plugins/cors
Package cors provides handlers to enable CORS support.
Package cors provides handlers to enable CORS support.
session
Package session provider Usage: import( "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package session provider Usage: import( "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
session/couchbase
Package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/couchbase" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/couchbase" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
session/ledis
Package ledis provide session Provider
Package ledis provide session Provider
session/memcache
Package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/memcache" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/memcache" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
session/mysql
Package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, `session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/mysql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, `session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/mysql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
session/postgres
Package postgres for session provider depends on github.com/lib/pq: go install github.com/lib/pq needs this table in your database: CREATE TABLE session ( session_key char(64) NOT NULL, session_data bytea, session_expiry timestamp NOT NULL, CONSTRAINT session_key PRIMARY KEY(session_key) ); will be activated with these settings in app.conf: SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/postgresql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package postgres for session provider depends on github.com/lib/pq: go install github.com/lib/pq needs this table in your database: CREATE TABLE session ( session_key char(64) NOT NULL, session_data bytea, session_expiry timestamp NOT NULL, CONSTRAINT session_key PRIMARY KEY(session_key) ); will be activated with these settings in app.conf: SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/postgresql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
session/redis
Package redis for session provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package redis for session provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
session/redis_cluster
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_cluster" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_cluster", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070;127.0.0.1:7071"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_cluster" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_cluster", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070;127.0.0.1:7071"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
session/redis_sentinel
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_sentinel" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_sentinel", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:26379;127.0.0.2:26379"}“) go globalSessions.GC() } more detail about params: please check the notes on the function SessionInit in this package
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_sentinel" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_sentinel", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:26379;127.0.0.2:26379"}“) go globalSessions.GC() } more detail about params: please check the notes on the function SessionInit in this package
swagger
Package swagger struct definition
Package swagger struct definition
toolbox
Package toolbox healthcheck type DatabaseCheck struct { } func (dc *DatabaseCheck) Check() error { if dc.isConnected() { return nil } else { return errors.New("can't connect database") } } AddHealthCheck("database",&DatabaseCheck{}) more docs: http://beego.me/docs/module/toolbox.md
Package toolbox healthcheck type DatabaseCheck struct { } func (dc *DatabaseCheck) Check() error { if dc.isConnected() { return nil } else { return errors.New("can't connect database") } } AddHealthCheck("database",&DatabaseCheck{}) more docs: http://beego.me/docs/module/toolbox.md
utils/captcha
Package captcha implements generation and verification of image CAPTCHAs.
Package captcha implements generation and verification of image CAPTCHAs.
utils/pagination
Package pagination provides utilities to setup a paginator within the context of a http request.
Package pagination provides utilities to setup a paginator within the context of a http request.
validation
Package validation for validations import ( "github.com/Sonek-HoangBui/beego/v2/core/validation" "log" ) 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() { // validation does not pass // print invalid message for _, err := range valid.Errors { log.Println(err.Key, err.Message) } } // or use like this if v := valid.Max(u.Age, 140, "ageMax"); !v.Ok { log.Println(v.Error.Key, v.Error.Message) } } more info: http://beego.me/docs/mvc/controller/validation.md
Package validation for validations import ( "github.com/Sonek-HoangBui/beego/v2/core/validation" "log" ) 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() { // validation does not pass // print invalid message for _, err := range valid.Errors { log.Println(err.Key, err.Message) } } // or use like this if v := valid.Max(u.Age, 140, "ageMax"); !v.Ok { log.Println(v.Error.Key, v.Error.Message) } } more info: http://beego.me/docs/mvc/controller/validation.md
client
cache
Package cache provide a Cache interface and some implement engine Usage: import( "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
Package cache provide a Cache interface and some implement engine Usage: import( "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
cache/memcache
Package memcache for cache provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/memcache" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
Package memcache for cache provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/memcache" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
cache/redis
Package redis for cache provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/redis" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
Package redis for cache provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/client/cache/redis" "github.com/Sonek-HoangBui/beego/v2/client/cache" ) bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
httplib
Package httplib is used as http.Client Usage: import "github.com/Sonek-HoangBui/beego/v2/client/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
Package httplib is used as http.Client Usage: import "github.com/Sonek-HoangBui/beego/v2/client/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
orm
Package orm provide ORM for MySQL/PostgreSQL/sqlite Simple Usage package main import ( "fmt" "github.com/Sonek-HoangBui/beego/v2/client/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) // Model Struct type User struct { Id int `orm:"auto"` Name string `orm:"size(100)"` } func init() { orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) } func main() { o := orm.NewOrm() user := User{Name: "slene"} // insert id, err := o.Insert(&user) // update user.Name = "astaxie" num, err := o.Update(&user) // read one u := User{Id: user.Id} err = o.Read(&u) // delete num, err = o.Delete(&u) } more docs: http://beego.me/docs/mvc/model/overview.md
Package orm provide ORM for MySQL/PostgreSQL/sqlite Simple Usage package main import ( "fmt" "github.com/Sonek-HoangBui/beego/v2/client/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) // Model Struct type User struct { Id int `orm:"auto"` Name string `orm:"size(100)"` } func init() { orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) } func main() { o := orm.NewOrm() user := User{Name: "slene"} // insert id, err := o.Insert(&user) // update user.Name = "astaxie" num, err := o.Update(&user) // read one u := User{Id: user.Id} err = o.Read(&u) // delete num, err = o.Delete(&u) } more docs: http://beego.me/docs/mvc/model/overview.md
orm/migration
Package migration enables you to generate migrations back and forth.
Package migration enables you to generate migrations back and forth.
core
admin
Package admin healthcheck type DatabaseCheck struct { } func (dc *DatabaseCheck) Check() error { if dc.isConnected() { return nil } else { return errors.New("can't connect database") } } AddHealthCheck("database",&DatabaseCheck{}) more docs: http://beego.me/docs/module/toolbox.md
Package admin healthcheck type DatabaseCheck struct { } func (dc *DatabaseCheck) Check() error { if dc.isConnected() { return nil } else { return errors.New("can't connect database") } } AddHealthCheck("database",&DatabaseCheck{}) more docs: http://beego.me/docs/module/toolbox.md
bean
bean is a basic package it should not depend on other modules except common module, log module and config module
bean is a basic package it should not depend on other modules except common module, log module and config module
config
Package config is used to parse config.
Package config is used to parse config.
config/env
Package env is used to parse environment.
Package env is used to parse environment.
config/xml
Package xml for config provider.
Package xml for config provider.
config/yaml
Package yaml for config provider depend on github.com/beego/goyaml2 go install github.com/beego/goyaml2 Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/core/config/yaml" "github.com/Sonek-HoangBui/beego/v2/core/config" ) cnf, err := config.NewConfig("yaml", "config.yaml") More docs http://beego.me/docs/module/config.md
Package yaml for config provider depend on github.com/beego/goyaml2 go install github.com/beego/goyaml2 Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/core/config/yaml" "github.com/Sonek-HoangBui/beego/v2/core/config" ) cnf, err := config.NewConfig("yaml", "config.yaml") More docs http://beego.me/docs/module/config.md
logs
Package logs provide a general log interface Usage: import "github.com/Sonek-HoangBui/beego/v2/core/logs" log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel Use it like this: log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md
Package logs provide a general log interface Usage: import "github.com/Sonek-HoangBui/beego/v2/core/logs" log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel Use it like this: log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md
logs/alils
Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr.
Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr.
utils/pagination
Package pagination provides utilities to setup a paginator within the context of a http request.
Package pagination provides utilities to setup a paginator within the context of a http request.
validation
Package validation for validations import ( "github.com/Sonek-HoangBui/beego/v2/core/validation" "log" ) 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() { // validation does not pass // print invalid message for _, err := range valid.Errors { log.Println(err.Key, err.Message) } } // or use like this if v := valid.Max(u.Age, 140, "ageMax"); !v.Ok { log.Println(v.Error.Key, v.Error.Message) } } more info: http://beego.me/docs/mvc/controller/validation.md
Package validation for validations import ( "github.com/Sonek-HoangBui/beego/v2/core/validation" "log" ) 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() { // validation does not pass // print invalid message for _, err := range valid.Errors { log.Println(err.Key, err.Message) } } // or use like this if v := valid.Max(u.Age, 140, "ageMax"); !v.Ok { log.Println(v.Error.Key, v.Error.Message) } } more info: http://beego.me/docs/mvc/controller/validation.md
server
web
Package beego provide a MVC framework beego: an open-source, high-performance, modular, full-stack web framework It is used for rapid development of RESTful APIs, web apps and backend services in Go.
Package beego provide a MVC framework beego: an open-source, high-performance, modular, full-stack web framework It is used for rapid development of RESTful APIs, web apps and backend services in Go.
web/captcha
Package captcha implements generation and verification of image CAPTCHAs.
Package captcha implements generation and verification of image CAPTCHAs.
web/context
Package context provide the context utils Usage: import "github.com/Sonek-HoangBui/beego/v2/server/web/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
Package context provide the context utils Usage: import "github.com/Sonek-HoangBui/beego/v2/server/web/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
web/filter/apiauth
Package apiauth provides handlers to enable apiauth support.
Package apiauth provides handlers to enable apiauth support.
web/filter/auth
Package auth provides handlers to enable basic auth support.
Package auth provides handlers to enable basic auth support.
web/filter/authz
Package authz provides handlers to enable ACL, RBAC, ABAC authorization support.
Package authz provides handlers to enable ACL, RBAC, ABAC authorization support.
web/filter/cors
Package cors provides handlers to enable CORS support.
Package cors provides handlers to enable CORS support.
web/grace
Package grace use to hot reload Description: http://grisha.org/blog/2014/06/03/graceful-restart-in-golang/ Usage: import( "log" "net/http" "os" "github.com/Sonek-HoangBui/beego/v2/server/web/grace" ) func handler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("WORLD!")) } func main() { mux := http.NewServeMux() mux.HandleFunc("/hello", handler) err := grace.ListenAndServe("localhost:8080", mux) if err != nil { log.Println(err) } log.Println("Server on 8080 stopped") os.Exit(0) }
Package grace use to hot reload Description: http://grisha.org/blog/2014/06/03/graceful-restart-in-golang/ Usage: import( "log" "net/http" "os" "github.com/Sonek-HoangBui/beego/v2/server/web/grace" ) func handler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("WORLD!")) } func main() { mux := http.NewServeMux() mux.HandleFunc("/hello", handler) err := grace.ListenAndServe("localhost:8080", mux) if err != nil { log.Println(err) } log.Println("Server on 8080 stopped") os.Exit(0) }
web/session
Package session provider Usage: import( "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package session provider Usage: import( "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
web/session/couchbase
Package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/couchbase" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/couchbase" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
web/session/ledis
Package ledis provide session Provider
Package ledis provide session Provider
web/session/memcache
Package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/memcache" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/memcache" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
web/session/mysql
Package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, `session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/mysql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, `session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/mysql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
web/session/postgres
Package postgres for session provider depends on github.com/lib/pq: go install github.com/lib/pq needs this table in your database: CREATE TABLE session ( session_key char(64) NOT NULL, session_data bytea, session_expiry timestamp NOT NULL, CONSTRAINT session_key PRIMARY KEY(session_key) ); will be activated with these settings in app.conf: SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/postgresql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package postgres for session provider depends on github.com/lib/pq: go install github.com/lib/pq needs this table in your database: CREATE TABLE session ( session_key char(64) NOT NULL, session_data bytea, session_expiry timestamp NOT NULL, CONSTRAINT session_key PRIMARY KEY(session_key) ); will be activated with these settings in app.conf: SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/postgresql" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
web/session/redis
Package redis for session provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package redis for session provider depend on github.com/gomodule/redigo/redis go install github.com/gomodule/redigo/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
web/session/redis_cluster
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_cluster" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_cluster", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070;127.0.0.1:7071"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_cluster" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_cluster", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070;127.0.0.1:7071"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
web/session/redis_sentinel
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_sentinel" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_sentinel", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:26379;127.0.0.2:26379"}“) go globalSessions.GC() } more detail about params: please check the notes on the function SessionInit in this package
Package redis for session provider depend on github.com/go-redis/redis go install github.com/go-redis/redis Usage: import( _ "github.com/Sonek-HoangBui/beego/v2/server/web/session/redis_sentinel" "github.com/Sonek-HoangBui/beego/v2/server/web/session" ) func init() { globalSessions, _ = session.NewManager("redis_sentinel", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:26379;127.0.0.2:26379"}“) go globalSessions.GC() } more detail about params: please check the notes on the function SessionInit in this package
web/swagger
Package swagger struct definition
Package swagger struct definition

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL