Merge branch 'develop' into develop
This commit is contained in:
commit
13508f2840
124
.github/workflows/test.yml
vendored
Normal file
124
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
name: Test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
paths:
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/test.yml"
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
paths:
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/test.yml"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
go-version: [1.14, 1.15, 1.16]
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
redis:
|
||||
image: redis:latest
|
||||
ports:
|
||||
- 6379:6379
|
||||
memcached:
|
||||
image: memcached:latest
|
||||
ports:
|
||||
- 11211:11211
|
||||
ssdb:
|
||||
image: wendal/ssdb:latest
|
||||
ports:
|
||||
- 8888:8888
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
env:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: orm_test
|
||||
ports:
|
||||
- 5432/tcp
|
||||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
||||
|
||||
steps:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run etcd
|
||||
env:
|
||||
ETCD_VERSION: v3.4.16
|
||||
run: |
|
||||
rm -rf /tmp/etcd-data.tmp
|
||||
mkdir -p /tmp/etcd-data.tmp
|
||||
docker rmi gcr.io/etcd-development/etcd:${ETCD_VERSION} || true && \
|
||||
docker run -d \
|
||||
-p 2379:2379 \
|
||||
-p 2380:2380 \
|
||||
--mount type=bind,source=/tmp/etcd-data.tmp,destination=/etcd-data \
|
||||
--name etcd-gcr-${ETCD_VERSION} \
|
||||
gcr.io/etcd-development/etcd:${ETCD_VERSION} \
|
||||
/usr/local/bin/etcd \
|
||||
--name s1 \
|
||||
--data-dir /etcd-data \
|
||||
--listen-client-urls http://0.0.0.0:2379 \
|
||||
--advertise-client-urls http://0.0.0.0:2379 \
|
||||
--listen-peer-urls http://0.0.0.0:2380 \
|
||||
--initial-advertise-peer-urls http://0.0.0.0:2380 \
|
||||
--initial-cluster s1=http://0.0.0.0:2380 \
|
||||
--initial-cluster-token tkn \
|
||||
--initial-cluster-state new
|
||||
docker exec etcd-gcr-${ETCD_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.float 1.23"
|
||||
docker exec etcd-gcr-${ETCD_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.bool true"
|
||||
docker exec etcd-gcr-${ETCD_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.int 11"
|
||||
docker exec etcd-gcr-${ETCD_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.string hello"
|
||||
docker exec etcd-gcr-${ETCD_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.serialize.name test"
|
||||
docker exec etcd-gcr-${ETCD_VERSION} /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put sub.sub.key1 sub.sub.key"
|
||||
|
||||
- name: Run ORM tests on sqlite3
|
||||
env:
|
||||
GOPATH: /home/runner/go
|
||||
ORM_DRIVER: sqlite3
|
||||
ORM_SOURCE: /tmp/sqlite3/orm_test.db
|
||||
run: |
|
||||
mkdir -p /tmp/sqlite3 && touch /tmp/sqlite3/orm_test.db
|
||||
go test -coverprofile=coverage_sqlite3.txt -covermode=atomic $(go list ./... | grep client/orm)
|
||||
|
||||
- name: Run ORM tests on postgres
|
||||
env:
|
||||
GOPATH: /home/runner/go
|
||||
ORM_DRIVER: postgres
|
||||
ORM_SOURCE: host=localhost port=${{ job.services.postgres.ports[5432] }} user=postgres password=postgres dbname=orm_test sslmode=disable
|
||||
run: |
|
||||
go test -coverprofile=coverage_postgres.txt -covermode=atomic $(go list ./... | grep client/orm)
|
||||
|
||||
- name: Run tests on mysql
|
||||
env:
|
||||
GOPATH: /home/runner/go
|
||||
ORM_DRIVER: mysql
|
||||
ORM_SOURCE: root:root@/orm_test?charset=utf8
|
||||
run: |
|
||||
sudo systemctl start mysql
|
||||
mysql -u root -proot -e 'create database orm_test;'
|
||||
go test -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
|
||||
- name: Upload codecov
|
||||
env:
|
||||
CODECOV_TOKEN: 4f4bc484-32a8-43b7-9f48-20966bd48ceb
|
||||
run: bash <(curl -s https://codecov.io/bash)
|
||||
77
.travis.yml
77
.travis.yml
@ -1,77 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- "1.14.x"
|
||||
- "1.15.x"
|
||||
- "1.16.x"
|
||||
services:
|
||||
- redis-server
|
||||
- mysql
|
||||
- postgresql
|
||||
- memcached
|
||||
- docker
|
||||
env:
|
||||
global:
|
||||
- GO_REPO_FULLNAME="github.com/beego/beego/v2"
|
||||
matrix:
|
||||
- ORM_DRIVER=sqlite3 ORM_SOURCE=$TRAVIS_BUILD_DIR/orm_test.db
|
||||
- ORM_DRIVER=postgres ORM_SOURCE="user=postgres dbname=orm_test sslmode=disable"
|
||||
- ORM_DRIVER=mysql export ORM_SOURCE="root:@/orm_test?charset=utf8"
|
||||
before_install:
|
||||
- export CODECOV_TOKEN="4f4bc484-32a8-43b7-9f48-20966bd48ceb"
|
||||
# link the local repo with ${GOPATH}/src/<namespace>/<repo>
|
||||
- GO_REPO_NAMESPACE=${GO_REPO_FULLNAME%/*}
|
||||
# relies on GOPATH to contain only one directory...
|
||||
- mkdir -p ${GOPATH}/src/${GO_REPO_NAMESPACE}
|
||||
- ln -sv ${TRAVIS_BUILD_DIR} ${GOPATH}/src/${GO_REPO_FULLNAME}
|
||||
- cd ${GOPATH}/src/${GO_REPO_FULLNAME}
|
||||
# get and build ssdb
|
||||
- git clone git://github.com/ideawu/ssdb.git
|
||||
- cd ssdb
|
||||
- make
|
||||
- cd ..
|
||||
# - prepare etcd
|
||||
# - prepare for etcd unit tests
|
||||
- rm -rf /tmp/etcd-data.tmp
|
||||
- mkdir -p /tmp/etcd-data.tmp
|
||||
- docker rmi gcr.io/etcd-development/etcd:v3.3.25 || true &&
|
||||
docker run -d
|
||||
-p 2379:2379
|
||||
-p 2380:2380
|
||||
--mount type=bind,source=/tmp/etcd-data.tmp,destination=/etcd-data
|
||||
--name etcd-gcr-v3.3.25
|
||||
gcr.io/etcd-development/etcd:v3.3.25
|
||||
/usr/local/bin/etcd
|
||||
--name s1
|
||||
--data-dir /etcd-data
|
||||
--listen-client-urls http://0.0.0.0:2379
|
||||
--advertise-client-urls http://0.0.0.0:2379
|
||||
--listen-peer-urls http://0.0.0.0:2380
|
||||
--initial-advertise-peer-urls http://0.0.0.0:2380
|
||||
--initial-cluster s1=http://0.0.0.0:2380
|
||||
--initial-cluster-token tkn
|
||||
--initial-cluster-state new
|
||||
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.float 1.23"
|
||||
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.bool true"
|
||||
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.int 11"
|
||||
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.string hello"
|
||||
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.serialize.name test"
|
||||
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put sub.sub.key1 sub.sub.key"
|
||||
before_script:
|
||||
- psql --version
|
||||
# - prepare for orm unit tests
|
||||
- sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi"
|
||||
- sh -c "if [ '$ORM_DRIVER' = 'mysql' ]; then mysql -u root -e 'create database orm_test;'; fi"
|
||||
- sh -c "if [ '$ORM_DRIVER' = 'sqlite' ]; then touch $TRAVIS_BUILD_DIR/orm_test.db; fi"
|
||||
- sh -c "go list ./... | grep -v vendor | xargs go vet -v"
|
||||
- mkdir -p res/var
|
||||
- ./ssdb/ssdb-server ./ssdb/ssdb.conf -d
|
||||
after_script:
|
||||
- killall -w ssdb-server
|
||||
- rm -rf ./res/var/*
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
script:
|
||||
- GO111MODULE=on go test -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
addons:
|
||||
postgresql: "9.6"
|
||||
18
CHANGELOG.md
18
CHANGELOG.md
@ -1,5 +1,7 @@
|
||||
# developing
|
||||
|
||||
- Add template functions eq,lt to support uint and int compare. [4607](https://github.com/beego/beego/pull/4607)
|
||||
- Migrate tests to GitHub Actions. [4663](https://github.com/beego/beego/issues/4663)
|
||||
- Add http client and option func. [4455](https://github.com/beego/beego/issues/4455)
|
||||
- Add: Convenient way to generate mock object [4620](https://github.com/beego/beego/issues/4620)
|
||||
- Infra: use dependabot to update dependencies. [4623](https://github.com/beego/beego/pull/4623)
|
||||
@ -59,3 +61,19 @@
|
||||
- [4474](https://github.com/beego/beego/pull/4474)
|
||||
- [4479](https://github.com/beego/beego/pull/4479)
|
||||
- [4639](https://github.com/beego/beego/pull/4639)
|
||||
|
||||
## Fix lint and format code
|
||||
|
||||
- [4644](https://github.com/beego/beego/pull/4644)
|
||||
- [4645](https://github.com/beego/beego/pull/4645)
|
||||
- [4646](https://github.com/beego/beego/pull/4646)
|
||||
- [4647](https://github.com/beego/beego/pull/4647)
|
||||
- [4648](https://github.com/beego/beego/pull/4648)
|
||||
- [4649](https://github.com/beego/beego/pull/4649)
|
||||
- [4651](https://github.com/beego/beego/pull/4651)
|
||||
- [4652](https://github.com/beego/beego/pull/4652)
|
||||
- [4653](https://github.com/beego/beego/pull/4653)
|
||||
- [4654](https://github.com/beego/beego/pull/4654)
|
||||
- [4655](https://github.com/beego/beego/pull/4655)
|
||||
- [4656](https://github.com/beego/beego/pull/4656)
|
||||
- [4660](https://github.com/beego/beego/pull/4660)
|
||||
|
||||
12
README.md
12
README.md
@ -1,14 +1,12 @@
|
||||
# Beego [](https://travis-ci.org/beego/beego) [](http://godoc.org/github.com/beego/beego) [](http://golangfoundation.org) [](https://goreportcard.com/report/github.com/beego/beego)
|
||||
# Beego [](https://github.com/beego/beego/actions/workflows/test.yml) [](https://goreportcard.com/report/github.com/beego/beego) [](https://pkg.go.dev/github.com/beego/beego/v2)
|
||||
|
||||
Beego is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend
|
||||
services.
|
||||
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.
|
||||
It is inspired by Tornado, Sinatra and Flask. beego has some Go-specific features such as interfaces and struct embedding.
|
||||
|
||||

|
||||
|
||||
Beego is compos of four parts:
|
||||
Beego is composed of four parts:
|
||||
|
||||
1. Base modules: including log module, config module, governor module;
|
||||
2. Task: is used for running timed tasks or periodic tasks;
|
||||
@ -97,4 +95,4 @@ Congratulations! You've just built your first **beego** app.
|
||||
## License
|
||||
|
||||
beego source code is licensed under the Apache Licence, Version 2.0
|
||||
(http://www.apache.org/licenses/LICENSE-2.0.html).
|
||||
([https://www.apache.org/licenses/LICENSE-2.0.html](https://www.apache.org/licenses/LICENSE-2.0.html)).
|
||||
|
||||
@ -22,10 +22,8 @@ import (
|
||||
"github.com/beego/beego/v2/server/web/context"
|
||||
)
|
||||
|
||||
var (
|
||||
// BeeApp is an application instance
|
||||
BeeApp *App
|
||||
)
|
||||
// BeeApp is an application instance
|
||||
var BeeApp *App
|
||||
|
||||
func init() {
|
||||
// create beego application
|
||||
|
||||
@ -36,10 +36,6 @@ type M web.M
|
||||
// Hook function to run
|
||||
type hookfunc func() error
|
||||
|
||||
var (
|
||||
hooks = make([]hookfunc, 0) // hook function slice to store the hookfunc
|
||||
)
|
||||
|
||||
// AddAPPStartHook is used to register the hookfunc
|
||||
// The hookfuncs will run in beego.Run()
|
||||
// such as initiating session , starting middleware , building template, starting admin control and so on.
|
||||
|
||||
28
adapter/cache/conv_test.go
vendored
28
adapter/cache/conv_test.go
vendored
@ -19,15 +19,15 @@ import (
|
||||
)
|
||||
|
||||
func TestGetString(t *testing.T) {
|
||||
var t1 = "test1"
|
||||
t1 := "test1"
|
||||
if "test1" != GetString(t1) {
|
||||
t.Error("get string from string error")
|
||||
}
|
||||
var t2 = []byte("test2")
|
||||
t2 := []byte("test2")
|
||||
if "test2" != GetString(t2) {
|
||||
t.Error("get string from byte array error")
|
||||
}
|
||||
var t3 = 1
|
||||
t3 := 1
|
||||
if "1" != GetString(t3) {
|
||||
t.Error("get string from int error")
|
||||
}
|
||||
@ -35,7 +35,7 @@ func TestGetString(t *testing.T) {
|
||||
if "1" != GetString(t4) {
|
||||
t.Error("get string from int64 error")
|
||||
}
|
||||
var t5 = 1.1
|
||||
t5 := 1.1
|
||||
if "1.1" != GetString(t5) {
|
||||
t.Error("get string from float64 error")
|
||||
}
|
||||
@ -46,7 +46,7 @@ func TestGetString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetInt(t *testing.T) {
|
||||
var t1 = 1
|
||||
t1 := 1
|
||||
if 1 != GetInt(t1) {
|
||||
t.Error("get int from int error")
|
||||
}
|
||||
@ -58,7 +58,7 @@ func TestGetInt(t *testing.T) {
|
||||
if 64 != GetInt(t3) {
|
||||
t.Error("get int from int64 error")
|
||||
}
|
||||
var t4 = "128"
|
||||
t4 := "128"
|
||||
if 128 != GetInt(t4) {
|
||||
t.Error("get int from num string error")
|
||||
}
|
||||
@ -69,7 +69,7 @@ func TestGetInt(t *testing.T) {
|
||||
|
||||
func TestGetInt64(t *testing.T) {
|
||||
var i int64 = 1
|
||||
var t1 = 1
|
||||
t1 := 1
|
||||
if i != GetInt64(t1) {
|
||||
t.Error("get int64 from int error")
|
||||
}
|
||||
@ -81,7 +81,7 @@ func TestGetInt64(t *testing.T) {
|
||||
if i != GetInt64(t3) {
|
||||
t.Error("get int64 from int64 error")
|
||||
}
|
||||
var t4 = "1"
|
||||
t4 := "1"
|
||||
if i != GetInt64(t4) {
|
||||
t.Error("get int64 from num string error")
|
||||
}
|
||||
@ -91,22 +91,22 @@ func TestGetInt64(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFloat64(t *testing.T) {
|
||||
var f = 1.11
|
||||
f := 1.11
|
||||
var t1 float32 = 1.11
|
||||
if f != GetFloat64(t1) {
|
||||
t.Error("get float64 from float32 error")
|
||||
}
|
||||
var t2 = 1.11
|
||||
t2 := 1.11
|
||||
if f != GetFloat64(t2) {
|
||||
t.Error("get float64 from float64 error")
|
||||
}
|
||||
var t3 = "1.11"
|
||||
t3 := "1.11"
|
||||
if f != GetFloat64(t3) {
|
||||
t.Error("get float64 from string error")
|
||||
}
|
||||
|
||||
var f2 float64 = 1
|
||||
var t4 = 1
|
||||
t4 := 1
|
||||
if f2 != GetFloat64(t4) {
|
||||
t.Error("get float64 from int error")
|
||||
}
|
||||
@ -117,11 +117,11 @@ func TestGetFloat64(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetBool(t *testing.T) {
|
||||
var t1 = true
|
||||
t1 := true
|
||||
if !GetBool(t1) {
|
||||
t.Error("get bool from bool error")
|
||||
}
|
||||
var t2 = "true"
|
||||
t2 := "true"
|
||||
if !GetBool(t2) {
|
||||
t.Error("get bool from string error")
|
||||
}
|
||||
|
||||
6
adapter/cache/redis/redis.go
vendored
6
adapter/cache/redis/redis.go
vendored
@ -34,10 +34,8 @@ import (
|
||||
redis2 "github.com/beego/beego/v2/client/cache/redis"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultKey the collection name of redis for cache adapter.
|
||||
DefaultKey = "beecacheRedis"
|
||||
)
|
||||
// DefaultKey the collection name of redis for cache adapter.
|
||||
var DefaultKey = "beecacheRedis"
|
||||
|
||||
// NewRedisCache create new redis cache with default collection name.
|
||||
func NewRedisCache() cache.Cache {
|
||||
|
||||
@ -20,7 +20,6 @@ import (
|
||||
)
|
||||
|
||||
func TestExpandValueEnv(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
item string
|
||||
want string
|
||||
@ -51,5 +50,4 @@ func TestExpandValueEnv(t *testing.T) {
|
||||
t.Errorf("expand value error, item %q want %q, got %q", c.item, c.want, got)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
func TestIni(t *testing.T) {
|
||||
|
||||
var (
|
||||
inicontext = `
|
||||
;comment one
|
||||
@ -129,11 +128,9 @@ password = ${GOPATH}
|
||||
if iniconf.String("name") != "astaxie" {
|
||||
t.Fatal("get name error")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIniSave(t *testing.T) {
|
||||
|
||||
const (
|
||||
inicontext = `
|
||||
app = app
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
func TestJsonStartsWithArray(t *testing.T) {
|
||||
|
||||
const jsoncontextwitharray = `[
|
||||
{
|
||||
"url": "user",
|
||||
@ -71,7 +70,6 @@ func TestJsonStartsWithArray(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJson(t *testing.T) {
|
||||
|
||||
var (
|
||||
jsoncontext = `{
|
||||
"appname": "beeapi",
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
func TestXML(t *testing.T) {
|
||||
|
||||
var (
|
||||
// xml parse should incluce in <config></config> tags
|
||||
xmlcontext = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
func TestYaml(t *testing.T) {
|
||||
|
||||
var (
|
||||
yamlcontext = `
|
||||
"appname": beeapi
|
||||
@ -112,5 +111,4 @@ func TestYaml(t *testing.T) {
|
||||
if yamlconf.String("name") != "astaxie" {
|
||||
t.Fatal("get name error")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,7 +25,6 @@ import (
|
||||
|
||||
// Demo is used to test, it's empty
|
||||
func Demo(i int) {
|
||||
|
||||
}
|
||||
|
||||
func TestConvertParams(t *testing.T) {
|
||||
|
||||
@ -48,9 +48,11 @@ type ControllerCommentsSlice web.ControllerCommentsSlice
|
||||
func (p ControllerCommentsSlice) Len() int {
|
||||
return (web.ControllerCommentsSlice)(p).Len()
|
||||
}
|
||||
|
||||
func (p ControllerCommentsSlice) Less(i, j int) bool {
|
||||
return (web.ControllerCommentsSlice)(p).Less(i, j)
|
||||
}
|
||||
|
||||
func (p ControllerCommentsSlice) Swap(i, j int) {
|
||||
(web.ControllerCommentsSlice)(p).Swap(i, j)
|
||||
}
|
||||
|
||||
@ -26,11 +26,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const getUrl = "http://httpbin.org/get"
|
||||
const ipUrl = "http://httpbin.org/ip"
|
||||
const (
|
||||
getURL = "http://httpbin.org/get"
|
||||
ipURL = "http://httpbin.org/ip"
|
||||
)
|
||||
|
||||
func TestResponse(t *testing.T) {
|
||||
req := Get(getUrl)
|
||||
req := Get(getURL)
|
||||
resp, err := req.Response()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -63,12 +65,10 @@ func TestDoRequest(t *testing.T) {
|
||||
if elapsedTime < delayedTime {
|
||||
t.Errorf("Not enough retries. Took %dms. Delay was meant to take %dms", elapsedTime, delayedTime)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
|
||||
req := Get(getUrl)
|
||||
req := Get(getURL)
|
||||
b, err := req.Bytes()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -210,7 +210,7 @@ func TestWithSetting(t *testing.T) {
|
||||
setting.ReadWriteTimeout = 5 * time.Second
|
||||
SetDefaultSetting(setting)
|
||||
|
||||
str, err := Get(getUrl).String()
|
||||
str, err := Get(getURL).String()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -223,8 +223,7 @@ func TestWithSetting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestToJson(t *testing.T) {
|
||||
|
||||
req := Get(ipUrl)
|
||||
req := Get(ipURL)
|
||||
resp, err := req.Response()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -250,12 +249,11 @@ func TestToJson(t *testing.T) {
|
||||
t.Fatal("response is not valid ip")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestToFile(t *testing.T) {
|
||||
f := "beego_testfile"
|
||||
req := Get(ipUrl)
|
||||
req := Get(ipURL)
|
||||
err := req.ToFile(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -269,7 +267,7 @@ func TestToFile(t *testing.T) {
|
||||
|
||||
func TestToFileDir(t *testing.T) {
|
||||
f := "./files/beego_testfile"
|
||||
req := Get(ipUrl)
|
||||
req := Get(ipURL)
|
||||
err := req.ToFile(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@ -18,7 +18,5 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMissPK missing pk error
|
||||
ErrMissPK = orm.ErrMissPK
|
||||
)
|
||||
// ErrMissPK missing pk error
|
||||
var ErrMissPK = orm.ErrMissPK
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
// Copyright 2020
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package orm
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
type baseQuerySetter struct {
|
||||
}
|
||||
|
||||
const shouldNotInvoke = "you should not invoke this method."
|
||||
|
||||
func (b *baseQuerySetter) ForceIndex(indexes ...string) orm.QuerySeter {
|
||||
panic(shouldNotInvoke)
|
||||
}
|
||||
|
||||
func (b *baseQuerySetter) UseIndex(indexes ...string) orm.QuerySeter {
|
||||
panic(shouldNotInvoke)
|
||||
}
|
||||
|
||||
func (b *baseQuerySetter) IgnoreIndex(indexes ...string) orm.QuerySeter {
|
||||
panic(shouldNotInvoke)
|
||||
}
|
||||
@ -72,5 +72,4 @@ func TestRedisSentinel(t *testing.T) {
|
||||
assert.Nil(t, password)
|
||||
|
||||
sess.SessionRelease(w)
|
||||
|
||||
}
|
||||
|
||||
@ -22,14 +22,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const sid = "Session_id"
|
||||
const sidNew = "Session_id_new"
|
||||
const sessionPath = "./_session_runtime"
|
||||
|
||||
var (
|
||||
mutex sync.Mutex
|
||||
const (
|
||||
sid = "Session_id"
|
||||
sidNew = "Session_id_new"
|
||||
sessionPath = "./_session_runtime"
|
||||
)
|
||||
|
||||
var mutex sync.Mutex
|
||||
|
||||
func TestFileProviderSessionExist(t *testing.T) {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
@ -118,7 +118,6 @@ func AssetsJs(text string) template.HTML {
|
||||
|
||||
// AssetsCSS returns stylesheet link tag with src string.
|
||||
func AssetsCSS(text string) template.HTML {
|
||||
|
||||
text = "<link href=\"" + text + "\" rel=\"stylesheet\" />"
|
||||
|
||||
return template.HTML(text)
|
||||
|
||||
@ -79,7 +79,6 @@ func TestHtmlunquote(t *testing.T) {
|
||||
h := `<' ”“&">`
|
||||
s := `<' ”“&">`
|
||||
assert.Equal(t, s, Htmlunquote(h))
|
||||
|
||||
}
|
||||
|
||||
func TestParseForm(t *testing.T) {
|
||||
@ -234,5 +233,4 @@ func TestMapGet(t *testing.T) {
|
||||
res, err = MapGet(m5, 5, 4, 3, 2, 1)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, res)
|
||||
|
||||
}
|
||||
|
||||
@ -14,12 +14,7 @@
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/httplib/testing"
|
||||
)
|
||||
|
||||
var port = ""
|
||||
var baseURL = "http://localhost:"
|
||||
import "github.com/beego/beego/v2/client/httplib/testing"
|
||||
|
||||
// TestHTTPRequest beego test request client
|
||||
type TestHTTPRequest testing.TestHTTPRequest
|
||||
|
||||
@ -16,19 +16,10 @@ package toolbox
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/core/admin"
|
||||
)
|
||||
|
||||
var startTime = time.Now()
|
||||
var pid int
|
||||
|
||||
func init() {
|
||||
pid = os.Getpid()
|
||||
}
|
||||
|
||||
// ProcessInput parse input command string
|
||||
func ProcessInput(input string, w io.Writer) {
|
||||
admin.ProcessInput(input, w)
|
||||
|
||||
@ -80,7 +80,6 @@ type Task struct {
|
||||
|
||||
// NewTask add new task with name, time and func
|
||||
func NewTask(tname string, spec string, f TaskFunc) *Task {
|
||||
|
||||
task := task.NewTask(tname, spec, func(ctx context.Context) error {
|
||||
return f()
|
||||
})
|
||||
@ -98,7 +97,6 @@ func (t *Task) GetSpec() string {
|
||||
|
||||
// GetStatus get current task status
|
||||
func (t *Task) GetStatus() string {
|
||||
|
||||
t.initDelegate()
|
||||
|
||||
return t.delegate.GetStatus(context.Background())
|
||||
@ -222,7 +220,6 @@ type MapSorter task.MapSorter
|
||||
|
||||
// NewMapSorter create new tasker map
|
||||
func NewMapSorter(m map[string]Tasker) *MapSorter {
|
||||
|
||||
newTaskerMap := make(map[string]task.Tasker, len(m))
|
||||
|
||||
for key, value := range m {
|
||||
@ -249,6 +246,7 @@ func (ms *MapSorter) Less(i, j int) bool {
|
||||
}
|
||||
return ms.Vals[i].GetNext(context.Background()).Before(ms.Vals[j].GetNext(context.Background()))
|
||||
}
|
||||
|
||||
func (ms *MapSorter) Swap(i, j int) {
|
||||
ms.Vals[i], ms.Vals[j] = ms.Vals[j], ms.Vals[i]
|
||||
ms.Keys[i], ms.Keys[j] = ms.Keys[j], ms.Keys[i]
|
||||
|
||||
@ -69,9 +69,7 @@ import (
|
||||
beecontext "github.com/beego/beego/v2/server/web/context"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultChars = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
)
|
||||
var defaultChars = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
|
||||
const (
|
||||
// default captcha attributes
|
||||
|
||||
@ -28,8 +28,8 @@ func TestPrint(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrintPoint(t *testing.T) {
|
||||
var v1 = new(mytype)
|
||||
var v2 = new(mytype)
|
||||
v1 := new(mytype)
|
||||
v2 := new(mytype)
|
||||
|
||||
v1.prev = nil
|
||||
v1.next = v2
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
)
|
||||
|
||||
type reducetype func(interface{}) interface{}
|
||||
|
||||
type filtertype func(interface{}) bool
|
||||
|
||||
// InSlice checks given string in string slice or not.
|
||||
|
||||
@ -27,9 +27,7 @@ const (
|
||||
LabelTag = validation.LabelTag
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInt64On32 = validation.ErrInt64On32
|
||||
)
|
||||
var ErrInt64On32 = validation.ErrInt64On32
|
||||
|
||||
// CustomFunc is for custom validate function
|
||||
type CustomFunc func(v *Validation, obj interface{}, key string)
|
||||
|
||||
@ -50,7 +50,6 @@ func TestMin(t *testing.T) {
|
||||
|
||||
assert.False(t, valid.Min(-1, 0, "min0").Ok)
|
||||
assert.True(t, valid.Min(1, 0, "min0").Ok)
|
||||
|
||||
}
|
||||
|
||||
func TestMax(t *testing.T) {
|
||||
@ -502,5 +501,4 @@ func TestCanSkipAlso(t *testing.T) {
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, b)
|
||||
|
||||
}
|
||||
|
||||
28
client/cache/conv_test.go
vendored
28
client/cache/conv_test.go
vendored
@ -21,29 +21,29 @@ import (
|
||||
)
|
||||
|
||||
func TestGetString(t *testing.T) {
|
||||
var t1 = "test1"
|
||||
t1 := "test1"
|
||||
|
||||
assert.Equal(t, "test1", GetString(t1))
|
||||
var t2 = []byte("test2")
|
||||
t2 := []byte("test2")
|
||||
assert.Equal(t, "test2", GetString(t2))
|
||||
var t3 = 1
|
||||
t3 := 1
|
||||
assert.Equal(t, "1", GetString(t3))
|
||||
var t4 int64 = 1
|
||||
assert.Equal(t, "1", GetString(t4))
|
||||
var t5 = 1.1
|
||||
t5 := 1.1
|
||||
assert.Equal(t, "1.1", GetString(t5))
|
||||
assert.Equal(t, "", GetString(nil))
|
||||
}
|
||||
|
||||
func TestGetInt(t *testing.T) {
|
||||
var t1 = 1
|
||||
t1 := 1
|
||||
assert.Equal(t, 1, GetInt(t1))
|
||||
var t2 int32 = 32
|
||||
assert.Equal(t, 32, GetInt(t2))
|
||||
|
||||
var t3 int64 = 64
|
||||
assert.Equal(t, 64, GetInt(t3))
|
||||
var t4 = "128"
|
||||
t4 := "128"
|
||||
|
||||
assert.Equal(t, 128, GetInt(t4))
|
||||
assert.Equal(t, 0, GetInt(nil))
|
||||
@ -51,38 +51,38 @@ func TestGetInt(t *testing.T) {
|
||||
|
||||
func TestGetInt64(t *testing.T) {
|
||||
var i int64 = 1
|
||||
var t1 = 1
|
||||
t1 := 1
|
||||
assert.Equal(t, i, GetInt64(t1))
|
||||
var t2 int32 = 1
|
||||
|
||||
assert.Equal(t, i, GetInt64(t2))
|
||||
var t3 int64 = 1
|
||||
assert.Equal(t, i, GetInt64(t3))
|
||||
var t4 = "1"
|
||||
t4 := "1"
|
||||
assert.Equal(t, i, GetInt64(t4))
|
||||
assert.Equal(t, int64(0), GetInt64(nil))
|
||||
}
|
||||
|
||||
func TestGetFloat64(t *testing.T) {
|
||||
var f = 1.11
|
||||
f := 1.11
|
||||
var t1 float32 = 1.11
|
||||
assert.Equal(t, f, GetFloat64(t1))
|
||||
var t2 = 1.11
|
||||
t2 := 1.11
|
||||
assert.Equal(t, f, GetFloat64(t2))
|
||||
var t3 = "1.11"
|
||||
t3 := "1.11"
|
||||
assert.Equal(t, f, GetFloat64(t3))
|
||||
|
||||
var f2 float64 = 1
|
||||
var t4 = 1
|
||||
t4 := 1
|
||||
assert.Equal(t, f2, GetFloat64(t4))
|
||||
|
||||
assert.Equal(t, float64(0), GetFloat64(nil))
|
||||
}
|
||||
|
||||
func TestGetBool(t *testing.T) {
|
||||
var t1 = true
|
||||
t1 := true
|
||||
assert.True(t, GetBool(t1))
|
||||
var t2 = "true"
|
||||
t2 := "true"
|
||||
assert.True(t, GetBool(t2))
|
||||
|
||||
assert.False(t, GetBool(nil))
|
||||
|
||||
6
client/cache/error_code.go
vendored
6
client/cache/error_code.go
vendored
@ -170,5 +170,7 @@ The reponse from SSDB server is invalid.
|
||||
Usually it indicates something wrong on server side.
|
||||
`)
|
||||
|
||||
var ErrKeyExpired = berror.Error(KeyExpired, "the key is expired")
|
||||
var ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")
|
||||
var (
|
||||
ErrKeyExpired = berror.Error(KeyExpired, "the key is expired")
|
||||
ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")
|
||||
)
|
||||
|
||||
1
client/cache/file.go
vendored
1
client/cache/file.go
vendored
@ -67,7 +67,6 @@ func NewFileCache() Cache {
|
||||
// StartAndGC starts gc for file cache.
|
||||
// config must be in the format {CachePath:"/cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}
|
||||
func (fc *FileCache) StartAndGC(config string) error {
|
||||
|
||||
cfg := make(map[string]string)
|
||||
err := json.Unmarshal([]byte(config), &cfg)
|
||||
if err != nil {
|
||||
|
||||
6
client/cache/memory.go
vendored
6
client/cache/memory.go
vendored
@ -25,10 +25,8 @@ import (
|
||||
"github.com/beego/beego/v2/core/berror"
|
||||
)
|
||||
|
||||
var (
|
||||
// Timer for how often to recycle the expired cache items in memory (in seconds)
|
||||
DefaultEvery = 60 // 1 minute
|
||||
)
|
||||
// DefaultEvery sets a timer for how often to recycle the expired cache items in memory (in seconds)
|
||||
var DefaultEvery = 60 // 1 minute
|
||||
|
||||
// MemoryItem stores memory cache item.
|
||||
type MemoryItem struct {
|
||||
|
||||
6
client/cache/redis/redis.go
vendored
6
client/cache/redis/redis.go
vendored
@ -43,10 +43,8 @@ import (
|
||||
"github.com/beego/beego/v2/core/berror"
|
||||
)
|
||||
|
||||
var (
|
||||
// The collection name of redis for the cache adapter.
|
||||
DefaultKey = "beecacheRedis"
|
||||
)
|
||||
// DefaultKey defines the collection name of redis for the cache adapter.
|
||||
var DefaultKey = "beecacheRedis"
|
||||
|
||||
// Cache is Redis cache adapter.
|
||||
type Cache struct {
|
||||
|
||||
1
client/cache/redis/redis_test.go
vendored
1
client/cache/redis/redis_test.go
vendored
@ -28,7 +28,6 @@ import (
|
||||
)
|
||||
|
||||
func TestRedisCache(t *testing.T) {
|
||||
|
||||
redisAddr := os.Getenv("REDIS_ADDR")
|
||||
if redisAddr == "" {
|
||||
redisAddr = "127.0.0.1:6379"
|
||||
|
||||
1
client/cache/ssdb/ssdb.go
vendored
1
client/cache/ssdb/ssdb.go
vendored
@ -124,7 +124,6 @@ func (rc *Cache) IsExist(ctx context.Context, key string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
|
||||
}
|
||||
|
||||
// ClearAll clears all cached items in ssdb.
|
||||
|
||||
1
client/cache/ssdb/ssdb_test.go
vendored
1
client/cache/ssdb/ssdb_test.go
vendored
@ -15,7 +15,6 @@ import (
|
||||
)
|
||||
|
||||
func TestSsdbcacheCache(t *testing.T) {
|
||||
|
||||
ssdbAddr := os.Getenv("SSDB_ADDR")
|
||||
if ssdbAddr == "" {
|
||||
ssdbAddr = "127.0.0.1:8888"
|
||||
|
||||
@ -35,9 +35,7 @@ type FilterChainBuilder struct {
|
||||
}
|
||||
|
||||
func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter {
|
||||
|
||||
return func(ctx context.Context, req *httplib.BeegoHTTPRequest) (*http.Response, error) {
|
||||
|
||||
method := req.GetRequest().Method
|
||||
|
||||
operationName := method + "#" + req.GetRequest().URL.String()
|
||||
|
||||
@ -32,11 +32,12 @@ type FilterChainBuilder struct {
|
||||
RunMode string
|
||||
}
|
||||
|
||||
var summaryVec prometheus.ObserverVec
|
||||
var initSummaryVec sync.Once
|
||||
var (
|
||||
summaryVec prometheus.ObserverVec
|
||||
initSummaryVec sync.Once
|
||||
)
|
||||
|
||||
func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter {
|
||||
|
||||
initSummaryVec.Do(func() {
|
||||
summaryVec = prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||
Name: "beego",
|
||||
|
||||
@ -400,7 +400,6 @@ func (b *BeegoHTTPRequest) handleFileToBody(bodyWriter *multipart.Writer, formna
|
||||
"could not create form file, formname: %s, filename: %s", formname, filename))
|
||||
}
|
||||
fh, err := os.Open(filename)
|
||||
|
||||
if err != nil {
|
||||
logs.Error(errFmt, berror.Wrapf(err, ReadFileFailed, "could not open this file %s", filename))
|
||||
}
|
||||
|
||||
@ -63,7 +63,6 @@ func TestDoRequest(t *testing.T) {
|
||||
if elapsedTime < delayedTime {
|
||||
t.Errorf("Not enough retries. Took %dms. Delay was meant to take %dms", elapsedTime, delayedTime)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
@ -248,7 +247,6 @@ func TestToJson(t *testing.T) {
|
||||
t.Fatal("response is not valid ip")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestToFile(t *testing.T) {
|
||||
|
||||
@ -23,10 +23,6 @@ import (
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
func TestSimpleCondition_MatchPath(t *testing.T) {
|
||||
sc := NewSimpleCondition("/abc/s")
|
||||
res := sc.Match(context.Background(), httplib.Get("http://localhost:8080/abc/s"))
|
||||
@ -72,7 +68,6 @@ func TestSimpleCondition_MatchHeader(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSimpleCondition_MatchBodyField(t *testing.T) {
|
||||
|
||||
sc := NewSimpleCondition("/abc/s")
|
||||
req := httplib.Post("http://localhost:8080/abc/s")
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@ import (
|
||||
)
|
||||
|
||||
func TestStartMock(t *testing.T) {
|
||||
|
||||
// httplib.defaultSetting.FilterChains = []httplib.FilterChain{mockFilter.FilterChain}
|
||||
|
||||
stub := StartMock()
|
||||
@ -41,7 +40,6 @@ func TestStartMock(t *testing.T) {
|
||||
|
||||
assert.Equal(t, expectedErr, err)
|
||||
assert.Equal(t, expectedResp, resp)
|
||||
|
||||
}
|
||||
|
||||
// TestStartMock_Isolation Test StartMock that
|
||||
|
||||
@ -68,8 +68,10 @@ var defaultSetting = BeegoHTTPSettings{
|
||||
FilterChains: make([]FilterChain, 0, 4),
|
||||
}
|
||||
|
||||
var defaultCookieJar http.CookieJar
|
||||
var settingMutex sync.Mutex
|
||||
var (
|
||||
defaultCookieJar http.CookieJar
|
||||
settingMutex sync.Mutex
|
||||
)
|
||||
|
||||
// AddDefaultFilter add a new filter into defaultSetting
|
||||
// Be careful about using this method if you invoke SetDefaultSetting somewhere
|
||||
|
||||
@ -18,8 +18,10 @@ import (
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
)
|
||||
|
||||
var port = ""
|
||||
var baseURL = "http://localhost:"
|
||||
var (
|
||||
port = ""
|
||||
baseURL = "http://localhost:"
|
||||
)
|
||||
|
||||
// TestHTTPRequest beego test request client
|
||||
type TestHTTPRequest struct {
|
||||
|
||||
@ -5,9 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func TestClause(t *testing.T) {
|
||||
var (
|
||||
column = `a`
|
||||
)
|
||||
column := `a`
|
||||
|
||||
o := Clause(
|
||||
Column(column),
|
||||
@ -108,7 +106,6 @@ func TestParseOrder(t *testing.T) {
|
||||
if orders[2].GetColumn() != `user.status` {
|
||||
t.Error()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestOrder_GetColumn(t *testing.T) {
|
||||
|
||||
@ -27,9 +27,7 @@ type commander interface {
|
||||
Run() error
|
||||
}
|
||||
|
||||
var (
|
||||
commands = make(map[string]commander)
|
||||
)
|
||||
var commands = make(map[string]commander)
|
||||
|
||||
// print help.
|
||||
func printHelp(errs ...string) {
|
||||
|
||||
@ -126,9 +126,7 @@ func getColumnAddQuery(al *alias, fi *fieldInfo) string {
|
||||
|
||||
// Get string value for the attribute "DEFAULT" for the CREATE, ALTER commands
|
||||
func getColumnDefault(fi *fieldInfo) string {
|
||||
var (
|
||||
v, t, d string
|
||||
)
|
||||
var v, t, d string
|
||||
|
||||
// Skip default attribute if field is in relations
|
||||
if fi.rel || fi.reverse {
|
||||
|
||||
@ -32,13 +32,10 @@ const (
|
||||
formatDateTime = "2006-01-02 15:04:05"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMissPK missing pk error
|
||||
ErrMissPK = errors.New("missed pk value")
|
||||
)
|
||||
// ErrMissPK missing pk error
|
||||
var ErrMissPK = errors.New("missed pk value")
|
||||
|
||||
var (
|
||||
operators = map[string]bool{
|
||||
var operators = map[string]bool{
|
||||
"exact": true,
|
||||
"iexact": true,
|
||||
"strictexact": true,
|
||||
@ -65,8 +62,7 @@ var (
|
||||
// "week_day": true,
|
||||
"isnull": true,
|
||||
// "search": true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// an instance of dbBaser interface/
|
||||
type dbBase struct {
|
||||
@ -537,7 +533,6 @@ func (d *dbBase) InsertOrUpdate(ctx context.Context, q dbQuerier, mi *modelInfo,
|
||||
names := make([]string, 0, len(mi.fields.dbcols)-1)
|
||||
Q := d.ins.TableQuote()
|
||||
values, _, err := d.collectValues(mi, ind, mi.fields.dbcols, true, true, &names, a.TZ)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -934,7 +929,6 @@ func (d *dbBase) DeleteBatch(ctx context.Context, q dbQuerier, qs *querySet, mi
|
||||
|
||||
// read related records.
|
||||
func (d *dbBase) ReadBatch(ctx context.Context, q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition, container interface{}, tz *time.Location, cols []string) (int64, error) {
|
||||
|
||||
val := reflect.ValueOf(container)
|
||||
ind := reflect.Indirect(val)
|
||||
|
||||
@ -1435,12 +1429,10 @@ end:
|
||||
}
|
||||
|
||||
return value, nil
|
||||
|
||||
}
|
||||
|
||||
// set one value to struct column field.
|
||||
func (d *dbBase) setFieldValue(fi *fieldInfo, value interface{}, field reflect.Value) (interface{}, error) {
|
||||
|
||||
fieldType := fi.fieldType
|
||||
isNative := !fi.isFielder
|
||||
|
||||
@ -1632,7 +1624,6 @@ setValue:
|
||||
|
||||
// query sql, read values , save to *[]ParamList.
|
||||
func (d *dbBase) ReadValues(ctx context.Context, q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition, exprs []string, container interface{}, tz *time.Location) (int64, error) {
|
||||
|
||||
var (
|
||||
maps []Params
|
||||
lists []ParamsList
|
||||
|
||||
@ -112,8 +112,10 @@ type DB struct {
|
||||
stmtDecoratorsLimit int
|
||||
}
|
||||
|
||||
var _ dbQuerier = new(DB)
|
||||
var _ txer = new(DB)
|
||||
var (
|
||||
_ dbQuerier = new(DB)
|
||||
_ txer = new(DB)
|
||||
)
|
||||
|
||||
func (d *DB) Begin() (*sql.Tx, error) {
|
||||
return d.DB.Begin()
|
||||
@ -221,8 +223,10 @@ type TxDB struct {
|
||||
tx *sql.Tx
|
||||
}
|
||||
|
||||
var _ dbQuerier = new(TxDB)
|
||||
var _ txEnder = new(TxDB)
|
||||
var (
|
||||
_ dbQuerier = new(TxDB)
|
||||
_ txEnder = new(TxDB)
|
||||
)
|
||||
|
||||
func (t *TxDB) Commit() error {
|
||||
return t.tx.Commit()
|
||||
@ -240,8 +244,10 @@ func (t *TxDB) RollbackUnlessCommit() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ dbQuerier = new(TxDB)
|
||||
var _ txEnder = new(TxDB)
|
||||
var (
|
||||
_ dbQuerier = new(TxDB)
|
||||
_ txEnder = new(TxDB)
|
||||
)
|
||||
|
||||
func (t *TxDB) Prepare(query string) (*sql.Stmt, error) {
|
||||
return t.PrepareContext(context.Background(), query)
|
||||
@ -365,7 +371,6 @@ func addAliasWthDB(aliasName, driverName string, db *sql.DB, params ...DBOption)
|
||||
}
|
||||
|
||||
func newAliasWithDb(aliasName, driverName string, db *sql.DB, params ...DBOption) (*alias, error) {
|
||||
|
||||
al := &alias{}
|
||||
al.DB = &DB{
|
||||
RWMutex: new(sync.RWMutex),
|
||||
|
||||
@ -124,7 +124,6 @@ func (d *dbBaseMysql) InsertOrUpdate(ctx context.Context, q dbQuerier, mi *model
|
||||
names := make([]string, 0, len(mi.fields.dbcols)-1)
|
||||
Q := d.ins.TableQuote()
|
||||
values, _, err := d.collectValues(mi, ind, mi.fields.dbcols, true, true, &names, a.TZ)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@ -106,7 +106,6 @@ func (t *dbTables) loopDepth(depth int, prefix string, fi *fieldInfo, related []
|
||||
|
||||
// parse related fields.
|
||||
func (t *dbTables) parseRelated(rels []string, depth int) {
|
||||
|
||||
relsNum := len(rels)
|
||||
related := make([]string, relsNum)
|
||||
copy(related, rels)
|
||||
|
||||
@ -55,7 +55,6 @@ func getExistPk(mi *modelInfo, ind reflect.Value) (column string, value interfac
|
||||
|
||||
// get fields description as flatted string.
|
||||
func getFlatParams(fi *fieldInfo, args []interface{}, tz *time.Location) (params []interface{}) {
|
||||
|
||||
outFor:
|
||||
for _, arg := range args {
|
||||
val := reflect.ValueOf(arg)
|
||||
|
||||
@ -27,8 +27,7 @@ import (
|
||||
|
||||
var _ Ormer = new(DoNothingOrm)
|
||||
|
||||
type DoNothingOrm struct {
|
||||
}
|
||||
type DoNothingOrm struct{}
|
||||
|
||||
func (d *DoNothingOrm) Read(md interface{}, cols ...string) error {
|
||||
return nil
|
||||
|
||||
@ -57,7 +57,6 @@ func TestDefaultValueFilterChainBuilder_FilterChain(t *testing.T) {
|
||||
_, _ = o.InsertMulti(3, []*DefaultValueTestEntity{entity})
|
||||
assert.Equal(t, 12, entity.Age)
|
||||
assert.Equal(t, 13, entity.AgeInOldStyle)
|
||||
|
||||
}
|
||||
|
||||
type defaultValueTestOrm struct {
|
||||
|
||||
@ -39,11 +39,12 @@ type FilterChainBuilder struct {
|
||||
RunMode string
|
||||
}
|
||||
|
||||
var summaryVec prometheus.ObserverVec
|
||||
var initSummaryVec sync.Once
|
||||
var (
|
||||
summaryVec prometheus.ObserverVec
|
||||
initSummaryVec sync.Once
|
||||
)
|
||||
|
||||
func (builder *FilterChainBuilder) FilterChain(next orm.Filter) orm.Filter {
|
||||
|
||||
initSummaryVec.Do(func() {
|
||||
summaryVec = prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||
Name: "beego",
|
||||
|
||||
@ -58,5 +58,4 @@ func TestFilterChainBuilder_FilterChain1(t *testing.T) {
|
||||
|
||||
inv.Method = "Update"
|
||||
builder.report(ctx, inv, time.Second)
|
||||
|
||||
}
|
||||
|
||||
@ -28,8 +28,10 @@ const (
|
||||
TxNameKey = "TxName"
|
||||
)
|
||||
|
||||
var _ Ormer = new(filterOrmDecorator)
|
||||
var _ TxOrmer = new(filterOrmDecorator)
|
||||
var (
|
||||
_ Ormer = new(filterOrmDecorator)
|
||||
_ TxOrmer = new(filterOrmDecorator)
|
||||
)
|
||||
|
||||
type filterOrmDecorator struct {
|
||||
ormer
|
||||
@ -120,7 +122,6 @@ func (f *filterOrmDecorator) ReadOrCreate(md interface{}, col1 string, cols ...s
|
||||
}
|
||||
|
||||
func (f *filterOrmDecorator) ReadOrCreateWithCtx(ctx context.Context, md interface{}, col1 string, cols ...string) (bool, int64, error) {
|
||||
|
||||
mi, _ := modelCache.getByMd(md)
|
||||
inv := &Invocation{
|
||||
Method: "ReadOrCreateWithCtx",
|
||||
@ -143,7 +144,6 @@ func (f *filterOrmDecorator) LoadRelated(md interface{}, name string, args ...ut
|
||||
}
|
||||
|
||||
func (f *filterOrmDecorator) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) {
|
||||
|
||||
mi, _ := modelCache.getByMd(md)
|
||||
inv := &Invocation{
|
||||
Method: "LoadRelatedWithCtx",
|
||||
@ -162,7 +162,6 @@ func (f *filterOrmDecorator) LoadRelatedWithCtx(ctx context.Context, md interfac
|
||||
}
|
||||
|
||||
func (f *filterOrmDecorator) QueryM2M(md interface{}, name string) QueryM2Mer {
|
||||
|
||||
mi, _ := modelCache.getByMd(md)
|
||||
inv := &Invocation{
|
||||
Method: "QueryM2M",
|
||||
|
||||
@ -27,7 +27,6 @@ import (
|
||||
)
|
||||
|
||||
func TestFilterOrmDecorator_Read(t *testing.T) {
|
||||
|
||||
register()
|
||||
|
||||
o := &filterMockOrm{}
|
||||
|
||||
@ -116,7 +116,6 @@ func (m *Migration) UniCol(uni, name string) *Column {
|
||||
|
||||
// ForeignCol creates a new foreign column and returns the instance of column
|
||||
func (m *Migration) ForeignCol(colname, foreigncol, foreigntable string) (foreign *Foreign) {
|
||||
|
||||
foreign = &Foreign{ForeignColumn: foreigncol, ForeignTable: foreigntable}
|
||||
foreign.Name = colname
|
||||
m.AddForeign(foreign)
|
||||
@ -153,7 +152,6 @@ func (c *Column) SetAuto(inc bool) *Column {
|
||||
func (c *Column) SetNullable(null bool) *Column {
|
||||
if null {
|
||||
c.Null = ""
|
||||
|
||||
} else {
|
||||
c.Null = "NOT NULL"
|
||||
}
|
||||
@ -184,7 +182,6 @@ func (c *Column) SetDataType(dataType string) *Column {
|
||||
func (c *RenameColumn) SetOldNullable(null bool) *RenameColumn {
|
||||
if null {
|
||||
c.OldNull = ""
|
||||
|
||||
} else {
|
||||
c.OldNull = "NOT NULL"
|
||||
}
|
||||
@ -219,7 +216,6 @@ func (c *Column) SetPrimary(m *Migration) *Column {
|
||||
|
||||
// AddColumnsToUnique adds the columns to Unique Struct
|
||||
func (unique *Unique) AddColumnsToUnique(columns ...*Column) *Unique {
|
||||
|
||||
unique.Columns = append(unique.Columns, columns...)
|
||||
|
||||
return unique
|
||||
@ -227,7 +223,6 @@ func (unique *Unique) AddColumnsToUnique(columns ...*Column) *Unique {
|
||||
|
||||
// AddColumns adds columns to m struct
|
||||
func (m *Migration) AddColumns(columns ...*Column) *Migration {
|
||||
|
||||
m.Columns = append(m.Columns, columns...)
|
||||
|
||||
return m
|
||||
|
||||
@ -72,9 +72,7 @@ type Migration struct {
|
||||
RemoveForeigns []*Foreign
|
||||
}
|
||||
|
||||
var (
|
||||
migrationMap map[string]Migrationer
|
||||
)
|
||||
var migrationMap map[string]Migrationer
|
||||
|
||||
func init() {
|
||||
migrationMap = make(map[string]Migrationer)
|
||||
@ -82,7 +80,6 @@ func init() {
|
||||
|
||||
// Up implement in the Inheritance struct for upgrade
|
||||
func (m *Migration) Up() {
|
||||
|
||||
switch m.ModifyType {
|
||||
case "reverse":
|
||||
m.ModifyType = "alter"
|
||||
@ -94,7 +91,6 @@ func (m *Migration) Up() {
|
||||
|
||||
// Down implement in the Inheritance struct for down
|
||||
func (m *Migration) Down() {
|
||||
|
||||
switch m.ModifyType {
|
||||
case "alter":
|
||||
m.ModifyType = "reverse"
|
||||
@ -311,6 +307,7 @@ func isRollBack(name string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getAllMigrations() (map[string]string, error) {
|
||||
o := orm.NewOrm()
|
||||
var maps []orm.Params
|
||||
|
||||
@ -55,7 +55,6 @@ func (o *OrmStub) Clear() {
|
||||
|
||||
func (o *OrmStub) FilterChain(next orm.Filter) orm.Filter {
|
||||
return func(ctx context.Context, inv *orm.Invocation) []interface{} {
|
||||
|
||||
ms := mockFromCtx(ctx)
|
||||
ms = append(ms, o.ms...)
|
||||
|
||||
|
||||
@ -247,7 +247,7 @@ func TestTransactionRollbackUnlessCommit(t *testing.T) {
|
||||
mock := errors.New(mockErrorMsg)
|
||||
s.Mock(MockRollbackUnlessCommit(mock))
|
||||
|
||||
//u := &User{}
|
||||
// u := &User{}
|
||||
o := orm.NewOrm()
|
||||
txOrm, _ := o.Begin()
|
||||
err := txOrm.RollbackUnlessCommit()
|
||||
|
||||
@ -22,8 +22,7 @@ import (
|
||||
|
||||
// DoNothingQueryM2Mer do nothing
|
||||
// use it to build mock orm.QueryM2Mer
|
||||
type DoNothingQueryM2Mer struct {
|
||||
}
|
||||
type DoNothingQueryM2Mer struct{}
|
||||
|
||||
func (d *DoNothingQueryM2Mer) AddWithCtx(ctx context.Context, i ...interface{}) (int64, error) {
|
||||
return 0, nil
|
||||
|
||||
@ -23,8 +23,7 @@ import (
|
||||
|
||||
// DoNothingQuerySetter do nothing
|
||||
// usually you use this to build your mock QuerySetter
|
||||
type DoNothingQuerySetter struct {
|
||||
}
|
||||
type DoNothingQuerySetter struct{}
|
||||
|
||||
func (d *DoNothingQuerySetter) OrderClauses(orders ...*order_clause.Order) orm.QuerySeter {
|
||||
return d
|
||||
|
||||
@ -20,8 +20,7 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
type DoNothingRawSetter struct {
|
||||
}
|
||||
type DoNothingRawSetter struct{}
|
||||
|
||||
func (d *DoNothingRawSetter) Exec() (sql.Result, error) {
|
||||
return nil, nil
|
||||
|
||||
@ -32,9 +32,7 @@ const (
|
||||
defaultStructTagDelim = ";"
|
||||
)
|
||||
|
||||
var (
|
||||
modelCache = NewModelCacheHandler()
|
||||
)
|
||||
var modelCache = NewModelCacheHandler()
|
||||
|
||||
// model info collection
|
||||
type _modelCache struct {
|
||||
@ -332,7 +330,6 @@ end:
|
||||
|
||||
// register register models to model cache
|
||||
func (mc *_modelCache) register(prefixOrSuffixStr string, prefixOrSuffix bool, models ...interface{}) (err error) {
|
||||
|
||||
for _, model := range models {
|
||||
val := reflect.ValueOf(model)
|
||||
typ := reflect.Indirect(val).Type()
|
||||
|
||||
@ -387,7 +387,6 @@ checkType:
|
||||
fi.timePrecision = &v
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if attrs["auto_now"] {
|
||||
|
||||
@ -193,22 +193,24 @@ type DataNull struct {
|
||||
DateTimePtr *time.Time `orm:"null"`
|
||||
}
|
||||
|
||||
type String string
|
||||
type Boolean bool
|
||||
type Byte byte
|
||||
type Rune rune
|
||||
type Int int
|
||||
type Int8 int8
|
||||
type Int16 int16
|
||||
type Int32 int32
|
||||
type Int64 int64
|
||||
type Uint uint
|
||||
type Uint8 uint8
|
||||
type Uint16 uint16
|
||||
type Uint32 uint32
|
||||
type Uint64 uint64
|
||||
type Float32 float64
|
||||
type Float64 float64
|
||||
type (
|
||||
String string
|
||||
Boolean bool
|
||||
Byte byte
|
||||
Rune rune
|
||||
Int int
|
||||
Int8 int8
|
||||
Int16 int16
|
||||
Int32 int32
|
||||
Int64 int64
|
||||
Uint uint
|
||||
Uint8 uint8
|
||||
Uint16 uint16
|
||||
Uint32 uint32
|
||||
Uint64 uint64
|
||||
Float32 float64
|
||||
Float64 float64
|
||||
)
|
||||
|
||||
type DataCustom struct {
|
||||
ID int `orm:"column(id)"`
|
||||
@ -486,8 +488,7 @@ var (
|
||||
dDbBaser dbBaser
|
||||
)
|
||||
|
||||
var (
|
||||
helpinfo = `need driver and source!
|
||||
var helpinfo = `need driver and source!
|
||||
|
||||
Default DB Drivers.
|
||||
|
||||
@ -530,7 +531,6 @@ var (
|
||||
go test -v github.com/beego/beego/v2/pgk/orm
|
||||
|
||||
`
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Debug, _ = StrTo(DBARGS.Debug).Bool()
|
||||
@ -542,7 +542,6 @@ func init() {
|
||||
}
|
||||
|
||||
err := RegisterDataBase("default", DBARGS.Driver, DBARGS.Source, MaxIdleConnections(20))
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("can not register database: %v", err))
|
||||
}
|
||||
@ -551,5 +550,4 @@ func init() {
|
||||
if alias.Driver == DRMySQL {
|
||||
alias.Engine = "INNODB"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -101,9 +101,11 @@ type ormBase struct {
|
||||
db dbQuerier
|
||||
}
|
||||
|
||||
var _ DQL = new(ormBase)
|
||||
var _ DML = new(ormBase)
|
||||
var _ DriverGetter = new(ormBase)
|
||||
var (
|
||||
_ DQL = new(ormBase)
|
||||
_ DML = new(ormBase)
|
||||
_ DriverGetter = new(ormBase)
|
||||
)
|
||||
|
||||
// get model info and model reflect value
|
||||
func (o *ormBase) getMiInd(md interface{}, needPtr bool) (mi *modelInfo, ind reflect.Value) {
|
||||
@ -133,6 +135,7 @@ func (o *ormBase) getFieldInfo(mi *modelInfo, name string) *fieldInfo {
|
||||
func (o *ormBase) Read(md interface{}, cols ...string) error {
|
||||
return o.ReadWithCtx(context.Background(), md, cols...)
|
||||
}
|
||||
|
||||
func (o *ormBase) ReadWithCtx(ctx context.Context, md interface{}, cols ...string) error {
|
||||
mi, ind := o.getMiInd(md, true)
|
||||
return o.alias.DbBaser.Read(ctx, o.db, mi, ind, o.alias.TZ, cols, false)
|
||||
@ -142,6 +145,7 @@ func (o *ormBase) ReadWithCtx(ctx context.Context, md interface{}, cols ...strin
|
||||
func (o *ormBase) ReadForUpdate(md interface{}, cols ...string) error {
|
||||
return o.ReadForUpdateWithCtx(context.Background(), md, cols...)
|
||||
}
|
||||
|
||||
func (o *ormBase) ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols ...string) error {
|
||||
mi, ind := o.getMiInd(md, true)
|
||||
return o.alias.DbBaser.Read(ctx, o.db, mi, ind, o.alias.TZ, cols, true)
|
||||
@ -151,6 +155,7 @@ func (o *ormBase) ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols
|
||||
func (o *ormBase) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error) {
|
||||
return o.ReadOrCreateWithCtx(context.Background(), md, col1, cols...)
|
||||
}
|
||||
|
||||
func (o *ormBase) ReadOrCreateWithCtx(ctx context.Context, md interface{}, col1 string, cols ...string) (bool, int64, error) {
|
||||
cols = append([]string{col1}, cols...)
|
||||
mi, ind := o.getMiInd(md, true)
|
||||
@ -177,6 +182,7 @@ func (o *ormBase) ReadOrCreateWithCtx(ctx context.Context, md interface{}, col1
|
||||
func (o *ormBase) Insert(md interface{}) (int64, error) {
|
||||
return o.InsertWithCtx(context.Background(), md)
|
||||
}
|
||||
|
||||
func (o *ormBase) InsertWithCtx(ctx context.Context, md interface{}) (int64, error) {
|
||||
mi, ind := o.getMiInd(md, true)
|
||||
id, err := o.alias.DbBaser.Insert(ctx, o.db, mi, ind, o.alias.TZ)
|
||||
@ -204,6 +210,7 @@ func (o *ormBase) setPk(mi *modelInfo, ind reflect.Value, id int64) {
|
||||
func (o *ormBase) InsertMulti(bulk int, mds interface{}) (int64, error) {
|
||||
return o.InsertMultiWithCtx(context.Background(), bulk, mds)
|
||||
}
|
||||
|
||||
func (o *ormBase) InsertMultiWithCtx(ctx context.Context, bulk int, mds interface{}) (int64, error) {
|
||||
var cnt int64
|
||||
|
||||
@ -242,6 +249,7 @@ func (o *ormBase) InsertMultiWithCtx(ctx context.Context, bulk int, mds interfac
|
||||
func (o *ormBase) InsertOrUpdate(md interface{}, colConflictAndArgs ...string) (int64, error) {
|
||||
return o.InsertOrUpdateWithCtx(context.Background(), md, colConflictAndArgs...)
|
||||
}
|
||||
|
||||
func (o *ormBase) InsertOrUpdateWithCtx(ctx context.Context, md interface{}, colConflitAndArgs ...string) (int64, error) {
|
||||
mi, ind := o.getMiInd(md, true)
|
||||
id, err := o.alias.DbBaser.InsertOrUpdate(ctx, o.db, mi, ind, o.alias, colConflitAndArgs...)
|
||||
@ -259,6 +267,7 @@ func (o *ormBase) InsertOrUpdateWithCtx(ctx context.Context, md interface{}, col
|
||||
func (o *ormBase) Update(md interface{}, cols ...string) (int64, error) {
|
||||
return o.UpdateWithCtx(context.Background(), md, cols...)
|
||||
}
|
||||
|
||||
func (o *ormBase) UpdateWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error) {
|
||||
mi, ind := o.getMiInd(md, true)
|
||||
return o.alias.DbBaser.Update(ctx, o.db, mi, ind, o.alias.TZ, cols)
|
||||
@ -269,6 +278,7 @@ func (o *ormBase) UpdateWithCtx(ctx context.Context, md interface{}, cols ...str
|
||||
func (o *ormBase) Delete(md interface{}, cols ...string) (int64, error) {
|
||||
return o.DeleteWithCtx(context.Background(), md, cols...)
|
||||
}
|
||||
|
||||
func (o *ormBase) DeleteWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error) {
|
||||
mi, ind := o.getMiInd(md, true)
|
||||
num, err := o.alias.DbBaser.Delete(ctx, o.db, mi, ind, o.alias.TZ, cols)
|
||||
@ -313,6 +323,7 @@ func (o *ormBase) QueryM2MWithCtx(_ context.Context, md interface{}, name string
|
||||
func (o *ormBase) LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error) {
|
||||
return o.LoadRelatedWithCtx(context.Background(), md, name, args...)
|
||||
}
|
||||
|
||||
func (o *ormBase) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) {
|
||||
_, fi, ind, qs := o.queryRelated(md, name)
|
||||
|
||||
@ -482,6 +493,7 @@ func (o *ormBase) QueryTableWithCtx(_ context.Context, ptrStructOrTableName inte
|
||||
func (o *ormBase) Raw(query string, args ...interface{}) RawSeter {
|
||||
return o.RawWithCtx(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
func (o *ormBase) RawWithCtx(ctx context.Context, query string, args ...interface{}) RawSeter {
|
||||
return newRawSet(o, query, args)
|
||||
}
|
||||
@ -571,7 +583,7 @@ func doTxTemplate(o TxBeginner, ctx context.Context, opts *sql.TxOptions,
|
||||
}
|
||||
}
|
||||
}()
|
||||
var taskTxOrm = _txOrm
|
||||
taskTxOrm := _txOrm
|
||||
err = task(ctx, taskTxOrm)
|
||||
panicked = false
|
||||
return err
|
||||
|
||||
@ -78,7 +78,6 @@ func (c Condition) AndNot(expr string, args ...interface{}) *Condition {
|
||||
|
||||
// AndCond combine a condition to current condition
|
||||
func (c *Condition) AndCond(cond *Condition) *Condition {
|
||||
|
||||
if c == cond {
|
||||
panic(fmt.Errorf("<Condition.AndCond> cannot use self as sub cond"))
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ func NewLog(out io.Writer) *Log {
|
||||
}
|
||||
|
||||
func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error, args ...interface{}) {
|
||||
var logMap = make(map[string]interface{})
|
||||
logMap := make(map[string]interface{})
|
||||
sub := time.Since(t) / 1e5
|
||||
elsp := float64(int(sub)) / 10.0
|
||||
logMap["cost_time"] = elsp
|
||||
@ -94,6 +94,7 @@ func (d *stmtQueryLog) ExecContext(ctx context.Context, args ...interface{}) (sq
|
||||
debugLogQueies(d.alias, "st.Exec", d.query, a, err, args...)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (d *stmtQueryLog) Query(args ...interface{}) (*sql.Rows, error) {
|
||||
return d.QueryContext(context.Background(), args...)
|
||||
}
|
||||
@ -133,9 +134,11 @@ type dbQueryLog struct {
|
||||
txe txEnder
|
||||
}
|
||||
|
||||
var _ dbQuerier = new(dbQueryLog)
|
||||
var _ txer = new(dbQueryLog)
|
||||
var _ txEnder = new(dbQueryLog)
|
||||
var (
|
||||
_ dbQuerier = new(dbQueryLog)
|
||||
_ txer = new(dbQueryLog)
|
||||
_ txEnder = new(dbQueryLog)
|
||||
)
|
||||
|
||||
func (d *dbQueryLog) Prepare(query string) (*sql.Stmt, error) {
|
||||
return d.PrepareContext(context.Background(), query)
|
||||
|
||||
@ -253,7 +253,6 @@ func (o *rawSet) loopSetRefs(refs []interface{}, sInds []reflect.Value, nIndsPtr
|
||||
}
|
||||
cur++
|
||||
}
|
||||
|
||||
} else {
|
||||
value := reflect.ValueOf(refs[cur]).Elem().Interface()
|
||||
if isPtr && value == nil {
|
||||
@ -437,7 +436,6 @@ func (o *rawSet) QueryRow(containers ...interface{}) error {
|
||||
sInd.Set(nInd)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return ErrNoRows
|
||||
}
|
||||
@ -606,7 +604,6 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) {
|
||||
}
|
||||
|
||||
if cnt > 0 {
|
||||
|
||||
if structMode {
|
||||
sInds[0].Set(sInd)
|
||||
} else {
|
||||
|
||||
@ -842,7 +842,6 @@ The program—and web server—godoc processes Go source files to extract docume
|
||||
throwFailNow(t, AssertIs(nums, num))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCustomField(t *testing.T) {
|
||||
@ -1235,7 +1234,6 @@ func TestOne(t *testing.T) {
|
||||
|
||||
err = qs.Filter("user_name", "nothing").One(&user)
|
||||
throwFail(t, AssertIs(err, ErrNoRows))
|
||||
|
||||
}
|
||||
|
||||
func TestValues(t *testing.T) {
|
||||
@ -1285,8 +1283,8 @@ func TestValuesList(t *testing.T) {
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(num, 3))
|
||||
if num == 3 {
|
||||
throwFail(t, AssertIs(list[0][1], "slene")) //username
|
||||
throwFail(t, AssertIs(list[2][10], nil)) //profile
|
||||
throwFail(t, AssertIs(list[0][1], "slene")) // username
|
||||
throwFail(t, AssertIs(list[2][10], nil)) // profile
|
||||
}
|
||||
|
||||
num, err = qs.OrderBy("Id").ValuesList(&list, "UserName", "Profile__Age")
|
||||
@ -2219,7 +2217,7 @@ func TestTransaction(t *testing.T) {
|
||||
to, err := o.Begin()
|
||||
throwFail(t, err)
|
||||
|
||||
var names = []string{"1", "2", "3"}
|
||||
names := []string{"1", "2", "3"}
|
||||
|
||||
var tag Tag
|
||||
tag.Name = names[0]
|
||||
@ -2262,7 +2260,6 @@ func TestTransaction(t *testing.T) {
|
||||
num, err = o.QueryTable("tag").Filter("name", "commit").Delete()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), num)
|
||||
|
||||
}
|
||||
|
||||
func TestTxOrmRollbackUnlessCommit(t *testing.T) {
|
||||
@ -2763,6 +2760,7 @@ func TestStrPkInsert(t *testing.T) {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
if err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport InsertOrUpdate in beego" {
|
||||
return
|
||||
} else if err == ErrLastInsertIdUnavailable {
|
||||
return
|
||||
} else {
|
||||
|
||||
@ -21,7 +21,6 @@ func processingStr(str []string) string {
|
||||
|
||||
// Select will join the fields
|
||||
func (qb *PostgresQueryBuilder) Select(fields ...string) QueryBuilder {
|
||||
|
||||
var str string
|
||||
n := len(fields)
|
||||
|
||||
@ -80,7 +79,6 @@ func (qb *PostgresQueryBuilder) RightJoin(table string) QueryBuilder {
|
||||
|
||||
// On join with on cond
|
||||
func (qb *PostgresQueryBuilder) On(cond string) QueryBuilder {
|
||||
|
||||
var str string
|
||||
cond = strings.Replace(cond, " ", "", -1)
|
||||
slice := strings.Split(cond, "=")
|
||||
|
||||
@ -246,7 +246,7 @@ type ormer interface {
|
||||
DriverGetter
|
||||
}
|
||||
|
||||
//QueryExecutor wrapping for ormer
|
||||
// QueryExecutor wrapping for ormer
|
||||
type QueryExecutor interface {
|
||||
ormer
|
||||
}
|
||||
|
||||
@ -29,8 +29,10 @@ import (
|
||||
"github.com/beego/beego/v2/core/utils"
|
||||
)
|
||||
|
||||
var startTime = time.Now()
|
||||
var pid int
|
||||
var (
|
||||
startTime = time.Now()
|
||||
pid int
|
||||
)
|
||||
|
||||
func init() {
|
||||
pid = os.Getpid()
|
||||
@ -105,7 +107,6 @@ func PrintGCSummary(w io.Writer) {
|
||||
}
|
||||
|
||||
func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) {
|
||||
|
||||
if gcstats.NumGC > 0 {
|
||||
lastPause := gcstats.Pause[0]
|
||||
elapsed := time.Since(startTime)
|
||||
|
||||
@ -16,5 +16,4 @@ package bean
|
||||
|
||||
// ApplicationContext define for future
|
||||
// when we decide to support DI, IoC, this will be core API
|
||||
type ApplicationContext interface {
|
||||
}
|
||||
type ApplicationContext interface{}
|
||||
|
||||
@ -46,6 +46,7 @@ func init() {
|
||||
func goCodeBlock(code string) string {
|
||||
return codeBlock("go", code)
|
||||
}
|
||||
|
||||
func codeBlock(lan string, code string) string {
|
||||
return fmt.Sprintf("```%s\n%s\n```", lan, code)
|
||||
}
|
||||
|
||||
@ -66,7 +66,6 @@ func newBaseConfier(str1 string) *BaseConfiger {
|
||||
} else {
|
||||
return "", errors.New("mock error")
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,6 +165,7 @@ func (c *BaseConfiger) DefaultBool(key string, defaultVal bool) bool {
|
||||
}
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
func (c *BaseConfiger) DefaultFloat(key string, defaultVal float64) float64 {
|
||||
if res, err := c.Float(key); err == nil {
|
||||
return res
|
||||
@ -370,5 +371,4 @@ func ToString(x interface{}) string {
|
||||
|
||||
type DecodeOption func(options decodeOptions)
|
||||
|
||||
type decodeOptions struct {
|
||||
}
|
||||
type decodeOptions struct{}
|
||||
|
||||
@ -20,7 +20,6 @@ import (
|
||||
)
|
||||
|
||||
func TestExpandValueEnv(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
item string
|
||||
want string
|
||||
@ -51,5 +50,4 @@ func TestExpandValueEnv(t *testing.T) {
|
||||
t.Errorf("expand value error, item %q want %q, got %q", c.item, c.want, got)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -119,7 +119,6 @@ func (e *EtcdConfiger) Sub(key string) (config.Configer, error) {
|
||||
|
||||
// TODO remove this before release v2.0.0
|
||||
func (e *EtcdConfiger) OnChange(key string, fn func(value string)) {
|
||||
|
||||
buildOptsFunc := func() []clientv3.OpOption {
|
||||
return []clientv3.OpOption{}
|
||||
}
|
||||
@ -144,11 +143,9 @@ func (e *EtcdConfiger) OnChange(key string, fn func(value string)) {
|
||||
rch = e.client.Watch(context.Background(), e.prefix+key, buildOptsFunc()...)
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
type EtcdConfigerProvider struct {
|
||||
}
|
||||
type EtcdConfigerProvider struct{}
|
||||
|
||||
// Parse = ParseData([]byte(key))
|
||||
// key must be json
|
||||
|
||||
@ -32,7 +32,6 @@ func TestEtcdConfigerProvider_Parse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEtcdConfiger(t *testing.T) {
|
||||
|
||||
provider := &EtcdConfigerProvider{}
|
||||
cfger, _ := provider.Parse(readEtcdConfig())
|
||||
|
||||
|
||||
@ -42,15 +42,19 @@ func String(key string) (string, error) {
|
||||
func Strings(key string) ([]string, error) {
|
||||
return globalInstance.Strings(key)
|
||||
}
|
||||
|
||||
func Int(key string) (int, error) {
|
||||
return globalInstance.Int(key)
|
||||
}
|
||||
|
||||
func Int64(key string) (int64, error) {
|
||||
return globalInstance.Int64(key)
|
||||
}
|
||||
|
||||
func Bool(key string) (bool, error) {
|
||||
return globalInstance.Bool(key)
|
||||
}
|
||||
|
||||
func Float(key string) (float64, error) {
|
||||
return globalInstance.Float(key)
|
||||
}
|
||||
@ -64,15 +68,19 @@ func DefaultString(key string, defaultVal string) string {
|
||||
func DefaultStrings(key string, defaultVal []string) []string {
|
||||
return globalInstance.DefaultStrings(key, defaultVal)
|
||||
}
|
||||
|
||||
func DefaultInt(key string, defaultVal int) int {
|
||||
return globalInstance.DefaultInt(key, defaultVal)
|
||||
}
|
||||
|
||||
func DefaultInt64(key string, defaultVal int64) int64 {
|
||||
return globalInstance.DefaultInt64(key, defaultVal)
|
||||
}
|
||||
|
||||
func DefaultBool(key string, defaultVal bool) bool {
|
||||
return globalInstance.DefaultBool(key, defaultVal)
|
||||
}
|
||||
|
||||
func DefaultFloat(key string, defaultVal float64) float64 {
|
||||
return globalInstance.DefaultFloat(key, defaultVal)
|
||||
}
|
||||
@ -89,6 +97,7 @@ func GetSection(section string) (map[string]string, error) {
|
||||
func Unmarshaler(prefix string, obj interface{}, opt ...DecodeOption) error {
|
||||
return globalInstance.Unmarshaler(prefix, obj, opt...)
|
||||
}
|
||||
|
||||
func Sub(key string) (Configer, error) {
|
||||
return globalInstance.Sub(key)
|
||||
}
|
||||
|
||||
@ -46,8 +46,7 @@ var (
|
||||
)
|
||||
|
||||
// IniConfig implements Config to parse ini file.
|
||||
type IniConfig struct {
|
||||
}
|
||||
type IniConfig struct{}
|
||||
|
||||
// Parse creates a new Config and parses the file configuration from the named file.
|
||||
func (ini *IniConfig) Parse(name string) (Configer, error) {
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
func TestIni(t *testing.T) {
|
||||
|
||||
var (
|
||||
inicontext = `
|
||||
;comment one
|
||||
@ -129,11 +128,9 @@ password = ${GOPATH}
|
||||
if res != "astaxie" {
|
||||
t.Fatal("get name error")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIniSave(t *testing.T) {
|
||||
|
||||
const (
|
||||
inicontext = `
|
||||
app = app
|
||||
|
||||
@ -31,8 +31,7 @@ import (
|
||||
)
|
||||
|
||||
// JSONConfig is a json config parser and implements Config interface.
|
||||
type JSONConfig struct {
|
||||
}
|
||||
type JSONConfig struct{}
|
||||
|
||||
// Parse returns a ConfigContainer with parsed json config map.
|
||||
func (js *JSONConfig) Parse(filename string) (config.Configer, error) {
|
||||
@ -211,7 +210,6 @@ func (c *JSONConfigContainer) String(key string) (string, error) {
|
||||
// DefaultString returns the string value for a given key.
|
||||
// if err != nil return defaultval
|
||||
func (c *JSONConfigContainer) DefaultString(key string, defaultVal string) string {
|
||||
// TODO FIXME should not use "" to replace non existence
|
||||
if v, err := c.String(key); v != "" && err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
@ -25,7 +25,6 @@ import (
|
||||
)
|
||||
|
||||
func TestJsonStartsWithArray(t *testing.T) {
|
||||
|
||||
const jsoncontextwitharray = `[
|
||||
{
|
||||
"url": "user",
|
||||
@ -72,7 +71,6 @@ func TestJsonStartsWithArray(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJson(t *testing.T) {
|
||||
|
||||
var (
|
||||
jsoncontext = `{
|
||||
"appname": "beeapi",
|
||||
|
||||
@ -47,7 +47,6 @@ func (c *Config) ParseData(data []byte) (config.Configer, error) {
|
||||
return &configContainer{
|
||||
t: t,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
// configContainer support key looks like "a.b.c"
|
||||
@ -70,7 +69,6 @@ func (c *configContainer) Set(key, val string) error {
|
||||
// return error if key not found or value is invalid type
|
||||
func (c *configContainer) String(key string) (string, error) {
|
||||
res, err := c.get(key)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -90,7 +88,6 @@ func (c *configContainer) String(key string) (string, error) {
|
||||
// return error if key not found or value is invalid type
|
||||
func (c *configContainer) Strings(key string) ([]string, error) {
|
||||
val, err := c.get(key)
|
||||
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
@ -141,9 +138,7 @@ func (c *configContainer) Int64(key string) (int64, error) {
|
||||
// bool return bool value
|
||||
// return error if key not found or value is invalid type
|
||||
func (c *configContainer) Bool(key string) (bool, error) {
|
||||
|
||||
res, err := c.get(key)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -330,7 +325,6 @@ func (c *configContainer) get(key string) (interface{}, error) {
|
||||
|
||||
segs := strings.Split(key, keySeparator)
|
||||
t, err := subTree(c.t, segs[0:len(segs)-1])
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -102,7 +102,6 @@ func (c *ConfigContainer) Sub(key string) (config.Configer, error) {
|
||||
return &ConfigContainer{
|
||||
data: sub,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *ConfigContainer) sub(key string) (map[string]interface{}, error) {
|
||||
@ -170,7 +169,6 @@ func (c *ConfigContainer) DefaultInt64(key string, defaultVal int64) int64 {
|
||||
return defaultVal
|
||||
}
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
// Float returns the float value for a given key.
|
||||
|
||||
@ -25,7 +25,6 @@ import (
|
||||
)
|
||||
|
||||
func TestXML(t *testing.T) {
|
||||
|
||||
var (
|
||||
// xml parse should incluce in <config></config> tags
|
||||
xmlcontext = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -149,7 +148,6 @@ func TestXML(t *testing.T) {
|
||||
err = xmlconf.Unmarshaler("mysection", sec)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "MySection", sec.Name)
|
||||
|
||||
}
|
||||
|
||||
type Section struct {
|
||||
|
||||
@ -302,7 +302,6 @@ func (c *ConfigContainer) DefaultStrings(key string, defaultVal []string) []stri
|
||||
|
||||
// GetSection returns map for the given section
|
||||
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
|
||||
|
||||
if v, ok := c.data[section]; ok {
|
||||
return v.(map[string]string), nil
|
||||
}
|
||||
@ -335,7 +334,6 @@ func (c *ConfigContainer) DIY(key string) (v interface{}, err error) {
|
||||
}
|
||||
|
||||
func (c *ConfigContainer) getData(key string) (interface{}, error) {
|
||||
|
||||
if len(key) == 0 {
|
||||
return nil, errors.New("key is empty")
|
||||
}
|
||||
|
||||
@ -25,7 +25,6 @@ import (
|
||||
)
|
||||
|
||||
func TestYaml(t *testing.T) {
|
||||
|
||||
var (
|
||||
yamlcontext = `
|
||||
"appname": beeapi
|
||||
|
||||
@ -180,7 +180,6 @@ func (c *aliLSWriter) WriteMsg(lm *logs.LogMsg) error {
|
||||
|
||||
// Flush implementing method. empty.
|
||||
func (c *aliLSWriter) Flush() {
|
||||
|
||||
// flush all group
|
||||
for _, lg := range c.group {
|
||||
c.flush(lg)
|
||||
@ -192,7 +191,6 @@ func (c *aliLSWriter) Destroy() {
|
||||
}
|
||||
|
||||
func (c *aliLSWriter) flush(lg *LogGroup) {
|
||||
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
err := c.store.PutLogs(lg)
|
||||
|
||||
@ -128,7 +128,6 @@ func (p *LogProject) GetLogStore(name string) (s *LogStore, err error) {
|
||||
// and ttl is time-to-live(in day) of logs,
|
||||
// and shardCnt is the number of shards.
|
||||
func (p *LogProject) CreateLogStore(name string, ttl, shardCnt int) (err error) {
|
||||
|
||||
type Body struct {
|
||||
Name string `json:"logstoreName"`
|
||||
TTL int `json:"ttl"`
|
||||
@ -212,7 +211,6 @@ func (p *LogProject) DeleteLogStore(name string) (err error) {
|
||||
// UpdateLogStore updates a logstore according by logstore name,
|
||||
// obviously we can't modify the logstore name itself.
|
||||
func (p *LogProject) UpdateLogStore(name string, ttl, shardCnt int) (err error) {
|
||||
|
||||
type Body struct {
|
||||
Name string `json:"logstoreName"`
|
||||
TTL int `json:"ttl"`
|
||||
@ -355,7 +353,6 @@ func (p *LogProject) GetMachineGroup(name string) (m *MachineGroup, err error) {
|
||||
|
||||
// CreateMachineGroup creates a new machine group in SLS.
|
||||
func (p *LogProject) CreateMachineGroup(m *MachineGroup) (err error) {
|
||||
|
||||
body, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
@ -395,7 +392,6 @@ func (p *LogProject) CreateMachineGroup(m *MachineGroup) (err error) {
|
||||
|
||||
// UpdateMachineGroup updates a machine group.
|
||||
func (p *LogProject) UpdateMachineGroup(m *MachineGroup) (err error) {
|
||||
|
||||
body, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
@ -555,7 +551,6 @@ func (p *LogProject) GetConfig(name string) (c *LogConfig, err error) {
|
||||
|
||||
// UpdateConfig updates a config.
|
||||
func (p *LogProject) UpdateConfig(c *LogConfig) (err error) {
|
||||
|
||||
body, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return
|
||||
@ -595,7 +590,6 @@ func (p *LogProject) UpdateConfig(c *LogConfig) (err error) {
|
||||
|
||||
// CreateConfig creates a new config in SLS.
|
||||
func (p *LogProject) CreateConfig(c *LogConfig) (err error) {
|
||||
|
||||
body, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@ -241,7 +241,6 @@ func (s *LogStore) GetLogsBytes(shardID int, cursor string,
|
||||
|
||||
// LogsBytesDecode decodes logs binary data retruned by GetLogsBytes API
|
||||
func LogsBytesDecode(data []byte) (gl *LogGroupList, err error) {
|
||||
|
||||
gl = &LogGroupList{}
|
||||
err = proto.Unmarshal(data, gl)
|
||||
if err != nil {
|
||||
|
||||
@ -95,7 +95,6 @@ func (c *connWriter) WriteMsg(lm *LogMsg) error {
|
||||
|
||||
// Flush implementing method. empty.
|
||||
func (c *connWriter) Flush() {
|
||||
|
||||
}
|
||||
|
||||
// Destroy destroy connection writer and close tcp listener.
|
||||
|
||||
@ -26,7 +26,6 @@ import (
|
||||
// ConnTCPListener takes a TCP listener and accepts n TCP connections
|
||||
// Returns connections using connChan
|
||||
func connTCPListener(t *testing.T, n int, ln net.Listener, connChan chan<- net.Conn) {
|
||||
|
||||
// Listen and accept n incoming connections
|
||||
for i := 0; i < n; i++ {
|
||||
conn, err := ln.Accept()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user