format code

This commit is contained in:
Ming Deng 2020-12-14 12:22:44 +08:00
parent 181a5b6ef6
commit d4da82ef77
51 changed files with 174 additions and 183 deletions

View File

@ -4,8 +4,8 @@ beego is an open source project.
It is the work of hundreds of contributors. We appreciate your help! It is the work of hundreds of contributors. We appreciate your help!
Here are instructions to get you started. They are probably not perfect, Here are instructions to get you started. They are probably not perfect, please let us know if anything feels wrong or
please let us know if anything feels wrong or incomplete. incomplete.
## Prepare environment ## Prepare environment
@ -18,6 +18,7 @@ go get -u github.com/gordonklaus/ineffassign
``` ```
Put those lines into your pre-commit githook script: Put those lines into your pre-commit githook script:
```shell script ```shell script
goimports -w -format-only ./ goimports -w -format-only ./
@ -33,10 +34,13 @@ Beego uses many middlewares, including MySQL, Redis, SSDB and so on.
We provide docker compose file to start all middlewares. We provide docker compose file to start all middlewares.
You can run: You can run:
```shell script ```shell script
docker-compose -f scripts/test_docker_compose.yml up -d docker-compose -f scripts/test_docker_compose.yml up -d
``` ```
Unit tests read addresses from environment, here is an example: Unit tests read addresses from environment, here is an example:
```shell script ```shell script
export ORM_DRIVER=mysql export ORM_DRIVER=mysql
export ORM_SOURCE="beego:test@tcp(192.168.0.105:13306)/orm_test?charset=utf8" export ORM_SOURCE="beego:test@tcp(192.168.0.105:13306)/orm_test?charset=utf8"
@ -45,34 +49,28 @@ export REDIS_ADDR="192.168.0.105:6379"
export SSDB_ADDR="192.168.0.105:8888" export SSDB_ADDR="192.168.0.105:8888"
``` ```
## Contribution guidelines ## Contribution guidelines
### Pull requests ### Pull requests
First of all. beego follow the gitflow. So please send you pull request First of all. beego follow the gitflow. So please send you pull request to **develop-2** branch. We will close the pull
to **develop-2** branch. We will close the pull request to master branch. request to master branch.
We are always happy to receive pull requests, and do our best to We are always happy to receive pull requests, and do our best to review them as fast as possible. Not sure if that typo
review them as fast as possible. Not sure if that typo is worth a pull is worth a pull request? Do it! We will appreciate it.
request? Do it! We will appreciate it.
Don't forget to rebase your commits! Don't forget to rebase your commits!
If your pull request is not accepted on the first try, don't be If your pull request is not accepted on the first try, don't be discouraged! Sometimes we can make a mistake, please do
discouraged! Sometimes we can make a mistake, please do more explaining more explaining for us. We will appreciate it.
for us. We will appreciate it.
We're trying very hard to keep beego simple and fast. We don't want it We're trying very hard to keep beego simple and fast. We don't want it to do everything for everybody. This means that
to do everything for everybody. This means that we might decide against we might decide against incorporating a new feature. But we will give you some advice on how to do it in other way.
incorporating a new feature. But we will give you some advice on how to
do it in other way.
### Create issues ### Create issues
Any significant improvement should be documented as [a GitHub Any significant improvement should be documented as [a GitHub issue](https://github.com/beego/beego/v2/issues) before
issue](https://github.com/beego/beego/v2/issues) before anybody anybody starts working on it.
starts working on it.
Also when filing an issue, make sure to answer these five questions: Also when filing an issue, make sure to answer these five questions:
@ -84,10 +82,8 @@ Also when filing an issue, make sure to answer these five questions:
### but check existing issues and docs first! ### but check existing issues and docs first!
Please take a moment to check that an issue doesn't already exist Please take a moment to check that an issue doesn't already exist documenting your bug report or improvement proposal.
documenting your bug report or improvement proposal. If it does, it If it does, it never hurts to add a quick "+1" or "I have this problem too". This will help prioritize the most common
never hurts to add a quick "+1" or "I have this problem too". This will problems and requests.
help prioritize the most common problems and requests.
Also, if you don't know how to use it. please make sure you have read through Also, if you don't know how to use it. please make sure you have read through the docs in http://beego.me/docs
the docs in http://beego.me/docs

View File

@ -9,6 +9,7 @@ embedding.
![architecture](https://cdn.nlark.com/yuque/0/2020/png/755700/1607857489109-1e267fce-d65f-4c5e-b915-5c475df33c58.png) ![architecture](https://cdn.nlark.com/yuque/0/2020/png/755700/1607857489109-1e267fce-d65f-4c5e-b915-5c475df33c58.png)
Beego is compos of four parts: Beego is compos of four parts:
1. Base modules: including log module, config module, governor module; 1. Base modules: including log module, config module, governor module;
2. Task: is used for running timed tasks or periodic tasks; 2. Task: is used for running timed tasks or periodic tasks;
3. Client: including ORM module, httplib module, cache module; 3. Client: including ORM module, httplib module, cache module;
@ -18,11 +19,10 @@ Beego is compos of four parts:
[Officail website](http://beego.me) [Officail website](http://beego.me)
[Example](https://github.com/beego-dev/beego-example) [Example](https://github.com/beego/beego-example)
> If you could not open official website, go to [beedoc](https://github.com/beego/beedoc) > If you could not open official website, go to [beedoc](https://github.com/beego/beedoc)
### Web Application ### Web Application
![Http Request](https://cdn.nlark.com/yuque/0/2020/png/755700/1607857462507-855ec543-7ce3-402d-a0cb-b2524d5a4b60.png) ![Http Request](https://cdn.nlark.com/yuque/0/2020/png/755700/1607857462507-855ec543-7ce3-402d-a0cb-b2524d5a4b60.png)
@ -73,6 +73,7 @@ Congratulations! You've just built your first **beego** app.
* Full stack for Web & API * Full stack for Web & API
## Modules ## Modules
* [orm](https://github.com/beego/beedoc/tree/master/en-US/mvc/model) * [orm](https://github.com/beego/beedoc/tree/master/en-US/mvc/model)
* [session](https://github.com/beego/beedoc/blob/master/en-US/module/session.md) * [session](https://github.com/beego/beedoc/blob/master/en-US/module/session.md)
* [logs](https://github.com/beego/beedoc/blob/master/en-US/module/logs.md) * [logs](https://github.com/beego/beedoc/blob/master/en-US/module/logs.md)

View File

@ -19,10 +19,11 @@ import (
"net/http/httptest" "net/http/httptest"
"testing" "testing"
"github.com/casbin/casbin"
beego "github.com/beego/beego/v2/adapter" beego "github.com/beego/beego/v2/adapter"
"github.com/beego/beego/v2/adapter/context" "github.com/beego/beego/v2/adapter/context"
"github.com/beego/beego/v2/adapter/plugins/auth" "github.com/beego/beego/v2/adapter/plugins/auth"
"github.com/casbin/casbin"
) )
func testRequest(t *testing.T, handler *beego.ControllerRegister, user string, path string, method string, code int) { func testRequest(t *testing.T, handler *beego.ControllerRegister, user string, path string, method string, code int) {

View File

@ -1,17 +1,15 @@
## cache ## cache
cache is a Go cache manager. It can use many cache 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/beego/beego/v2/cache go get github.com/beego/beego/v2/cache
## What adapters are supported? ## What adapters are supported?
As of now this cache support memory, Memcache and Redis. As of now this cache support memory, Memcache and Redis.
## How to use it? ## How to use it?
First you must import it First you must import it
@ -31,7 +29,6 @@ Use it like this:
bm.IsExist("astaxie") bm.IsExist("astaxie")
bm.Delete("astaxie") bm.Delete("astaxie")
## Memory adapter ## Memory adapter
Configure memory adapter like this: Configure memory adapter like this:
@ -40,7 +37,6 @@ Configure memory adapter like this:
interval means the gc time. The cache will check at each time interval, whether item has expired. interval means the gc time. The cache will check at each time interval, whether item has expired.
## Memcache adapter ## Memcache adapter
Memcache adapter use the [gomemcache](http://github.com/bradfitz/gomemcache) client. Memcache adapter use the [gomemcache](http://github.com/bradfitz/gomemcache) client.
@ -49,7 +45,6 @@ Configure like this:
{"conn":"127.0.0.1:11211"} {"conn":"127.0.0.1:11211"}
## Redis adapter ## Redis adapter
Redis adapter use the [redigo](http://github.com/gomodule/redigo) client. Redis adapter use the [redigo](http://github.com/gomodule/redigo) client.

View File

@ -1,9 +1,11 @@
# httplib # httplib
httplib is an libs help you to curl remote url. httplib is an libs help you to curl remote url.
# How to use? # How to use?
## GET ## GET
you can use Get to crawl data. you can use Get to crawl data.
import "github.com/beego/beego/v2/httplib" import "github.com/beego/beego/v2/httplib"
@ -15,6 +17,7 @@ you can use Get to crawl data.
fmt.Println(str) fmt.Println(str)
## POST ## POST
POST data to remote url POST data to remote url
req := httplib.Post("http://beego.me/") req := httplib.Post("http://beego.me/")
@ -40,7 +43,6 @@ Example:
// POST // POST
httplib.Post("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second) httplib.Post("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second)
## Debug ## Debug
If you want to debug the request info, set the debug on If you want to debug the request info, set the debug on
@ -91,7 +93,6 @@ httplib support mutil file upload, use `req.PostFile()`
} }
fmt.Println(str) fmt.Println(str)
See godoc for further documentation and examples. See godoc for further documentation and examples.
* [godoc.org/github.com/beego/beego/v2/httplib](https://godoc.org/github.com/beego/beego/v2/httplib) * [godoc.org/github.com/beego/beego/v2/httplib](https://godoc.org/github.com/beego/beego/v2/httplib)

View File

@ -18,10 +18,11 @@ import (
"context" "context"
"net/http" "net/http"
"github.com/beego/beego/v2/client/httplib"
logKit "github.com/go-kit/kit/log" logKit "github.com/go-kit/kit/log"
opentracingKit "github.com/go-kit/kit/tracing/opentracing" opentracingKit "github.com/go-kit/kit/tracing/opentracing"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/beego/beego/v2/client/httplib"
) )
type FilterChainBuilder struct { type FilterChainBuilder struct {

View File

@ -1,17 +1,15 @@
## logs ## logs
logs is a Go logs manager. It can use many logs adapters. The repo is inspired by `database/sql` .
logs is a Go logs manager. It can use many logs adapters. The repo is inspired by `database/sql` .
## How to install? ## How to install?
go get github.com/beego/beego/v2/logs go get github.com/beego/beego/v2/logs
## What adapters are supported? ## What adapters are supported?
As of now this logs support console, file,smtp and conn. As of now this logs support console, file,smtp and conn.
## How to use it? ## How to use it?
First you must import it First you must import it

View File

@ -141,7 +141,6 @@ Struct Tag Functions:
Phone Phone
ZipCode ZipCode
## LICENSE ## LICENSE
BSD License http://creativecommons.org/licenses/BSD/ BSD License http://creativecommons.org/licenses/BSD/

View File

@ -17,11 +17,12 @@ package opentracing
import ( import (
"context" "context"
"github.com/beego/beego/v2/server/web"
beegoCtx "github.com/beego/beego/v2/server/web/context"
logKit "github.com/go-kit/kit/log" logKit "github.com/go-kit/kit/log"
opentracingKit "github.com/go-kit/kit/tracing/opentracing" opentracingKit "github.com/go-kit/kit/tracing/opentracing"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/beego/beego/v2/server/web"
beegoCtx "github.com/beego/beego/v2/server/web/context"
) )
// FilterChainBuilder provides an extension point that we can support more configurations if necessary // FilterChainBuilder provides an extension point that we can support more configurations if necessary

View File

@ -1,18 +1,17 @@
session session
============== ==============
session is a Go session manager. It can use many session 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/beego/beego/v2/session go get github.com/beego/beego/v2/session
## What providers are supported? ## What providers are supported?
As of now this session manager support memory, file, Redis and MySQL. As of now this session manager support memory, file, Redis and MySQL.
## How to use it? ## How to use it?
First you must import it First you must import it
@ -46,7 +45,8 @@ Then in you web app init the global session manager
go globalSessions.GC() 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): * 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() { func init() {
globalSessions, _ = session.NewManager( globalSessions, _ = session.NewManager(
@ -62,7 +62,6 @@ Then in you web app init the global session manager
go globalSessions.GC() go globalSessions.GC()
} }
Finally 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) { func login(w http.ResponseWriter, r *http.Request) {
@ -80,14 +79,13 @@ Finally in the handlerfunc you can use it like this
} }
} }
## How to write own provider? ## How to write own provider?
When you develop a web app, maybe you want to write own provider because you must meet the requirements. 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 Writing a provider is easy. You only need to define two struct types
(Session and Provider), which satisfy the interface definition. (Session and Provider), which satisfy the interface definition. Maybe you will find the **memory** provider is a good
Maybe you will find the **memory** provider is a good example. example.
type SessionStore interface { type SessionStore interface {
Set(key, value interface{}) error //set session value Set(key, value interface{}) error //set session value
@ -108,7 +106,6 @@ Maybe you will find the **memory** provider is a good example.
SessionGC() SessionGC()
} }
## LICENSE ## LICENSE
BSD License http://creativecommons.org/licenses/BSD/ BSD License http://creativecommons.org/licenses/BSD/

View File

@ -26,9 +26,10 @@ import (
"sync" "sync"
"time" "time"
"github.com/beego/beego/v2/core/logs"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/context" "github.com/beego/beego/v2/server/web/context"
) )