From b886ed59a551365cadf38268e57dab6c770778ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dobros=C5=82aw=20=C5=BBybort?= Date: Thu, 20 Jun 2013 14:37:26 +0300 Subject: [PATCH 1/4] Update cache docs --- cache/cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache/cache.go b/cache/cache.go index 0353a038..abef179e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -28,7 +28,7 @@ func Register(name string, adapter Cache) { adapters[name] = adapter } -//config is json {"interval":360} +// config need to be correct JSON as string: {"interval":360} func NewCache(adapterName, config string) (Cache, error) { adapter, ok := adapters[adapterName] if !ok { From b68a37a115447f4bc9313fe1f661268671356f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dobros=C5=82aw=20=C5=BBybort?= Date: Thu, 20 Jun 2013 13:58:35 +0200 Subject: [PATCH 2/4] Some updates to cache README --- cache/README.md | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/cache/README.md b/cache/README.md index 93868458..d4c80fad 100644 --- a/cache/README.md +++ b/cache/README.md @@ -1,52 +1,59 @@ ## cache -cache is a golang cache manager. It can use cache for many adapters. The repo is inspired by `database/sql` . +cache is a Go cache manager. It can use many cache adapters. The repo is inspired by `database/sql` . -##How to install + +## How to install? go get github.com/astaxie/beego/cache - -##how many adapter support -Now this cache support memory/redis/memcache - -## how to use it -first you must import it +## What adapters are supported? +As of now this cache support memory, Memcache and Redis. + + +## How to use it? + +First you must import it import ( "github.com/astaxie/beego/cache" ) -then init an Cache(memory adapter) +Then init a Cache (example with memory adapter) bm, err := NewCache("memory", `{"interval":60}`) -use it like this: +Use it like this: bm.Put("astaxie", 1, 10) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") - -## memory adapter -memory adapter config like this: + + +## Memory adapter + +Configure memory adapter like this: {"interval":60} -interval means the gc time. The cache will every interval time to check wheather have item expired. +interval means the gc time. The cache will check at each time interval, whether item has expired. -## memcache adapter -memory adapter use the vitess's [memcache](code.google.com/p/vitess/go/memcache) client. -the config like this: +## Memcache adapter + +memory adapter use the vitess's [Memcache](http://code.google.com/p/vitess/go/memcache) client. + +Configure like this: {"conn":"127.0.0.1:11211"} -## redis adapter -redis adapter use the [redigo](github.com/garyburd/redigo/redis) client. +## Redis adapter -the config like this: +Redis adapter use the [redigo](http://github.com/garyburd/redigo/redis) client. - {"conn":":6039"} \ No newline at end of file +Configure like this: + + {"conn":":6039"} From cc6c84b317e7c28d710017c0a1c9501d7dade117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dobros=C5=82aw=20=C5=BBybort?= Date: Thu, 20 Jun 2013 14:22:06 +0200 Subject: [PATCH 3/4] Update: session README --- session/README.md | 85 ++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/session/README.md b/session/README.md index f42c74b0..e5a366e3 100644 --- a/session/README.md +++ b/session/README.md @@ -1,60 +1,60 @@ -sessionmanager +session ============== -sessionmanager is a golang session manager. It can use session for many providers.Just like the `database/sql` and `database/sql/driver`. +session is a Go session manager. It can use many session providers. Just like the `database/sql` and `database/sql/driver`. -##How to install +## How to install? go get github.com/astaxie/beego/session -##how many providers support -Now this sessionmanager support memory/file/redis/mysql +## What providers are supported? + +As of now this session manager support memory, file, Redis and MySQL. +## How to use it? -##How do we use it? - -first you must import it - +First you must import it import ( "github.com/astaxie/beego/session" ) -then in you web app init the globalsession manager +Then in you web app init the global session manager var globalSessions *session.Manager -use memory as providers: +* Use **memory** as provider: - func init() { - globalSessions, _ = session.NewManager("memory", "gosessionid", 3600,"") - go globalSessions.GC() - } + func init() { + globalSessions, _ = session.NewManager("memory", "gosessionid", 3600,"") + go globalSessions.GC() + } -use mysql as providers,the last param is the DNS, learn more from [mysql](https://github.com/Go-SQL-Driver/MySQL#dsn-data-source-name): +* Use **MySQL** as provider, the last param is the DNS, learn more from [mysql](https://github.com/Go-SQL-Driver/MySQL#dsn-data-source-name): - func init() { - globalSessions, _ = session.NewManager("mysql", "gosessionid", 3600,"username:password@protocol(address)/dbname?param=value") - go globalSessions.GC() - } + func init() { + globalSessions, _ = session.NewManager( + "mysql", "gosessionid", 3600, "username:password@protocol(address)/dbname?param=value") + go globalSessions.GC() + } -use file as providers,the last param is the path where to store the file: +* Use **file** as provider, the last param is the path where you want file to be stored: - func init() { - globalSessions, _ = session.NewManager("file", "gosessionid", 3600,"./tmp") - go globalSessions.GC() - } + func init() { + globalSessions, _ = session.NewManager("file", "gosessionid", 3600, "./tmp") + go globalSessions.GC() + } -use redis as providers,the last param is the redis's conn address: +* Use **Redis** as provider, the last param is the Redis conn address: - func init() { - globalSessions, _ = session.NewManager("redis", "gosessionid", 3600,"127.0.0.1:6379") - go globalSessions.GC() - } + func init() { + globalSessions, _ = session.NewManager("redis", "gosessionid", 3600, "127.0.0.1:6379") + go globalSessions.GC() + } -at last in the handlerfunc you can use it like this +Finally in the handlerfunc you can use it like this func login(w http.ResponseWriter, r *http.Request) { sess := globalSessions.SessionStart(w, r) @@ -70,19 +70,21 @@ at last in the handlerfunc you can use it like this fmt.Println("password:", r.Form["password"]) } } - -##How to write own provider -When we develop a web app, maybe you want to write a provider because you must meet the requirements. +## How to write own provider? -Write a provider is so easy. You only define two struct type(Session and Provider),which satisfy the interface definition.Maybe The memory provider is a good example for you. +When you develop a web app, maybe you want to write own provider because you must meet the requirements. + +Writing a provider is easy. You only need to define two struct types +(Session and Provider), which satisfy the interface definition. +Maybe you will find the **memory** provider as good example. type SessionStore interface { - Set(key, value interface{}) error //set session value - Get(key interface{}) interface{} //get session value - Delete(key interface{}) error //delete session value - SessionID() string //back current sessionID + Set(key, value interface{}) error // set session value + Get(key interface{}) interface{} // get session value + Delete(key interface{}) error // delete session value + SessionID() string // return current sessionID SessionRelease() // release the resource } @@ -93,6 +95,7 @@ Write a provider is so easy. You only define two struct type(Session and Provide SessionGC() } -##LICENSE -BSD License http://creativecommons.org/licenses/BSD/ \ No newline at end of file +## LICENSE + +BSD License http://creativecommons.org/licenses/BSD/ From 43f588b5c1701f645e0ebe084942b39bdd0cb118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dobros=C5=82aw=20=C5=BBybort?= Date: Thu, 20 Jun 2013 15:25:39 +0300 Subject: [PATCH 4/4] Fix: session README --- session/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/session/README.md b/session/README.md index e5a366e3..226359de 100644 --- a/session/README.md +++ b/session/README.md @@ -32,14 +32,6 @@ Then in you web app init the global session manager go globalSessions.GC() } -* Use **MySQL** as provider, the last param is the DNS, learn more from [mysql](https://github.com/Go-SQL-Driver/MySQL#dsn-data-source-name): - - func init() { - globalSessions, _ = session.NewManager( - "mysql", "gosessionid", 3600, "username:password@protocol(address)/dbname?param=value") - go globalSessions.GC() - } - * Use **file** as provider, the last param is the path where you want file to be stored: func init() { @@ -53,6 +45,14 @@ Then in you web app init the global session manager globalSessions, _ = session.NewManager("redis", "gosessionid", 3600, "127.0.0.1:6379") go globalSessions.GC() } + +* Use **MySQL** as provider, the last param is the DSN, learn more from [mysql](https://github.com/Go-SQL-Driver/MySQL#dsn-data-source-name): + + func init() { + globalSessions, _ = session.NewManager( + "mysql", "gosessionid", 3600, "username:password@protocol(address)/dbname?param=value") + go globalSessions.GC() + } Finally in the handlerfunc you can use it like this