Merge pull request #4360 from flycash/develop

format code
This commit is contained in:
Ming Deng 2020-12-14 13:09:19 +08:00 committed by GitHub
commit f49c763025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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!
Here are instructions to get you started. They are probably not perfect,
please let us know if anything feels wrong or incomplete.
Here are instructions to get you started. They are probably not perfect, please let us know if anything feels wrong or
incomplete.
## Prepare environment
@ -18,6 +18,7 @@ go get -u github.com/gordonklaus/ineffassign
```
Put those lines into your pre-commit githook script:
```shell script
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.
You can run:
```shell script
docker-compose -f scripts/test_docker_compose.yml up -d
```
Unit tests read addresses from environment, here is an example:
```shell script
export ORM_DRIVER=mysql
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"
```
## Contribution guidelines
### Pull requests
First of all. beego follow the gitflow. So please send you pull request
to **develop-2** branch. We will close the pull request to master branch.
First of all. beego follow the gitflow. So please send you pull request to **develop-2** branch. We will close the pull
request to master branch.
We are always happy to receive pull requests, and do our best to
review them as fast as possible. Not sure if that typo is worth a pull
request? Do it! We will appreciate it.
We are always happy to receive pull requests, and do our best to review them as fast as possible. Not sure if that typo
is worth a pull request? Do it! We will appreciate it.
Don't forget to rebase your commits!
If your pull request is not accepted on the first try, don't be
discouraged! Sometimes we can make a mistake, please do more explaining
for us. We will appreciate it.
If your pull request is not accepted on the first try, don't be discouraged! Sometimes we can make a mistake, please do
more explaining for us. We will appreciate 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 we might decide against
incorporating a new feature. But we will give you some advice on how to
do it in other way.
We're trying very hard to keep beego simple and fast. We don't want it to do everything for everybody. This means that
we might decide against incorporating a new feature. But we will give you some advice on how to do it in other way.
### Create issues
Any significant improvement should be documented as [a GitHub
issue](https://github.com/beego/beego/v2/issues) before anybody
starts working on it.
Any significant improvement should be documented as [a GitHub issue](https://github.com/beego/beego/v2/issues) before
anybody starts working on it.
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!
Please take a moment to check that an issue doesn't already exist
documenting your bug report or improvement proposal. If it does, it
never hurts to add a quick "+1" or "I have this problem too". This will
help prioritize the most common problems and requests.
Please take a moment to check that an issue doesn't already exist documenting your bug report or improvement proposal.
If it does, it never hurts to add a quick "+1" or "I have this problem too". This will 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
the docs in http://beego.me/docs
Also, if you don't know how to use it. please make sure you have read through 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)
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;
@ -18,11 +19,10 @@ Beego is compos of four parts:
[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)
### Web Application
![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
## Modules
* [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)
* [logs](https://github.com/beego/beedoc/blob/master/en-US/module/logs.md)

View File

@ -19,10 +19,11 @@ import (
"net/http/httptest"
"testing"
"github.com/casbin/casbin"
beego "github.com/beego/beego/v2/adapter"
"github.com/beego/beego/v2/adapter/context"
"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) {

View File

@ -1,17 +1,15 @@
## 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?
go get github.com/beego/beego/v2/cache
## What adapters are supported?
As of now this cache support memory, Memcache and Redis.
## How to use it?
First you must import it
@ -31,7 +29,6 @@ Use it like this:
bm.IsExist("astaxie")
bm.Delete("astaxie")
## Memory adapter
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.
## Memcache adapter
Memcache adapter use the [gomemcache](http://github.com/bradfitz/gomemcache) client.
@ -49,7 +45,6 @@ Configure like this:
{"conn":"127.0.0.1:11211"}
## Redis adapter
Redis adapter use the [redigo](http://github.com/gomodule/redigo) client.

View File

@ -1,9 +1,11 @@
# httplib
httplib is an libs help you to curl remote url.
# How to use?
## GET
you can use Get to crawl data.
import "github.com/beego/beego/v2/httplib"
@ -15,6 +17,7 @@ you can use Get to crawl data.
fmt.Println(str)
## POST
POST data to remote url
req := httplib.Post("http://beego.me/")
@ -40,7 +43,6 @@ Example:
// POST
httplib.Post("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second)
## Debug
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)
See godoc for further documentation and examples.
* [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"
"net/http"
"github.com/beego/beego/v2/client/httplib"
logKit "github.com/go-kit/kit/log"
opentracingKit "github.com/go-kit/kit/tracing/opentracing"
"github.com/opentracing/opentracing-go"
"github.com/beego/beego/v2/client/httplib"
)
type FilterChainBuilder struct {

View File

@ -1,17 +1,15 @@
## 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?
go get github.com/beego/beego/v2/logs
## What adapters are supported?
As of now this logs support console, file,smtp and conn.
## How to use it?
First you must import it

View File

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

View File

@ -17,11 +17,12 @@ package opentracing
import (
"context"
"github.com/beego/beego/v2/server/web"
beegoCtx "github.com/beego/beego/v2/server/web/context"
logKit "github.com/go-kit/kit/log"
opentracingKit "github.com/go-kit/kit/tracing/opentracing"
"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

View File

@ -1,18 +1,17 @@
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?
go get github.com/beego/beego/v2/session
## What providers are supported?
As of now this session manager support memory, file, Redis and MySQL.
## How to use it?
First you must import it
@ -46,7 +45,8 @@ Then in you web app init the global session manager
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() {
globalSessions, _ = session.NewManager(
@ -62,7 +62,6 @@ Then in you web app init the global session manager
go globalSessions.GC()
}
Finally in the handlerfunc you can use it like this
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?
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 is a good example.
(Session and Provider), which satisfy the interface definition. Maybe you will find the **memory** provider is a good
example.
type SessionStore interface {
Set(key, value interface{}) error //set session value
@ -108,7 +106,6 @@ Maybe you will find the **memory** provider is a good example.
SessionGC()
}
## LICENSE
BSD License http://creativecommons.org/licenses/BSD/

View File

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