Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
12dff072
Commit
12dff072
authored
Mar 18, 2017
by
astaxie
Committed by
GitHub
Mar 18, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2509 from sergeylanzman/add-gosimple
add go simple support
parents
8dbf9eb0
d9564449
Show whitespace changes
Inline
Side-by-side
Showing
43 changed files
with
134 additions
and
211 deletions
+134
-211
.gosimpleignore
.gosimpleignore
+5
-0
.travis.yml
.travis.yml
+2
-0
admin.go
admin.go
+11
-11
conv_test.go
cache/conv_test.go
+3
-3
memcache.go
cache/memcache/memcache.go
+1
-4
redis.go
cache/redis/redis.go
+1
-1
ssdb.go
cache/ssdb/ssdb.go
+0
-9
ini.go
config/ini.go
+1
-4
ini_test.go
config/ini_test.go
+1
-1
controller.go
controller.go
+3
-3
flash_test.go
flash_test.go
+1
-1
listener.go
grace/listener.go
+1
-1
httplib.go
httplib/httplib.go
+1
-1
file.go
logs/file.go
+1
-3
jianliao.go
logs/jianliao.go
+1
-5
log.go
logs/log.go
+2
-6
slack.go
logs/slack.go
+1
-5
smtp.go
logs/smtp.go
+2
-11
namespace_test.go
namespace_test.go
+1
-4
cmd.go
orm/cmd.go
+2
-2
cmd_utils.go
orm/cmd_utils.go
+4
-4
db.go
orm/db.go
+13
-13
db_alias.go
orm/db_alias.go
+2
-2
db_tables.go
orm/db_tables.go
+6
-6
models_boot.go
orm/models_boot.go
+7
-7
models_info_f.go
orm/models_info_f.go
+3
-3
models_info_m.go
orm/models_info_m.go
+1
-1
orm.go
orm/orm.go
+7
-19
orm_querym2m.go
orm/orm_querym2m.go
+3
-7
orm_test.go
orm/orm_test.go
+2
-2
utils.go
orm/utils.go
+1
-1
router_test.go
router_test.go
+20
-20
ledis_session.go
session/ledis/ledis_session.go
+1
-4
sess_memcache.go
session/memcache/sess_memcache.go
+1
-5
sess_mysql.go
session/mysql/sess_mysql.go
+1
-4
sess_postgresql.go
session/postgres/sess_postgresql.go
+1
-5
sess_file.go
session/sess_file.go
+1
-4
sess_test.go
session/sess_test.go
+1
-1
sess_ssdb.go
session/ssdb/sess_ssdb.go
+1
-11
staticfile.go
staticfile.go
+2
-2
template.go
template.go
+5
-5
templatefunc_test.go
templatefunc_test.go
+9
-9
validation.go
validation/validation.go
+1
-1
No files found.
.gosimpleignore
0 → 100644
View file @
12dff072
github.com/astaxie/beego/*/*:S1012
github.com/astaxie/beego/*:S1012
github.com/astaxie/beego/*/*:S1007
github.com/astaxie/beego/*:S1007
\ No newline at end of file
.travis.yml
View file @
12dff072
...
@@ -33,6 +33,7 @@ install:
...
@@ -33,6 +33,7 @@ install:
-
go get github.com/ssdb/gossdb/ssdb
-
go get github.com/ssdb/gossdb/ssdb
-
go get github.com/cloudflare/golz4
-
go get github.com/cloudflare/golz4
-
go get github.com/gogo/protobuf/proto
-
go get github.com/gogo/protobuf/proto
-
go get -u honnef.co/go/tools/cmd/gosimple
-
go get -u github.com/mdempsky/unconvert
-
go get -u github.com/mdempsky/unconvert
before_script
:
before_script
:
-
psql --version
-
psql --version
...
@@ -48,6 +49,7 @@ after_script:
...
@@ -48,6 +49,7 @@ after_script:
- rm -rf ./res/var/*
- rm -rf ./res/var/*
script
:
script
:
-
go test -v ./...
-
go test -v ./...
-
gosimple -ignore "$(cat .gosimpleignore)" $(go list ./... | grep -v /vendor/)
-
unconvert $(go list ./... | grep -v /vendor/)
-
unconvert $(go list ./... | grep -v /vendor/)
addons
:
addons
:
postgresql
:
"
9.4"
postgresql
:
"
9.4"
admin.go
View file @
12dff072
...
@@ -157,8 +157,8 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
...
@@ -157,8 +157,8 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
resultList
:=
new
([][]
string
)
resultList
:=
new
([][]
string
)
for
_
,
f
:=
range
bf
{
for
_
,
f
:=
range
bf
{
var
result
=
[]
string
{
var
result
=
[]
string
{
f
mt
.
Sprintf
(
"%s"
,
f
.
pattern
)
,
f
.
pattern
,
fmt
.
Sprintf
(
"%s"
,
utils
.
GetFuncName
(
f
.
filterFunc
)
),
utils
.
GetFuncName
(
f
.
filterFunc
),
}
}
*
resultList
=
append
(
*
resultList
,
result
)
*
resultList
=
append
(
*
resultList
,
result
)
}
}
...
@@ -213,7 +213,7 @@ func printTree(resultList *[][]string, t *Tree) {
...
@@ -213,7 +213,7 @@ func printTree(resultList *[][]string, t *Tree) {
var
result
=
[]
string
{
var
result
=
[]
string
{
v
.
pattern
,
v
.
pattern
,
fmt
.
Sprintf
(
"%s"
,
v
.
methods
),
fmt
.
Sprintf
(
"%s"
,
v
.
methods
),
fmt
.
Sprintf
(
"%s"
,
v
.
controllerType
),
v
.
controllerType
.
String
(
),
}
}
*
resultList
=
append
(
*
resultList
,
result
)
*
resultList
=
append
(
*
resultList
,
result
)
}
else
if
v
.
routerType
==
routerTypeRESTFul
{
}
else
if
v
.
routerType
==
routerTypeRESTFul
{
...
@@ -287,16 +287,16 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) {
...
@@ -287,16 +287,16 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) {
for
name
,
h
:=
range
toolbox
.
AdminCheckList
{
for
name
,
h
:=
range
toolbox
.
AdminCheckList
{
if
err
:=
h
.
Check
();
err
!=
nil
{
if
err
:=
h
.
Check
();
err
!=
nil
{
result
=
[]
string
{
result
=
[]
string
{
fmt
.
Sprintf
(
"error"
)
,
"error"
,
fmt
.
Sprintf
(
"%s"
,
name
)
,
name
,
fmt
.
Sprintf
(
"%s"
,
err
.
Error
()
),
err
.
Error
(
),
}
}
}
else
{
}
else
{
result
=
[]
string
{
result
=
[]
string
{
fmt
.
Sprintf
(
"success"
)
,
"success"
,
fmt
.
Sprintf
(
"%s"
,
name
)
,
name
,
fmt
.
Sprintf
(
"OK"
)
,
"OK"
,
}
}
}
}
...
@@ -341,8 +341,8 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
...
@@ -341,8 +341,8 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
for
tname
,
tk
:=
range
toolbox
.
AdminTaskList
{
for
tname
,
tk
:=
range
toolbox
.
AdminTaskList
{
result
=
[]
string
{
result
=
[]
string
{
tname
,
tname
,
fmt
.
Sprintf
(
"%s"
,
tk
.
GetSpec
()
),
tk
.
GetSpec
(
),
fmt
.
Sprintf
(
"%s"
,
tk
.
GetStatus
()
),
tk
.
GetStatus
(
),
tk
.
GetPrev
()
.
String
(),
tk
.
GetPrev
()
.
String
(),
}
}
*
resultList
=
append
(
*
resultList
,
result
)
*
resultList
=
append
(
*
resultList
,
result
)
...
...
cache/conv_test.go
View file @
12dff072
...
@@ -118,14 +118,14 @@ func TestGetFloat64(t *testing.T) {
...
@@ -118,14 +118,14 @@ func TestGetFloat64(t *testing.T) {
func
TestGetBool
(
t
*
testing
.
T
)
{
func
TestGetBool
(
t
*
testing
.
T
)
{
var
t1
=
true
var
t1
=
true
if
true
!=
GetBool
(
t1
)
{
if
!
GetBool
(
t1
)
{
t
.
Error
(
"get bool from bool error"
)
t
.
Error
(
"get bool from bool error"
)
}
}
var
t2
=
"true"
var
t2
=
"true"
if
true
!=
GetBool
(
t2
)
{
if
!
GetBool
(
t2
)
{
t
.
Error
(
"get bool from string error"
)
t
.
Error
(
"get bool from string error"
)
}
}
if
false
!=
GetBool
(
nil
)
{
if
GetBool
(
nil
)
{
t
.
Error
(
"get bool from nil error"
)
t
.
Error
(
"get bool from nil error"
)
}
}
}
}
...
...
cache/memcache/memcache.go
View file @
12dff072
...
@@ -146,10 +146,7 @@ func (rc *Cache) IsExist(key string) bool {
...
@@ -146,10 +146,7 @@ func (rc *Cache) IsExist(key string) bool {
}
}
}
}
_
,
err
:=
rc
.
conn
.
Get
(
key
)
_
,
err
:=
rc
.
conn
.
Get
(
key
)
if
err
!=
nil
{
return
!
(
err
!=
nil
)
return
false
}
return
true
}
}
// ClearAll clear all cached in memcache.
// ClearAll clear all cached in memcache.
...
...
cache/redis/redis.go
View file @
12dff072
...
@@ -137,7 +137,7 @@ func (rc *Cache) IsExist(key string) bool {
...
@@ -137,7 +137,7 @@ func (rc *Cache) IsExist(key string) bool {
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
}
}
if
v
==
false
{
if
!
v
{
if
_
,
err
=
rc
.
do
(
"HDEL"
,
rc
.
key
,
key
);
err
!=
nil
{
if
_
,
err
=
rc
.
do
(
"HDEL"
,
rc
.
key
,
key
);
err
!=
nil
{
return
false
return
false
}
}
...
...
cache/ssdb/ssdb.go
View file @
12dff072
...
@@ -71,10 +71,7 @@ func (rc *Cache) DelMulti(keys []string) error {
...
@@ -71,10 +71,7 @@ func (rc *Cache) DelMulti(keys []string) error {
}
}
}
}
_
,
err
:=
rc
.
conn
.
Do
(
"multi_del"
,
keys
)
_
,
err
:=
rc
.
conn
.
Do
(
"multi_del"
,
keys
)
if
err
!=
nil
{
return
err
return
err
}
return
nil
}
}
// Put put value to memcache. only support string.
// Put put value to memcache. only support string.
...
@@ -113,10 +110,7 @@ func (rc *Cache) Delete(key string) error {
...
@@ -113,10 +110,7 @@ func (rc *Cache) Delete(key string) error {
}
}
}
}
_
,
err
:=
rc
.
conn
.
Del
(
key
)
_
,
err
:=
rc
.
conn
.
Del
(
key
)
if
err
!=
nil
{
return
err
return
err
}
return
nil
}
}
// Incr increase counter.
// Incr increase counter.
...
@@ -229,10 +223,7 @@ func (rc *Cache) connectInit() error {
...
@@ -229,10 +223,7 @@ func (rc *Cache) connectInit() error {
}
}
var
err
error
var
err
error
rc
.
conn
,
err
=
ssdb
.
Connect
(
host
,
port
)
rc
.
conn
,
err
=
ssdb
.
Connect
(
host
,
port
)
if
err
!=
nil
{
return
err
return
err
}
return
nil
}
}
func
init
()
{
func
init
()
{
...
...
config/ini.go
View file @
12dff072
...
@@ -397,11 +397,8 @@ func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
...
@@ -397,11 +397,8 @@ func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
}
}
}
}
}
}
_
,
err
=
buf
.
WriteTo
(
f
)
if
_
,
err
=
buf
.
WriteTo
(
f
);
err
!=
nil
{
return
err
return
err
}
return
nil
}
}
// Set writes a new value for key.
// Set writes a new value for key.
...
...
config/ini_test.go
View file @
12dff072
...
@@ -181,7 +181,7 @@ name=mysql
...
@@ -181,7 +181,7 @@ name=mysql
cfgData
:=
string
(
data
)
cfgData
:=
string
(
data
)
datas
:=
strings
.
Split
(
saveResult
,
"
\n
"
)
datas
:=
strings
.
Split
(
saveResult
,
"
\n
"
)
for
_
,
line
:=
range
datas
{
for
_
,
line
:=
range
datas
{
if
strings
.
Contains
(
cfgData
,
line
+
"
\n
"
)
==
false
{
if
!
strings
.
Contains
(
cfgData
,
line
+
"
\n
"
)
{
t
.
Fatalf
(
"different after save ini config file. need contains %q"
,
line
)
t
.
Fatalf
(
"different after save ini config file. need contains %q"
,
line
)
}
}
}
}
...
...
controller.go
View file @
12dff072
...
@@ -223,7 +223,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
...
@@ -223,7 +223,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
}
}
buf
.
Reset
()
buf
.
Reset
()
ExecuteViewPathTemplate
(
&
buf
,
c
.
Layout
,
c
.
viewPath
()
,
c
.
Data
)
ExecuteViewPathTemplate
(
&
buf
,
c
.
Layout
,
c
.
viewPath
()
,
c
.
Data
)
}
}
return
buf
.
Bytes
(),
err
return
buf
.
Bytes
(),
err
}
}
...
@@ -249,7 +249,7 @@ func (c *Controller) renderTemplate() (bytes.Buffer, error) {
...
@@ -249,7 +249,7 @@ func (c *Controller) renderTemplate() (bytes.Buffer, error) {
}
}
}
}
}
}
BuildTemplate
(
c
.
viewPath
()
,
buildFiles
...
)
BuildTemplate
(
c
.
viewPath
(),
buildFiles
...
)
}
}
return
buf
,
ExecuteViewPathTemplate
(
&
buf
,
c
.
TplName
,
c
.
viewPath
(),
c
.
Data
)
return
buf
,
ExecuteViewPathTemplate
(
&
buf
,
c
.
TplName
,
c
.
viewPath
(),
c
.
Data
)
}
}
...
@@ -314,7 +314,7 @@ func (c *Controller) ServeJSON(encoding ...bool) {
...
@@ -314,7 +314,7 @@ func (c *Controller) ServeJSON(encoding ...bool) {
if
BConfig
.
RunMode
==
PROD
{
if
BConfig
.
RunMode
==
PROD
{
hasIndent
=
false
hasIndent
=
false
}
}
if
len
(
encoding
)
>
0
&&
encoding
[
0
]
==
true
{
if
len
(
encoding
)
>
0
&&
encoding
[
0
]
{
hasEncoding
=
true
hasEncoding
=
true
}
}
c
.
Ctx
.
Output
.
JSON
(
c
.
Data
[
"json"
],
hasIndent
,
hasEncoding
)
c
.
Ctx
.
Output
.
JSON
(
c
.
Data
[
"json"
],
hasIndent
,
hasEncoding
)
...
...
flash_test.go
View file @
12dff072
...
@@ -48,7 +48,7 @@ func TestFlashHeader(t *testing.T) {
...
@@ -48,7 +48,7 @@ func TestFlashHeader(t *testing.T) {
// match for the expected header
// match for the expected header
res
:=
strings
.
Contains
(
sc
,
"BEEGO_FLASH=%00notice%23BEEGOFLASH%23TestFlashString%00"
)
res
:=
strings
.
Contains
(
sc
,
"BEEGO_FLASH=%00notice%23BEEGOFLASH%23TestFlashString%00"
)
// validate the assertion
// validate the assertion
if
res
!=
true
{
if
!
res
{
t
.
Errorf
(
"TestFlashHeader() unable to validate flash message"
)
t
.
Errorf
(
"TestFlashHeader() unable to validate flash message"
)
}
}
}
}
grace/listener.go
View file @
12dff072
...
@@ -21,7 +21,7 @@ func newGraceListener(l net.Listener, srv *Server) (el *graceListener) {
...
@@ -21,7 +21,7 @@ func newGraceListener(l net.Listener, srv *Server) (el *graceListener) {
server
:
srv
,
server
:
srv
,
}
}
go
func
()
{
go
func
()
{
_
=
<-
el
.
stop
<-
el
.
stop
el
.
stopped
=
true
el
.
stopped
=
true
el
.
stop
<-
el
.
Listener
.
Close
()
el
.
stop
<-
el
.
Listener
.
Close
()
}()
}()
...
...
httplib/httplib.go
View file @
12dff072
...
@@ -335,7 +335,7 @@ func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)
...
@@ -335,7 +335,7 @@ func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)
func
(
b
*
BeegoHTTPRequest
)
buildURL
(
paramBody
string
)
{
func
(
b
*
BeegoHTTPRequest
)
buildURL
(
paramBody
string
)
{
// build GET url with query string
// build GET url with query string
if
b
.
req
.
Method
==
"GET"
&&
len
(
paramBody
)
>
0
{
if
b
.
req
.
Method
==
"GET"
&&
len
(
paramBody
)
>
0
{
if
strings
.
Index
(
b
.
url
,
"?"
)
!=
-
1
{
if
strings
.
Contains
(
b
.
url
,
"?"
)
{
b
.
url
+=
"&"
+
paramBody
b
.
url
+=
"&"
+
paramBody
}
else
{
}
else
{
b
.
url
=
b
.
url
+
"?"
+
paramBody
b
.
url
=
b
.
url
+
"?"
+
paramBody
...
...
logs/file.go
View file @
12dff072
...
@@ -193,8 +193,7 @@ func (w *fileLogWriter) dailyRotate(openTime time.Time) {
...
@@ -193,8 +193,7 @@ func (w *fileLogWriter) dailyRotate(openTime time.Time) {
y
,
m
,
d
:=
openTime
.
Add
(
24
*
time
.
Hour
)
.
Date
()
y
,
m
,
d
:=
openTime
.
Add
(
24
*
time
.
Hour
)
.
Date
()
nextDay
:=
time
.
Date
(
y
,
m
,
d
,
0
,
0
,
0
,
0
,
openTime
.
Location
())
nextDay
:=
time
.
Date
(
y
,
m
,
d
,
0
,
0
,
0
,
0
,
openTime
.
Location
())
tm
:=
time
.
NewTimer
(
time
.
Duration
(
nextDay
.
UnixNano
()
-
openTime
.
UnixNano
()
+
100
))
tm
:=
time
.
NewTimer
(
time
.
Duration
(
nextDay
.
UnixNano
()
-
openTime
.
UnixNano
()
+
100
))
select
{
<-
tm
.
C
case
<-
tm
.
C
:
w
.
Lock
()
w
.
Lock
()
if
w
.
needRotate
(
0
,
time
.
Now
()
.
Day
())
{
if
w
.
needRotate
(
0
,
time
.
Now
()
.
Day
())
{
if
err
:=
w
.
doRotate
(
time
.
Now
());
err
!=
nil
{
if
err
:=
w
.
doRotate
(
time
.
Now
());
err
!=
nil
{
...
@@ -202,7 +201,6 @@ func (w *fileLogWriter) dailyRotate(openTime time.Time) {
...
@@ -202,7 +201,6 @@ func (w *fileLogWriter) dailyRotate(openTime time.Time) {
}
}
}
}
w
.
Unlock
()
w
.
Unlock
()
}
}
}
func
(
w
*
fileLogWriter
)
lines
()
(
int
,
error
)
{
func
(
w
*
fileLogWriter
)
lines
()
(
int
,
error
)
{
...
...
logs/jianliao.go
View file @
12dff072
...
@@ -25,11 +25,7 @@ func newJLWriter() Logger {
...
@@ -25,11 +25,7 @@ func newJLWriter() Logger {
// Init JLWriter with json config string
// Init JLWriter with json config string
func
(
s
*
JLWriter
)
Init
(
jsonconfig
string
)
error
{
func
(
s
*
JLWriter
)
Init
(
jsonconfig
string
)
error
{
err
:=
json
.
Unmarshal
([]
byte
(
jsonconfig
),
s
)
return
json
.
Unmarshal
([]
byte
(
jsonconfig
),
s
)
if
err
!=
nil
{
return
err
}
return
nil
}
}
// WriteMsg write message in smtp writer.
// WriteMsg write message in smtp writer.
...
...
logs/log.go
View file @
12dff072
...
@@ -275,7 +275,7 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error
...
@@ -275,7 +275,7 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error
line
=
0
line
=
0
}
}
_
,
filename
:=
path
.
Split
(
file
)
_
,
filename
:=
path
.
Split
(
file
)
msg
=
"["
+
filename
+
":"
+
strconv
.
FormatInt
(
int64
(
line
),
10
)
+
"] "
+
msg
msg
=
"["
+
filename
+
":"
+
strconv
.
Itoa
(
line
)
+
"] "
+
msg
}
}
//set level info in front of filename info
//set level info in front of filename info
...
@@ -561,11 +561,7 @@ func SetLogFuncCallDepth(d int) {
...
@@ -561,11 +561,7 @@ func SetLogFuncCallDepth(d int) {
// SetLogger sets a new logger.
// SetLogger sets a new logger.
func
SetLogger
(
adapter
string
,
config
...
string
)
error
{
func
SetLogger
(
adapter
string
,
config
...
string
)
error
{
err
:=
beeLogger
.
SetLogger
(
adapter
,
config
...
)
return
beeLogger
.
SetLogger
(
adapter
,
config
...
)
if
err
!=
nil
{
return
err
}
return
nil
}
}
// Emergency logs a message at emergency level.
// Emergency logs a message at emergency level.
...
...
logs/slack.go
View file @
12dff072
...
@@ -21,11 +21,7 @@ func newSLACKWriter() Logger {
...
@@ -21,11 +21,7 @@ func newSLACKWriter() Logger {
// Init SLACKWriter with json config string
// Init SLACKWriter with json config string
func
(
s
*
SLACKWriter
)
Init
(
jsonconfig
string
)
error
{
func
(
s
*
SLACKWriter
)
Init
(
jsonconfig
string
)
error
{
err
:=
json
.
Unmarshal
([]
byte
(
jsonconfig
),
s
)
return
json
.
Unmarshal
([]
byte
(
jsonconfig
),
s
)
if
err
!=
nil
{
return
err
}
return
nil
}
}
// WriteMsg write message in smtp writer.
// WriteMsg write message in smtp writer.
...
...
logs/smtp.go
View file @
12dff072
...
@@ -52,11 +52,7 @@ func newSMTPWriter() Logger {
...
@@ -52,11 +52,7 @@ func newSMTPWriter() Logger {
// "level":LevelError
// "level":LevelError
// }
// }
func
(
s
*
SMTPWriter
)
Init
(
jsonconfig
string
)
error
{
func
(
s
*
SMTPWriter
)
Init
(
jsonconfig
string
)
error
{
err
:=
json
.
Unmarshal
([]
byte
(
jsonconfig
),
s
)
return
json
.
Unmarshal
([]
byte
(
jsonconfig
),
s
)
if
err
!=
nil
{
return
err
}
return
nil
}
}
func
(
s
*
SMTPWriter
)
getSMTPAuth
(
host
string
)
smtp
.
Auth
{
func
(
s
*
SMTPWriter
)
getSMTPAuth
(
host
string
)
smtp
.
Auth
{
...
@@ -116,12 +112,7 @@ func (s *SMTPWriter) sendMail(hostAddressWithPort string, auth smtp.Auth, fromAd
...
@@ -116,12 +112,7 @@ func (s *SMTPWriter) sendMail(hostAddressWithPort string, auth smtp.Auth, fromAd
return
err
return
err
}
}
err
=
client
.
Quit
()
return
client
.
Quit
()
if
err
!=
nil
{
return
err
}
return
nil
}
}
// WriteMsg write message in smtp writer.
// WriteMsg write message in smtp writer.
...
...
namespace_test.go
View file @
12dff072
...
@@ -139,10 +139,7 @@ func TestNamespaceCond(t *testing.T) {
...
@@ -139,10 +139,7 @@ func TestNamespaceCond(t *testing.T) {
ns
:=
NewNamespace
(
"/v2"
)
ns
:=
NewNamespace
(
"/v2"
)
ns
.
Cond
(
func
(
ctx
*
context
.
Context
)
bool
{
ns
.
Cond
(
func
(
ctx
*
context
.
Context
)
bool
{
if
ctx
.
Input
.
Domain
()
==
"beego.me"
{
return
ctx
.
Input
.
Domain
()
==
"beego.me"
return
true
}
return
false
})
.
})
.
AutoRouter
(
&
TestController
{})
AutoRouter
(
&
TestController
{})
AddNamespace
(
ns
)
AddNamespace
(
ns
)
...
...
orm/cmd.go
View file @
12dff072
...
@@ -150,7 +150,7 @@ func (d *commandSyncDb) Run() error {
...
@@ -150,7 +150,7 @@ func (d *commandSyncDb) Run() error {
}
}
for
_
,
fi
:=
range
mi
.
fields
.
fieldsDB
{
for
_
,
fi
:=
range
mi
.
fields
.
fieldsDB
{
if
_
,
ok
:=
columns
[
fi
.
column
];
ok
==
false
{
if
_
,
ok
:=
columns
[
fi
.
column
];
!
ok
{
fields
=
append
(
fields
,
fi
)
fields
=
append
(
fields
,
fi
)
}
}
}
}
...
@@ -175,7 +175,7 @@ func (d *commandSyncDb) Run() error {
...
@@ -175,7 +175,7 @@ func (d *commandSyncDb) Run() error {
}
}
for
_
,
idx
:=
range
indexes
[
mi
.
table
]
{
for
_
,
idx
:=
range
indexes
[
mi
.
table
]
{
if
d
.
al
.
DbBaser
.
IndexExists
(
db
,
idx
.
Table
,
idx
.
Name
)
==
false
{
if
!
d
.
al
.
DbBaser
.
IndexExists
(
db
,
idx
.
Table
,
idx
.
Name
)
{
if
!
d
.
noInfo
{
if
!
d
.
noInfo
{
fmt
.
Printf
(
"create index `%s` for table `%s`
\n
"
,
idx
.
Name
,
idx
.
Table
)
fmt
.
Printf
(
"create index `%s` for table `%s`
\n
"
,
idx
.
Name
,
idx
.
Table
)
}
}
...
...
orm/cmd_utils.go
View file @
12dff072
...
@@ -89,7 +89,7 @@ checkColumn:
...
@@ -89,7 +89,7 @@ checkColumn:
col
=
T
[
"float64"
]
col
=
T
[
"float64"
]
case
TypeDecimalField
:
case
TypeDecimalField
:
s
:=
T
[
"float64-decimal"
]
s
:=
T
[
"float64-decimal"
]
if
strings
.
Index
(
s
,
"%d"
)
==
-
1
{
if
!
strings
.
Contains
(
s
,
"%d"
)
{
col
=
s
col
=
s
}
else
{
}
else
{
col
=
fmt
.
Sprintf
(
s
,
fi
.
digits
,
fi
.
decimals
)
col
=
fmt
.
Sprintf
(
s
,
fi
.
digits
,
fi
.
decimals
)
...
@@ -120,7 +120,7 @@ func getColumnAddQuery(al *alias, fi *fieldInfo) string {
...
@@ -120,7 +120,7 @@ func getColumnAddQuery(al *alias, fi *fieldInfo) string {
Q
:=
al
.
DbBaser
.
TableQuote
()
Q
:=
al
.
DbBaser
.
TableQuote
()
typ
:=
getColumnTyp
(
al
,
fi
)
typ
:=
getColumnTyp
(
al
,
fi
)
if
fi
.
null
==
false
{
if
!
fi
.
null
{
typ
+=
" "
+
"NOT NULL"
typ
+=
" "
+
"NOT NULL"
}
}
...
@@ -172,7 +172,7 @@ func getDbCreateSQL(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
...
@@ -172,7 +172,7 @@ func getDbCreateSQL(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
}
else
{
}
else
{
column
+=
col
column
+=
col
if
fi
.
null
==
false
{
if
!
fi
.
null
{
column
+=
" "
+
"NOT NULL"
column
+=
" "
+
"NOT NULL"
}
}
...
@@ -192,7 +192,7 @@ func getDbCreateSQL(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
...
@@ -192,7 +192,7 @@ func getDbCreateSQL(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
}
}
}
}
if
strings
.
Index
(
column
,
"%COL%"
)
!=
-
1
{
if
strings
.
Contains
(
column
,
"%COL%"
)
{
column
=
strings
.
Replace
(
column
,
"%COL%"
,
fi
.
column
,
-
1
)
column
=
strings
.
Replace
(
column
,
"%COL%"
,
fi
.
column
,
-
1
)
}
}
...
...
orm/db.go
View file @
12dff072
...
@@ -87,7 +87,7 @@ func (d *dbBase) collectValues(mi *modelInfo, ind reflect.Value, cols []string,
...
@@ -87,7 +87,7 @@ func (d *dbBase) collectValues(mi *modelInfo, ind reflect.Value, cols []string,
}
else
{
}
else
{
panic
(
fmt
.
Errorf
(
"wrong db field/column name `%s` for model `%s`"
,
column
,
mi
.
fullName
))
panic
(
fmt
.
Errorf
(
"wrong db field/column name `%s` for model `%s`"
,
column
,
mi
.
fullName
))
}
}
if
fi
.
dbcol
==
false
||
fi
.
auto
&&
skipAuto
{
if
!
fi
.
dbcol
||
fi
.
auto
&&
skipAuto
{
continue
continue
}
}
value
,
err
:=
d
.
collectFieldValue
(
mi
,
fi
,
ind
,
insert
,
tz
)
value
,
err
:=
d
.
collectFieldValue
(
mi
,
fi
,
ind
,
insert
,
tz
)
...
@@ -224,7 +224,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
...
@@ -224,7 +224,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
value
=
nil
value
=
nil
}
}
}
}
if
fi
.
null
==
false
&&
value
==
nil
{
if
!
fi
.
null
&&
value
==
nil
{
return
nil
,
fmt
.
Errorf
(
"field `%s` cannot be NULL"
,
fi
.
fullName
)
return
nil
,
fmt
.
Errorf
(
"field `%s` cannot be NULL"
,
fi
.
fullName
)
}
}
}
}
...
@@ -271,7 +271,7 @@ func (d *dbBase) PrepareInsert(q dbQuerier, mi *modelInfo) (stmtQuerier, string,
...
@@ -271,7 +271,7 @@ func (d *dbBase) PrepareInsert(q dbQuerier, mi *modelInfo) (stmtQuerier, string,
dbcols
:=
make
([]
string
,
0
,
len
(
mi
.
fields
.
dbcols
))
dbcols
:=
make
([]
string
,
0
,
len
(
mi
.
fields
.
dbcols
))
marks
:=
make
([]
string
,
0
,
len
(
mi
.
fields
.
dbcols
))
marks
:=
make
([]
string
,
0
,
len
(
mi
.
fields
.
dbcols
))
for
_
,
fi
:=
range
mi
.
fields
.
fieldsDB
{
for
_
,
fi
:=
range
mi
.
fields
.
fieldsDB
{
if
fi
.
auto
==
false
{
if
!
fi
.
auto
{
dbcols
=
append
(
dbcols
,
fi
.
column
)
dbcols
=
append
(
dbcols
,
fi
.
column
)
marks
=
append
(
marks
,
"?"
)
marks
=
append
(
marks
,
"?"
)
}
}
...
@@ -326,7 +326,7 @@ func (d *dbBase) Read(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Lo
...
@@ -326,7 +326,7 @@ func (d *dbBase) Read(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Lo
}
else
{
}
else
{
// default use pk value as where condtion.
// default use pk value as where condtion.
pkColumn
,
pkValue
,
ok
:=
getExistPk
(
mi
,
ind
)
pkColumn
,
pkValue
,
ok
:=
getExistPk
(
mi
,
ind
)
if
ok
==
false
{
if
!
ok
{
return
ErrMissPK
return
ErrMissPK
}
}
whereCols
=
[]
string
{
pkColumn
}
whereCols
=
[]
string
{
pkColumn
}
...
@@ -601,7 +601,7 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a
...
@@ -601,7 +601,7 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a
// execute update sql dbQuerier with given struct reflect.Value.
// execute update sql dbQuerier with given struct reflect.Value.
func
(
d
*
dbBase
)
Update
(
q
dbQuerier
,
mi
*
modelInfo
,
ind
reflect
.
Value
,
tz
*
time
.
Location
,
cols
[]
string
)
(
int64
,
error
)
{
func
(
d
*
dbBase
)
Update
(
q
dbQuerier
,
mi
*
modelInfo
,
ind
reflect
.
Value
,
tz
*
time
.
Location
,
cols
[]
string
)
(
int64
,
error
)
{
pkName
,
pkValue
,
ok
:=
getExistPk
(
mi
,
ind
)
pkName
,
pkValue
,
ok
:=
getExistPk
(
mi
,
ind
)
if
ok
==
false
{
if
!
ok
{
return
0
,
ErrMissPK
return
0
,
ErrMissPK
}
}
...
@@ -654,7 +654,7 @@ func (d *dbBase) Delete(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.
...
@@ -654,7 +654,7 @@ func (d *dbBase) Delete(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.
}
else
{
}
else
{
// default use pk value as where condtion.
// default use pk value as where condtion.
pkColumn
,
pkValue
,
ok
:=
getExistPk
(
mi
,
ind
)
pkColumn
,
pkValue
,
ok
:=
getExistPk
(
mi
,
ind
)
if
ok
==
false
{
if
!
ok
{
return
0
,
ErrMissPK
return
0
,
ErrMissPK
}
}
whereCols
=
[]
string
{
pkColumn
}
whereCols
=
[]
string
{
pkColumn
}
...
@@ -699,7 +699,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
...
@@ -699,7 +699,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
columns
:=
make
([]
string
,
0
,
len
(
params
))
columns
:=
make
([]
string
,
0
,
len
(
params
))
values
:=
make
([]
interface
{},
0
,
len
(
params
))
values
:=
make
([]
interface
{},
0
,
len
(
params
))
for
col
,
val
:=
range
params
{
for
col
,
val
:=
range
params
{
if
fi
,
ok
:=
mi
.
fields
.
GetByAny
(
col
);
ok
==
false
||
fi
.
dbcol
==
false
{
if
fi
,
ok
:=
mi
.
fields
.
GetByAny
(
col
);
!
ok
||
!
fi
.
dbcol
{
panic
(
fmt
.
Errorf
(
"wrong field/column name `%s`"
,
col
))
panic
(
fmt
.
Errorf
(
"wrong field/column name `%s`"
,
col
))
}
else
{
}
else
{
columns
=
append
(
columns
,
fi
.
column
)
columns
=
append
(
columns
,
fi
.
column
)
...
@@ -929,7 +929,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
...
@@ -929,7 +929,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
if
hasRel
{
if
hasRel
{
for
_
,
fi
:=
range
mi
.
fields
.
fieldsDB
{
for
_
,
fi
:=
range
mi
.
fields
.
fieldsDB
{
if
fi
.
fieldType
&
IsRelField
>
0
{
if
fi
.
fieldType
&
IsRelField
>
0
{
if
maps
[
fi
.
column
]
==
false
{
if
!
maps
[
fi
.
column
]
{
tCols
=
append
(
tCols
,
fi
.
column
)
tCols
=
append
(
tCols
,
fi
.
column
)
}
}
}
}
...
@@ -987,7 +987,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
...
@@ -987,7 +987,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
var
cnt
int64
var
cnt
int64
for
rs
.
Next
()
{
for
rs
.
Next
()
{
if
one
&&
cnt
==
0
||
one
==
fals
e
{
if
one
&&
cnt
==
0
||
!
on
e
{
if
err
:=
rs
.
Scan
(
refs
...
);
err
!=
nil
{
if
err
:=
rs
.
Scan
(
refs
...
);
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -1067,7 +1067,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
...
@@ -1067,7 +1067,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
cnt
++
cnt
++
}
}
if
one
==
fals
e
{
if
!
on
e
{
if
cnt
>
0
{
if
cnt
>
0
{
ind
.
Set
(
slice
)
ind
.
Set
(
slice
)
}
else
{
}
else
{
...
@@ -1357,7 +1357,7 @@ end:
...
@@ -1357,7 +1357,7 @@ end:
func
(
d
*
dbBase
)
setFieldValue
(
fi
*
fieldInfo
,
value
interface
{},
field
reflect
.
Value
)
(
interface
{},
error
)
{
func
(
d
*
dbBase
)
setFieldValue
(
fi
*
fieldInfo
,
value
interface
{},
field
reflect
.
Value
)
(
interface
{},
error
)
{
fieldType
:=
fi
.
fieldType
fieldType
:=
fi
.
fieldType
isNative
:=
fi
.
isFielder
==
false
isNative
:=
!
fi
.
isFielder
setValue
:
setValue
:
switch
{
switch
{
...
@@ -1533,7 +1533,7 @@ setValue:
...
@@ -1533,7 +1533,7 @@ setValue:
}
}
}
}
if
isNative
==
fals
e
{
if
!
isNativ
e
{
fd
:=
field
.
Addr
()
.
Interface
()
.
(
Fielder
)
fd
:=
field
.
Addr
()
.
Interface
()
.
(
Fielder
)
err
:=
fd
.
SetRaw
(
value
)
err
:=
fd
.
SetRaw
(
value
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1594,7 +1594,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
...
@@ -1594,7 +1594,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
infos
=
make
([]
*
fieldInfo
,
0
,
len
(
exprs
))
infos
=
make
([]
*
fieldInfo
,
0
,
len
(
exprs
))
for
_
,
ex
:=
range
exprs
{
for
_
,
ex
:=
range
exprs
{
index
,
name
,
fi
,
suc
:=
tables
.
parseExprs
(
mi
,
strings
.
Split
(
ex
,
ExprSep
))
index
,
name
,
fi
,
suc
:=
tables
.
parseExprs
(
mi
,
strings
.
Split
(
ex
,
ExprSep
))
if
suc
==
false
{
if
!
suc
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
ex
))
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
ex
))
}
}
cols
=
append
(
cols
,
fmt
.
Sprintf
(
"%s.%s%s%s %s%s%s"
,
index
,
Q
,
fi
.
column
,
Q
,
Q
,
name
,
Q
))
cols
=
append
(
cols
,
fmt
.
Sprintf
(
"%s.%s%s%s %s%s%s"
,
index
,
Q
,
fi
.
column
,
Q
,
Q
,
name
,
Q
))
...
...
orm/db_alias.go
View file @
12dff072
...
@@ -186,7 +186,7 @@ func addAliasWthDB(aliasName, driverName string, db *sql.DB) (*alias, error) {
...
@@ -186,7 +186,7 @@ func addAliasWthDB(aliasName, driverName string, db *sql.DB) (*alias, error) {
return
nil
,
fmt
.
Errorf
(
"register db Ping `%s`, %s"
,
aliasName
,
err
.
Error
())
return
nil
,
fmt
.
Errorf
(
"register db Ping `%s`, %s"
,
aliasName
,
err
.
Error
())
}
}
if
dataBaseCache
.
add
(
aliasName
,
al
)
==
false
{
if
!
dataBaseCache
.
add
(
aliasName
,
al
)
{
return
nil
,
fmt
.
Errorf
(
"DataBase alias name `%s` already registered, cannot reuse"
,
aliasName
)
return
nil
,
fmt
.
Errorf
(
"DataBase alias name `%s` already registered, cannot reuse"
,
aliasName
)
}
}
...
@@ -244,7 +244,7 @@ end:
...
@@ -244,7 +244,7 @@ end:
// RegisterDriver Register a database driver use specify driver name, this can be definition the driver is which database type.
// RegisterDriver Register a database driver use specify driver name, this can be definition the driver is which database type.
func
RegisterDriver
(
driverName
string
,
typ
DriverType
)
error
{
func
RegisterDriver
(
driverName
string
,
typ
DriverType
)
error
{
if
t
,
ok
:=
drivers
[
driverName
];
ok
==
false
{
if
t
,
ok
:=
drivers
[
driverName
];
!
ok
{
drivers
[
driverName
]
=
typ
drivers
[
driverName
]
=
typ
}
else
{
}
else
{
if
t
!=
typ
{
if
t
!=
typ
{
...
...
orm/db_tables.go
View file @
12dff072
...
@@ -63,7 +63,7 @@ func (t *dbTables) set(names []string, mi *modelInfo, fi *fieldInfo, inner bool)
...
@@ -63,7 +63,7 @@ func (t *dbTables) set(names []string, mi *modelInfo, fi *fieldInfo, inner bool)
// add table info to collection.
// add table info to collection.
func
(
t
*
dbTables
)
add
(
names
[]
string
,
mi
*
modelInfo
,
fi
*
fieldInfo
,
inner
bool
)
(
*
dbTable
,
bool
)
{
func
(
t
*
dbTables
)
add
(
names
[]
string
,
mi
*
modelInfo
,
fi
*
fieldInfo
,
inner
bool
)
(
*
dbTable
,
bool
)
{
name
:=
strings
.
Join
(
names
,
ExprSep
)
name
:=
strings
.
Join
(
names
,
ExprSep
)
if
_
,
ok
:=
t
.
tablesM
[
name
];
ok
==
false
{
if
_
,
ok
:=
t
.
tablesM
[
name
];
!
ok
{
i
:=
len
(
t
.
tables
)
+
1
i
:=
len
(
t
.
tables
)
+
1
jt
:=
&
dbTable
{
i
,
fmt
.
Sprintf
(
"T%d"
,
i
),
name
,
names
,
false
,
inner
,
mi
,
fi
,
nil
}
jt
:=
&
dbTable
{
i
,
fmt
.
Sprintf
(
"T%d"
,
i
),
name
,
names
,
false
,
inner
,
mi
,
fi
,
nil
}
t
.
tablesM
[
name
]
=
jt
t
.
tablesM
[
name
]
=
jt
...
@@ -261,7 +261,7 @@ loopFor:
...
@@ -261,7 +261,7 @@ loopFor:
fiN
,
okN
=
mmi
.
fields
.
GetByAny
(
exprs
[
i
+
1
])
fiN
,
okN
=
mmi
.
fields
.
GetByAny
(
exprs
[
i
+
1
])
}
}
if
isRel
&&
(
fi
.
mi
.
isThrough
==
false
||
num
!=
i
)
{
if
isRel
&&
(
!
fi
.
mi
.
isThrough
||
num
!=
i
)
{
if
fi
.
null
||
t
.
skipEnd
{
if
fi
.
null
||
t
.
skipEnd
{
inner
=
false
inner
=
false
}
}
...
@@ -364,7 +364,7 @@ func (t *dbTables) getCondSQL(cond *Condition, sub bool, tz *time.Location) (whe
...
@@ -364,7 +364,7 @@ func (t *dbTables) getCondSQL(cond *Condition, sub bool, tz *time.Location) (whe
}
}
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
mi
,
exprs
)
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
mi
,
exprs
)
if
suc
==
false
{
if
!
suc
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
p
.
exprs
,
ExprSep
)))
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
p
.
exprs
,
ExprSep
)))
}
}
...
@@ -383,7 +383,7 @@ func (t *dbTables) getCondSQL(cond *Condition, sub bool, tz *time.Location) (whe
...
@@ -383,7 +383,7 @@ func (t *dbTables) getCondSQL(cond *Condition, sub bool, tz *time.Location) (whe
}
}
}
}
if
sub
==
false
&&
where
!=
""
{
if
!
sub
&&
where
!=
""
{
where
=
"WHERE "
+
where
where
=
"WHERE "
+
where
}
}
...
@@ -403,7 +403,7 @@ func (t *dbTables) getGroupSQL(groups []string) (groupSQL string) {
...
@@ -403,7 +403,7 @@ func (t *dbTables) getGroupSQL(groups []string) (groupSQL string) {
exprs
:=
strings
.
Split
(
group
,
ExprSep
)
exprs
:=
strings
.
Split
(
group
,
ExprSep
)
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
t
.
mi
,
exprs
)
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
t
.
mi
,
exprs
)
if
suc
==
false
{
if
!
suc
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
exprs
,
ExprSep
)))
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
exprs
,
ExprSep
)))
}
}
...
@@ -432,7 +432,7 @@ func (t *dbTables) getOrderSQL(orders []string) (orderSQL string) {
...
@@ -432,7 +432,7 @@ func (t *dbTables) getOrderSQL(orders []string) (orderSQL string) {
exprs
:=
strings
.
Split
(
order
,
ExprSep
)
exprs
:=
strings
.
Split
(
order
,
ExprSep
)
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
t
.
mi
,
exprs
)
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
t
.
mi
,
exprs
)
if
suc
==
false
{
if
!
suc
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
exprs
,
ExprSep
)))
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
exprs
,
ExprSep
)))
}
}
...
...
orm/models_boot.go
View file @
12dff072
...
@@ -128,7 +128,7 @@ func bootStrap() {
...
@@ -128,7 +128,7 @@ func bootStrap() {
if
i
:=
strings
.
LastIndex
(
fi
.
relThrough
,
"."
);
i
!=
-
1
&&
len
(
fi
.
relThrough
)
>
(
i
+
1
)
{
if
i
:=
strings
.
LastIndex
(
fi
.
relThrough
,
"."
);
i
!=
-
1
&&
len
(
fi
.
relThrough
)
>
(
i
+
1
)
{
pn
:=
fi
.
relThrough
[
:
i
]
pn
:=
fi
.
relThrough
[
:
i
]
rmi
,
ok
:=
modelCache
.
getByFullName
(
fi
.
relThrough
)
rmi
,
ok
:=
modelCache
.
getByFullName
(
fi
.
relThrough
)
if
ok
==
false
||
pn
!=
rmi
.
pkg
{
if
!
ok
||
pn
!=
rmi
.
pkg
{
err
=
fmt
.
Errorf
(
"field `%s` wrong rel_through value `%s` cannot find table"
,
fi
.
fullName
,
fi
.
relThrough
)
err
=
fmt
.
Errorf
(
"field `%s` wrong rel_through value `%s` cannot find table"
,
fi
.
fullName
,
fi
.
relThrough
)
goto
end
goto
end
}
}
...
@@ -171,7 +171,7 @@ func bootStrap() {
...
@@ -171,7 +171,7 @@ func bootStrap() {
break
break
}
}
}
}
if
inModel
==
false
{
if
!
inModel
{
rmi
:=
fi
.
relModelInfo
rmi
:=
fi
.
relModelInfo
ffi
:=
new
(
fieldInfo
)
ffi
:=
new
(
fieldInfo
)
ffi
.
name
=
mi
.
name
ffi
.
name
=
mi
.
name
...
@@ -185,7 +185,7 @@ func bootStrap() {
...
@@ -185,7 +185,7 @@ func bootStrap() {
}
else
{
}
else
{
ffi
.
fieldType
=
RelReverseMany
ffi
.
fieldType
=
RelReverseMany
}
}
if
rmi
.
fields
.
Add
(
ffi
)
==
false
{
if
!
rmi
.
fields
.
Add
(
ffi
)
{
added
:=
false
added
:=
false
for
cnt
:=
0
;
cnt
<
5
;
cnt
++
{
for
cnt
:=
0
;
cnt
<
5
;
cnt
++
{
ffi
.
name
=
fmt
.
Sprintf
(
"%s%d"
,
mi
.
name
,
cnt
)
ffi
.
name
=
fmt
.
Sprintf
(
"%s%d"
,
mi
.
name
,
cnt
)
...
@@ -195,7 +195,7 @@ func bootStrap() {
...
@@ -195,7 +195,7 @@ func bootStrap() {
break
break
}
}
}
}
if
added
==
false
{
if
!
added
{
panic
(
fmt
.
Errorf
(
"cannot generate auto reverse field info `%s` to `%s`"
,
fi
.
fullName
,
ffi
.
fullName
))
panic
(
fmt
.
Errorf
(
"cannot generate auto reverse field info `%s` to `%s`"
,
fi
.
fullName
,
ffi
.
fullName
))
}
}
}
}
...
@@ -248,7 +248,7 @@ func bootStrap() {
...
@@ -248,7 +248,7 @@ func bootStrap() {
break
mForA
break
mForA
}
}
}
}
if
found
==
false
{
if
!
found
{
err
=
fmt
.
Errorf
(
"reverse field `%s` not found in model `%s`"
,
fi
.
fullName
,
fi
.
relModelInfo
.
fullName
)
err
=
fmt
.
Errorf
(
"reverse field `%s` not found in model `%s`"
,
fi
.
fullName
,
fi
.
relModelInfo
.
fullName
)
goto
end
goto
end
}
}
...
@@ -267,7 +267,7 @@ func bootStrap() {
...
@@ -267,7 +267,7 @@ func bootStrap() {
break
mForB
break
mForB
}
}
}
}
if
found
==
false
{
if
!
found
{
mForC
:
mForC
:
for
_
,
ffi
:=
range
fi
.
relModelInfo
.
fields
.
fieldsByType
[
RelManyToMany
]
{
for
_
,
ffi
:=
range
fi
.
relModelInfo
.
fields
.
fieldsByType
[
RelManyToMany
]
{
conditions
:=
fi
.
relThrough
!=
""
&&
fi
.
relThrough
==
ffi
.
relThrough
||
conditions
:=
fi
.
relThrough
!=
""
&&
fi
.
relThrough
==
ffi
.
relThrough
||
...
@@ -287,7 +287,7 @@ func bootStrap() {
...
@@ -287,7 +287,7 @@ func bootStrap() {
}
}
}
}
}
}
if
found
==
false
{
if
!
found
{
err
=
fmt
.
Errorf
(
"reverse field for `%s` not found in model `%s`"
,
fi
.
fullName
,
fi
.
relModelInfo
.
fullName
)
err
=
fmt
.
Errorf
(
"reverse field for `%s` not found in model `%s`"
,
fi
.
fullName
,
fi
.
relModelInfo
.
fullName
)
goto
end
goto
end
}
}
...
...
orm/models_info_f.go
View file @
12dff072
...
@@ -47,7 +47,7 @@ func (f *fields) Add(fi *fieldInfo) (added bool) {
...
@@ -47,7 +47,7 @@ func (f *fields) Add(fi *fieldInfo) (added bool) {
}
else
{
}
else
{
return
return
}
}
if
_
,
ok
:=
f
.
fieldsByType
[
fi
.
fieldType
];
ok
==
false
{
if
_
,
ok
:=
f
.
fieldsByType
[
fi
.
fieldType
];
!
ok
{
f
.
fieldsByType
[
fi
.
fieldType
]
=
make
([]
*
fieldInfo
,
0
)
f
.
fieldsByType
[
fi
.
fieldType
]
=
make
([]
*
fieldInfo
,
0
)
}
}
f
.
fieldsByType
[
fi
.
fieldType
]
=
append
(
f
.
fieldsByType
[
fi
.
fieldType
],
fi
)
f
.
fieldsByType
[
fi
.
fieldType
]
=
append
(
f
.
fieldsByType
[
fi
.
fieldType
],
fi
)
...
@@ -334,12 +334,12 @@ checkType:
...
@@ -334,12 +334,12 @@ checkType:
switch
onDelete
{
switch
onDelete
{
case
odCascade
,
odDoNothing
:
case
odCascade
,
odDoNothing
:
case
odSetDefault
:
case
odSetDefault
:
if
initial
.
Exist
()
==
false
{
if
!
initial
.
Exist
()
{
err
=
errors
.
New
(
"on_delete: set_default need set field a default value"
)
err
=
errors
.
New
(
"on_delete: set_default need set field a default value"
)
goto
end
goto
end
}
}
case
odSetNULL
:
case
odSetNULL
:
if
fi
.
null
==
false
{
if
!
fi
.
null
{
err
=
errors
.
New
(
"on_delete: set_null need set field null"
)
err
=
errors
.
New
(
"on_delete: set_null need set field null"
)
goto
end
goto
end
}
}
...
...
orm/models_info_m.go
View file @
12dff072
...
@@ -78,7 +78,7 @@ func addModelFields(mi *modelInfo, ind reflect.Value, mName string, index []int)
...
@@ -78,7 +78,7 @@ func addModelFields(mi *modelInfo, ind reflect.Value, mName string, index []int)
fi
.
fieldIndex
=
append
(
index
,
i
)
fi
.
fieldIndex
=
append
(
index
,
i
)
fi
.
mi
=
mi
fi
.
mi
=
mi
fi
.
inModel
=
true
fi
.
inModel
=
true
if
mi
.
fields
.
Add
(
fi
)
==
false
{
if
!
mi
.
fields
.
Add
(
fi
)
{
err
=
fmt
.
Errorf
(
"duplicate column name: %s"
,
fi
.
column
)
err
=
fmt
.
Errorf
(
"duplicate column name: %s"
,
fi
.
column
)
break
break
}
}
...
...
orm/orm.go
View file @
12dff072
...
@@ -122,21 +122,13 @@ func (o *orm) getFieldInfo(mi *modelInfo, name string) *fieldInfo {
...
@@ -122,21 +122,13 @@ func (o *orm) getFieldInfo(mi *modelInfo, name string) *fieldInfo {
// read data to model
// read data to model
func
(
o
*
orm
)
Read
(
md
interface
{},
cols
...
string
)
error
{
func
(
o
*
orm
)
Read
(
md
interface
{},
cols
...
string
)
error
{
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
err
:=
o
.
alias
.
DbBaser
.
Read
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
,
false
)
return
o
.
alias
.
DbBaser
.
Read
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
,
false
)
if
err
!=
nil
{
return
err
}
return
nil
}
}
// read data to model, like Read(), but use "SELECT FOR UPDATE" form
// read data to model, like Read(), but use "SELECT FOR UPDATE" form
func
(
o
*
orm
)
ReadForUpdate
(
md
interface
{},
cols
...
string
)
error
{
func
(
o
*
orm
)
ReadForUpdate
(
md
interface
{},
cols
...
string
)
error
{
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
err
:=
o
.
alias
.
DbBaser
.
Read
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
,
true
)
return
o
.
alias
.
DbBaser
.
Read
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
,
true
)
if
err
!=
nil
{
return
err
}
return
nil
}
}
// Try to read a row from the database, or insert one if it doesn't exist
// Try to read a row from the database, or insert one if it doesn't exist
...
@@ -238,15 +230,11 @@ func (o *orm) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64
...
@@ -238,15 +230,11 @@ func (o *orm) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64
// cols set the columns those want to update.
// cols set the columns those want to update.
func
(
o
*
orm
)
Update
(
md
interface
{},
cols
...
string
)
(
int64
,
error
)
{
func
(
o
*
orm
)
Update
(
md
interface
{},
cols
...
string
)
(
int64
,
error
)
{
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
num
,
err
:=
o
.
alias
.
DbBaser
.
Update
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
)
return
o
.
alias
.
DbBaser
.
Update
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
)
if
err
!=
nil
{
return
num
,
err
}
return
num
,
nil
}
}
// delete model in database
// delete model in database
// cols shows the delete conditions values read from. de
af
ult is pk
// cols shows the delete conditions values read from. de
fa
ult is pk
func
(
o
*
orm
)
Delete
(
md
interface
{},
cols
...
string
)
(
int64
,
error
)
{
func
(
o
*
orm
)
Delete
(
md
interface
{},
cols
...
string
)
(
int64
,
error
)
{
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
mi
,
ind
:=
o
.
getMiInd
(
md
,
true
)
num
,
err
:=
o
.
alias
.
DbBaser
.
Delete
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
)
num
,
err
:=
o
.
alias
.
DbBaser
.
Delete
(
o
.
db
,
mi
,
ind
,
o
.
alias
.
TZ
,
cols
)
...
@@ -361,7 +349,7 @@ func (o *orm) queryRelated(md interface{}, name string) (*modelInfo, *fieldInfo,
...
@@ -361,7 +349,7 @@ func (o *orm) queryRelated(md interface{}, name string) (*modelInfo, *fieldInfo,
fi
:=
o
.
getFieldInfo
(
mi
,
name
)
fi
:=
o
.
getFieldInfo
(
mi
,
name
)
_
,
_
,
exist
:=
getExistPk
(
mi
,
ind
)
_
,
_
,
exist
:=
getExistPk
(
mi
,
ind
)
if
exist
==
false
{
if
!
exist
{
panic
(
ErrMissPK
)
panic
(
ErrMissPK
)
}
}
...
@@ -489,7 +477,7 @@ func (o *orm) Begin() error {
...
@@ -489,7 +477,7 @@ func (o *orm) Begin() error {
// commit transaction
// commit transaction
func
(
o
*
orm
)
Commit
()
error
{
func
(
o
*
orm
)
Commit
()
error
{
if
o
.
isTx
==
false
{
if
!
o
.
isTx
{
return
ErrTxDone
return
ErrTxDone
}
}
err
:=
o
.
db
.
(
txEnder
)
.
Commit
()
err
:=
o
.
db
.
(
txEnder
)
.
Commit
()
...
@@ -504,7 +492,7 @@ func (o *orm) Commit() error {
...
@@ -504,7 +492,7 @@ func (o *orm) Commit() error {
// rollback transaction
// rollback transaction
func
(
o
*
orm
)
Rollback
()
error
{
func
(
o
*
orm
)
Rollback
()
error
{
if
o
.
isTx
==
false
{
if
!
o
.
isTx
{
return
ErrTxDone
return
ErrTxDone
}
}
err
:=
o
.
db
.
(
txEnder
)
.
Rollback
()
err
:=
o
.
db
.
(
txEnder
)
.
Rollback
()
...
...
orm/orm_querym2m.go
View file @
12dff072
...
@@ -72,7 +72,7 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
...
@@ -72,7 +72,7 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
}
}
_
,
v1
,
exist
:=
getExistPk
(
o
.
mi
,
o
.
ind
)
_
,
v1
,
exist
:=
getExistPk
(
o
.
mi
,
o
.
ind
)
if
exist
==
false
{
if
!
exist
{
panic
(
ErrMissPK
)
panic
(
ErrMissPK
)
}
}
...
@@ -87,7 +87,7 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
...
@@ -87,7 +87,7 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
v2
=
ind
.
Interface
()
v2
=
ind
.
Interface
()
}
else
{
}
else
{
_
,
v2
,
exist
=
getExistPk
(
fi
.
relModelInfo
,
ind
)
_
,
v2
,
exist
=
getExistPk
(
fi
.
relModelInfo
,
ind
)
if
exist
==
false
{
if
!
exist
{
panic
(
ErrMissPK
)
panic
(
ErrMissPK
)
}
}
}
}
...
@@ -104,11 +104,7 @@ func (o *queryM2M) Remove(mds ...interface{}) (int64, error) {
...
@@ -104,11 +104,7 @@ func (o *queryM2M) Remove(mds ...interface{}) (int64, error) {
fi
:=
o
.
fi
fi
:=
o
.
fi
qs
:=
o
.
qs
.
Filter
(
fi
.
reverseFieldInfo
.
name
,
o
.
md
)
qs
:=
o
.
qs
.
Filter
(
fi
.
reverseFieldInfo
.
name
,
o
.
md
)
nums
,
err
:=
qs
.
Filter
(
fi
.
reverseFieldInfoTwo
.
name
+
ExprSep
+
"in"
,
mds
)
.
Delete
()
return
qs
.
Filter
(
fi
.
reverseFieldInfoTwo
.
name
+
ExprSep
+
"in"
,
mds
)
.
Delete
()
if
err
!=
nil
{
return
nums
,
err
}
return
nums
,
nil
}
}
// check model is existed in relationship of origin model
// check model is existed in relationship of origin model
...
...
orm/orm_test.go
View file @
12dff072
...
@@ -93,14 +93,14 @@ wrongArg:
...
@@ -93,14 +93,14 @@ wrongArg:
}
}
func
AssertIs
(
a
interface
{},
args
...
interface
{})
error
{
func
AssertIs
(
a
interface
{},
args
...
interface
{})
error
{
if
ok
,
err
:=
ValuesCompare
(
true
,
a
,
args
...
);
ok
==
false
{
if
ok
,
err
:=
ValuesCompare
(
true
,
a
,
args
...
);
!
ok
{
return
err
return
err
}
}
return
nil
return
nil
}
}
func
AssertNot
(
a
interface
{},
args
...
interface
{})
error
{
func
AssertNot
(
a
interface
{},
args
...
interface
{})
error
{
if
ok
,
err
:=
ValuesCompare
(
false
,
a
,
args
...
);
ok
==
false
{
if
ok
,
err
:=
ValuesCompare
(
false
,
a
,
args
...
);
!
ok
{
return
err
return
err
}
}
return
nil
return
nil
...
...
orm/utils.go
View file @
12dff072
...
@@ -225,7 +225,7 @@ func camelString(s string) string {
...
@@ -225,7 +225,7 @@ func camelString(s string) string {
if
d
==
'_'
{
if
d
==
'_'
{
flag
=
true
flag
=
true
continue
continue
}
else
if
flag
==
true
{
}
else
if
flag
{
if
d
>=
'a'
&&
d
<=
'z'
{
if
d
>=
'a'
&&
d
<=
'z'
{
d
=
d
-
32
d
=
d
-
32
}
}
...
...
router_test.go
View file @
12dff072
...
@@ -502,10 +502,10 @@ func TestFilterBeforeRouter(t *testing.T) {
...
@@ -502,10 +502,10 @@ func TestFilterBeforeRouter(t *testing.T) {
rw
,
r
:=
testRequest
(
"GET"
,
url
)
rw
,
r
:=
testRequest
(
"GET"
,
url
)
mux
.
ServeHTTP
(
rw
,
r
)
mux
.
ServeHTTP
(
rw
,
r
)
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter1"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter1"
)
{
t
.
Errorf
(
testName
+
" BeforeRouter did not run"
)
t
.
Errorf
(
testName
+
" BeforeRouter did not run"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
{
t
.
Errorf
(
testName
+
" BeforeRouter did not return properly"
)
t
.
Errorf
(
testName
+
" BeforeRouter did not return properly"
)
}
}
}
}
...
@@ -525,13 +525,13 @@ func TestFilterBeforeExec(t *testing.T) {
...
@@ -525,13 +525,13 @@ func TestFilterBeforeExec(t *testing.T) {
rw
,
r
:=
testRequest
(
"GET"
,
url
)
rw
,
r
:=
testRequest
(
"GET"
,
url
)
mux
.
ServeHTTP
(
rw
,
r
)
mux
.
ServeHTTP
(
rw
,
r
)
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeExec1"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeExec1"
)
{
t
.
Errorf
(
testName
+
" BeforeExec did not run"
)
t
.
Errorf
(
testName
+
" BeforeExec did not run"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
{
t
.
Errorf
(
testName
+
" BeforeExec did not return properly"
)
t
.
Errorf
(
testName
+
" BeforeExec did not return properly"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter"
)
{
t
.
Errorf
(
testName
+
" BeforeRouter ran in error"
)
t
.
Errorf
(
testName
+
" BeforeRouter ran in error"
)
}
}
}
}
...
@@ -552,16 +552,16 @@ func TestFilterAfterExec(t *testing.T) {
...
@@ -552,16 +552,16 @@ func TestFilterAfterExec(t *testing.T) {
rw
,
r
:=
testRequest
(
"GET"
,
url
)
rw
,
r
:=
testRequest
(
"GET"
,
url
)
mux
.
ServeHTTP
(
rw
,
r
)
mux
.
ServeHTTP
(
rw
,
r
)
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"AfterExec1"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"AfterExec1"
)
{
t
.
Errorf
(
testName
+
" AfterExec did not run"
)
t
.
Errorf
(
testName
+
" AfterExec did not run"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
{
t
.
Errorf
(
testName
+
" handler did not run properly"
)
t
.
Errorf
(
testName
+
" handler did not run properly"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter"
)
{
t
.
Errorf
(
testName
+
" BeforeRouter ran in error"
)
t
.
Errorf
(
testName
+
" BeforeRouter ran in error"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeExec"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeExec"
)
{
t
.
Errorf
(
testName
+
" BeforeExec ran in error"
)
t
.
Errorf
(
testName
+
" BeforeExec ran in error"
)
}
}
}
}
...
@@ -583,19 +583,19 @@ func TestFilterFinishRouter(t *testing.T) {
...
@@ -583,19 +583,19 @@ func TestFilterFinishRouter(t *testing.T) {
rw
,
r
:=
testRequest
(
"GET"
,
url
)
rw
,
r
:=
testRequest
(
"GET"
,
url
)
mux
.
ServeHTTP
(
rw
,
r
)
mux
.
ServeHTTP
(
rw
,
r
)
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter1"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter1"
)
{
t
.
Errorf
(
testName
+
" FinishRouter did not run"
)
t
.
Errorf
(
testName
+
" FinishRouter did not run"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
{
t
.
Errorf
(
testName
+
" handler did not run properly"
)
t
.
Errorf
(
testName
+
" handler did not run properly"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"AfterExec1"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"AfterExec1"
)
{
t
.
Errorf
(
testName
+
" AfterExec ran in error"
)
t
.
Errorf
(
testName
+
" AfterExec ran in error"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeRouter"
)
{
t
.
Errorf
(
testName
+
" BeforeRouter ran in error"
)
t
.
Errorf
(
testName
+
" BeforeRouter ran in error"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeExec"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"BeforeExec"
)
{
t
.
Errorf
(
testName
+
" BeforeExec ran in error"
)
t
.
Errorf
(
testName
+
" BeforeExec ran in error"
)
}
}
}
}
...
@@ -615,14 +615,14 @@ func TestFilterFinishRouterMultiFirstOnly(t *testing.T) {
...
@@ -615,14 +615,14 @@ func TestFilterFinishRouterMultiFirstOnly(t *testing.T) {
rw
,
r
:=
testRequest
(
"GET"
,
url
)
rw
,
r
:=
testRequest
(
"GET"
,
url
)
mux
.
ServeHTTP
(
rw
,
r
)
mux
.
ServeHTTP
(
rw
,
r
)
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter1"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter1"
)
{
t
.
Errorf
(
testName
+
" FinishRouter1 did not run"
)
t
.
Errorf
(
testName
+
" FinishRouter1 did not run"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
{
t
.
Errorf
(
testName
+
" handler did not run properly"
)
t
.
Errorf
(
testName
+
" handler did not run properly"
)
}
}
// not expected in body
// not expected in body
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter2"
)
==
true
{
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter2"
)
{
t
.
Errorf
(
testName
+
" FinishRouter2 did run"
)
t
.
Errorf
(
testName
+
" FinishRouter2 did run"
)
}
}
}
}
...
@@ -642,13 +642,13 @@ func TestFilterFinishRouterMulti(t *testing.T) {
...
@@ -642,13 +642,13 @@ func TestFilterFinishRouterMulti(t *testing.T) {
rw
,
r
:=
testRequest
(
"GET"
,
url
)
rw
,
r
:=
testRequest
(
"GET"
,
url
)
mux
.
ServeHTTP
(
rw
,
r
)
mux
.
ServeHTTP
(
rw
,
r
)
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter1"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter1"
)
{
t
.
Errorf
(
testName
+
" FinishRouter1 did not run"
)
t
.
Errorf
(
testName
+
" FinishRouter1 did not run"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"hello"
)
{
t
.
Errorf
(
testName
+
" handler did not run properly"
)
t
.
Errorf
(
testName
+
" handler did not run properly"
)
}
}
if
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter2"
)
==
false
{
if
!
strings
.
Contains
(
rw
.
Body
.
String
(),
"FinishRouter2"
)
{
t
.
Errorf
(
testName
+
" FinishRouter2 did not run properly"
)
t
.
Errorf
(
testName
+
" FinishRouter2 did not run properly"
)
}
}
}
}
...
...
session/ledis/ledis_session.go
View file @
12dff072
...
@@ -125,10 +125,7 @@ func (lp *Provider) SessionRead(sid string) (session.Store, error) {
...
@@ -125,10 +125,7 @@ func (lp *Provider) SessionRead(sid string) (session.Store, error) {
// SessionExist check ledis session exist by sid
// SessionExist check ledis session exist by sid
func
(
lp
*
Provider
)
SessionExist
(
sid
string
)
bool
{
func
(
lp
*
Provider
)
SessionExist
(
sid
string
)
bool
{
count
,
_
:=
c
.
Exists
([]
byte
(
sid
))
count
,
_
:=
c
.
Exists
([]
byte
(
sid
))
if
count
==
0
{
return
!
(
count
==
0
)
return
false
}
return
true
}
}
// SessionRegenerate generate new sid for ledis session
// SessionRegenerate generate new sid for ledis session
...
...
session/memcache/sess_memcache.go
View file @
12dff072
...
@@ -205,11 +205,7 @@ func (rp *MemProvider) SessionDestroy(sid string) error {
...
@@ -205,11 +205,7 @@ func (rp *MemProvider) SessionDestroy(sid string) error {
}
}
}
}
err
:=
client
.
Delete
(
sid
)
return
client
.
Delete
(
sid
)
if
err
!=
nil
{
return
err
}
return
nil
}
}
func
(
rp
*
MemProvider
)
connectInit
()
error
{
func
(
rp
*
MemProvider
)
connectInit
()
error
{
...
...
session/mysql/sess_mysql.go
View file @
12dff072
...
@@ -171,10 +171,7 @@ func (mp *Provider) SessionExist(sid string) bool {
...
@@ -171,10 +171,7 @@ func (mp *Provider) SessionExist(sid string) bool {
row
:=
c
.
QueryRow
(
"select session_data from "
+
TableName
+
" where session_key=?"
,
sid
)
row
:=
c
.
QueryRow
(
"select session_data from "
+
TableName
+
" where session_key=?"
,
sid
)
var
sessiondata
[]
byte
var
sessiondata
[]
byte
err
:=
row
.
Scan
(
&
sessiondata
)
err
:=
row
.
Scan
(
&
sessiondata
)
if
err
==
sql
.
ErrNoRows
{
return
!
(
err
==
sql
.
ErrNoRows
)
return
false
}
return
true
}
}
// SessionRegenerate generate new sid for mysql session
// SessionRegenerate generate new sid for mysql session
...
...
session/postgres/sess_postgresql.go
View file @
12dff072
...
@@ -184,11 +184,7 @@ func (mp *Provider) SessionExist(sid string) bool {
...
@@ -184,11 +184,7 @@ func (mp *Provider) SessionExist(sid string) bool {
row
:=
c
.
QueryRow
(
"select session_data from session where session_key=$1"
,
sid
)
row
:=
c
.
QueryRow
(
"select session_data from session where session_key=$1"
,
sid
)
var
sessiondata
[]
byte
var
sessiondata
[]
byte
err
:=
row
.
Scan
(
&
sessiondata
)
err
:=
row
.
Scan
(
&
sessiondata
)
return
!
(
err
==
sql
.
ErrNoRows
)
if
err
==
sql
.
ErrNoRows
{
return
false
}
return
true
}
}
// SessionRegenerate generate new sid for postgresql session
// SessionRegenerate generate new sid for postgresql session
...
...
session/sess_file.go
View file @
12dff072
...
@@ -163,10 +163,7 @@ func (fp *FileProvider) SessionExist(sid string) bool {
...
@@ -163,10 +163,7 @@ func (fp *FileProvider) SessionExist(sid string) bool {
defer
filepder
.
lock
.
Unlock
()
defer
filepder
.
lock
.
Unlock
()
_
,
err
:=
os
.
Stat
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
]),
sid
))
_
,
err
:=
os
.
Stat
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
]),
sid
))
if
err
==
nil
{
return
err
==
nil
return
true
}
return
false
}
}
// SessionDestroy Remove all files in this save path
// SessionDestroy Remove all files in this save path
...
...
session/sess_test.go
View file @
12dff072
...
@@ -115,7 +115,7 @@ func TestParseConfig(t *testing.T) {
...
@@ -115,7 +115,7 @@ func TestParseConfig(t *testing.T) {
if
cf2
.
Gclifetime
!=
3600
{
if
cf2
.
Gclifetime
!=
3600
{
t
.
Fatal
(
"parseconfig get gclifetime error"
)
t
.
Fatal
(
"parseconfig get gclifetime error"
)
}
}
if
cf2
.
EnableSetCookie
!=
false
{
if
cf2
.
EnableSetCookie
{
t
.
Fatal
(
"parseconfig get enableSetCookie error"
)
t
.
Fatal
(
"parseconfig get enableSetCookie error"
)
}
}
cconfig
:=
new
(
cookieConfig
)
cconfig
:=
new
(
cookieConfig
)
...
...
session/ssdb/sess_ssdb.go
View file @
12dff072
...
@@ -26,10 +26,7 @@ func (p *SsdbProvider) connectInit() error {
...
@@ -26,10 +26,7 @@ func (p *SsdbProvider) connectInit() error {
return
errors
.
New
(
"SessionInit First"
)
return
errors
.
New
(
"SessionInit First"
)
}
}
p
.
client
,
err
=
ssdb
.
Connect
(
p
.
host
,
p
.
port
)
p
.
client
,
err
=
ssdb
.
Connect
(
p
.
host
,
p
.
port
)
if
err
!=
nil
{
return
err
return
err
}
return
nil
}
}
func
(
p
*
SsdbProvider
)
SessionInit
(
maxLifetime
int64
,
savePath
string
)
error
{
func
(
p
*
SsdbProvider
)
SessionInit
(
maxLifetime
int64
,
savePath
string
)
error
{
...
@@ -41,11 +38,7 @@ func (p *SsdbProvider) SessionInit(maxLifetime int64, savePath string) error {
...
@@ -41,11 +38,7 @@ func (p *SsdbProvider) SessionInit(maxLifetime int64, savePath string) error {
if
e
!=
nil
{
if
e
!=
nil
{
return
e
return
e
}
}
err
:=
p
.
connectInit
()
return
p
.
connectInit
()
if
err
!=
nil
{
return
err
}
return
nil
}
}
func
(
p
*
SsdbProvider
)
SessionRead
(
sid
string
)
(
session
.
Store
,
error
)
{
func
(
p
*
SsdbProvider
)
SessionRead
(
sid
string
)
(
session
.
Store
,
error
)
{
...
@@ -126,10 +119,7 @@ func (p *SsdbProvider) SessionDestroy(sid string) error {
...
@@ -126,10 +119,7 @@ func (p *SsdbProvider) SessionDestroy(sid string) error {
}
}
}
}
_
,
err
:=
p
.
client
.
Del
(
sid
)
_
,
err
:=
p
.
client
.
Del
(
sid
)
if
err
!=
nil
{
return
err
return
err
}
return
nil
}
}
func
(
p
*
SsdbProvider
)
SessionGC
()
{
func
(
p
*
SsdbProvider
)
SessionGC
()
{
...
...
staticfile.go
View file @
12dff072
...
@@ -109,14 +109,14 @@ var (
...
@@ -109,14 +109,14 @@ var (
func
openFile
(
filePath
string
,
fi
os
.
FileInfo
,
acceptEncoding
string
)
(
bool
,
string
,
*
serveContentHolder
,
error
)
{
func
openFile
(
filePath
string
,
fi
os
.
FileInfo
,
acceptEncoding
string
)
(
bool
,
string
,
*
serveContentHolder
,
error
)
{
mapKey
:=
acceptEncoding
+
":"
+
filePath
mapKey
:=
acceptEncoding
+
":"
+
filePath
mapLock
.
RLock
()
mapLock
.
RLock
()
mapFile
,
_
:=
staticFileMap
[
mapKey
]
mapFile
:=
staticFileMap
[
mapKey
]
mapLock
.
RUnlock
()
mapLock
.
RUnlock
()
if
isOk
(
mapFile
,
fi
)
{
if
isOk
(
mapFile
,
fi
)
{
return
mapFile
.
encoding
!=
""
,
mapFile
.
encoding
,
mapFile
,
nil
return
mapFile
.
encoding
!=
""
,
mapFile
.
encoding
,
mapFile
,
nil
}
}
mapLock
.
Lock
()
mapLock
.
Lock
()
defer
mapLock
.
Unlock
()
defer
mapLock
.
Unlock
()
if
mapFile
,
_
=
staticFileMap
[
mapKey
];
!
isOk
(
mapFile
,
fi
)
{
if
mapFile
=
staticFileMap
[
mapKey
];
!
isOk
(
mapFile
,
fi
)
{
file
,
err
:=
os
.
Open
(
filePath
)
file
,
err
:=
os
.
Open
(
filePath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
""
,
nil
,
err
return
false
,
""
,
nil
,
err
...
...
template.go
View file @
12dff072
...
@@ -46,7 +46,7 @@ var (
...
@@ -46,7 +46,7 @@ var (
// writing the output to wr.
// writing the output to wr.
// A template will be executed safely in parallel.
// A template will be executed safely in parallel.
func
ExecuteTemplate
(
wr
io
.
Writer
,
name
string
,
data
interface
{})
error
{
func
ExecuteTemplate
(
wr
io
.
Writer
,
name
string
,
data
interface
{})
error
{
return
ExecuteViewPathTemplate
(
wr
,
name
,
BConfig
.
WebConfig
.
ViewsPath
,
data
)
return
ExecuteViewPathTemplate
(
wr
,
name
,
BConfig
.
WebConfig
.
ViewsPath
,
data
)
}
}
// ExecuteViewPathTemplate applies the template with name and from specific viewPath to the specified data object,
// ExecuteViewPathTemplate applies the template with name and from specific viewPath to the specified data object,
...
@@ -57,7 +57,7 @@ func ExecuteViewPathTemplate(wr io.Writer, name string, viewPath string, data in
...
@@ -57,7 +57,7 @@ func ExecuteViewPathTemplate(wr io.Writer, name string, viewPath string, data in
templatesLock
.
RLock
()
templatesLock
.
RLock
()
defer
templatesLock
.
RUnlock
()
defer
templatesLock
.
RUnlock
()
}
}
if
beeTemplates
,
ok
:=
beeViewPathTemplates
[
viewPath
];
ok
{
if
beeTemplates
,
ok
:=
beeViewPathTemplates
[
viewPath
];
ok
{
if
t
,
ok
:=
beeTemplates
[
name
];
ok
{
if
t
,
ok
:=
beeTemplates
[
name
];
ok
{
var
err
error
var
err
error
if
t
.
Lookup
(
name
)
!=
nil
{
if
t
.
Lookup
(
name
)
!=
nil
{
...
@@ -187,7 +187,7 @@ func BuildTemplate(dir string, files ...string) error {
...
@@ -187,7 +187,7 @@ func BuildTemplate(dir string, files ...string) error {
}
}
return
errors
.
New
(
"dir open err"
)
return
errors
.
New
(
"dir open err"
)
}
}
beeTemplates
,
ok
:=
beeViewPathTemplates
[
dir
];
beeTemplates
,
ok
:=
beeViewPathTemplates
[
dir
]
if
!
ok
{
if
!
ok
{
panic
(
"Unknown view path: "
+
dir
)
panic
(
"Unknown view path: "
+
dir
)
}
}
...
@@ -296,7 +296,7 @@ func _getTemplate(t0 *template.Template, root string, subMods [][]string, others
...
@@ -296,7 +296,7 @@ func _getTemplate(t0 *template.Template, root string, subMods [][]string, others
t
,
subMods1
,
err
=
getTplDeep
(
root
,
otherFile
,
""
,
t
)
t
,
subMods1
,
err
=
getTplDeep
(
root
,
otherFile
,
""
,
t
)
if
err
!=
nil
{
if
err
!=
nil
{
logs
.
Trace
(
"template parse file err:"
,
err
)
logs
.
Trace
(
"template parse file err:"
,
err
)
}
else
if
subMods1
!=
nil
&&
len
(
subMods1
)
>
0
{
}
else
if
len
(
subMods1
)
>
0
{
t
,
err
=
_getTemplate
(
t
,
root
,
subMods1
,
others
...
)
t
,
err
=
_getTemplate
(
t
,
root
,
subMods1
,
others
...
)
}
}
break
break
...
@@ -317,7 +317,7 @@ func _getTemplate(t0 *template.Template, root string, subMods [][]string, others
...
@@ -317,7 +317,7 @@ func _getTemplate(t0 *template.Template, root string, subMods [][]string, others
t
,
subMods1
,
err
=
getTplDeep
(
root
,
otherFile
,
""
,
t
)
t
,
subMods1
,
err
=
getTplDeep
(
root
,
otherFile
,
""
,
t
)
if
err
!=
nil
{
if
err
!=
nil
{
logs
.
Trace
(
"template parse file err:"
,
err
)
logs
.
Trace
(
"template parse file err:"
,
err
)
}
else
if
subMods1
!=
nil
&&
len
(
subMods1
)
>
0
{
}
else
if
len
(
subMods1
)
>
0
{
t
,
err
=
_getTemplate
(
t
,
root
,
subMods1
,
others
...
)
t
,
err
=
_getTemplate
(
t
,
root
,
subMods1
,
others
...
)
}
}
break
break
...
...
templatefunc_test.go
View file @
12dff072
...
@@ -173,7 +173,7 @@ func TestParseForm(t *testing.T) {
...
@@ -173,7 +173,7 @@ func TestParseForm(t *testing.T) {
if
u
.
Intro
!=
"I am an engineer!"
{
if
u
.
Intro
!=
"I am an engineer!"
{
t
.
Errorf
(
"Intro should equal `I am an engineer!` but got `%v`"
,
u
.
Intro
)
t
.
Errorf
(
"Intro should equal `I am an engineer!` but got `%v`"
,
u
.
Intro
)
}
}
if
u
.
StrBool
!=
true
{
if
!
u
.
StrBool
{
t
.
Errorf
(
"strboll should equal `true`, but got `%v`"
,
u
.
StrBool
)
t
.
Errorf
(
"strboll should equal `true`, but got `%v`"
,
u
.
StrBool
)
}
}
y
,
m
,
d
:=
u
.
Date
.
Date
()
y
,
m
,
d
:=
u
.
Date
.
Date
()
...
@@ -255,43 +255,43 @@ func TestParseFormTag(t *testing.T) {
...
@@ -255,43 +255,43 @@ func TestParseFormTag(t *testing.T) {
objT
:=
reflect
.
TypeOf
(
&
user
{})
.
Elem
()
objT
:=
reflect
.
TypeOf
(
&
user
{})
.
Elem
()
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
:=
parseFormTag
(
objT
.
Field
(
0
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
:=
parseFormTag
(
objT
.
Field
(
0
))
if
!
(
name
==
"name"
&&
label
==
"年龄:"
&&
fType
==
"text"
&&
ignored
==
false
)
{
if
!
(
name
==
"name"
&&
label
==
"年龄:"
&&
fType
==
"text"
&&
!
ignored
)
{
t
.
Errorf
(
"Form Tag with name, label and type was not correctly parsed."
)
t
.
Errorf
(
"Form Tag with name, label and type was not correctly parsed."
)
}
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
1
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
1
))
if
!
(
name
==
"NoName"
&&
label
==
"年龄:"
&&
fType
==
"hidden"
&&
ignored
==
false
)
{
if
!
(
name
==
"NoName"
&&
label
==
"年龄:"
&&
fType
==
"hidden"
&&
!
ignored
)
{
t
.
Errorf
(
"Form Tag with label and type but without name was not correctly parsed."
)
t
.
Errorf
(
"Form Tag with label and type but without name was not correctly parsed."
)
}
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
2
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
2
))
if
!
(
name
==
"OnlyLabel"
&&
label
==
"年龄:"
&&
fType
==
"text"
&&
ignored
==
false
)
{
if
!
(
name
==
"OnlyLabel"
&&
label
==
"年龄:"
&&
fType
==
"text"
&&
!
ignored
)
{
t
.
Errorf
(
"Form Tag containing only label was not correctly parsed."
)
t
.
Errorf
(
"Form Tag containing only label was not correctly parsed."
)
}
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
3
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
3
))
if
!
(
name
==
"name"
&&
label
==
"OnlyName: "
&&
fType
==
"text"
&&
ignored
==
false
&&
if
!
(
name
==
"name"
&&
label
==
"OnlyName: "
&&
fType
==
"text"
&&
!
ignored
&&
id
==
"name"
&&
class
==
"form-name"
)
{
id
==
"name"
&&
class
==
"form-name"
)
{
t
.
Errorf
(
"Form Tag containing only name was not correctly parsed."
)
t
.
Errorf
(
"Form Tag containing only name was not correctly parsed."
)
}
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
4
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
4
))
if
ignored
==
false
{
if
!
ignored
{
t
.
Errorf
(
"Form Tag that should be ignored was not correctly parsed."
)
t
.
Errorf
(
"Form Tag that should be ignored was not correctly parsed."
)
}
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
5
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
5
))
if
!
(
name
==
"name"
&&
required
==
true
)
{
if
!
(
name
==
"name"
&&
required
)
{
t
.
Errorf
(
"Form Tag containing only name and required was not correctly parsed."
)
t
.
Errorf
(
"Form Tag containing only name and required was not correctly parsed."
)
}
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
6
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
6
))
if
!
(
name
==
"name"
&&
required
==
false
)
{
if
!
(
name
==
"name"
&&
!
required
)
{
t
.
Errorf
(
"Form Tag containing only name and ignore required was not correctly parsed."
)
t
.
Errorf
(
"Form Tag containing only name and ignore required was not correctly parsed."
)
}
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
7
))
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
7
))
if
!
(
name
==
"name"
&&
required
==
false
)
{
if
!
(
name
==
"name"
&&
!
required
)
{
t
.
Errorf
(
"Form Tag containing only name and not required was not correctly parsed."
)
t
.
Errorf
(
"Form Tag containing only name and not required was not correctly parsed."
)
}
}
...
...
validation/validation.go
View file @
12dff072
...
@@ -349,7 +349,7 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) {
...
@@ -349,7 +349,7 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) {
//Step 1: validate obj itself firstly
//Step 1: validate obj itself firstly
// fails if objc is not struct
// fails if objc is not struct
pass
,
err
:=
v
.
Valid
(
objc
)
pass
,
err
:=
v
.
Valid
(
objc
)
if
err
!=
nil
||
false
==
pass
{
if
err
!=
nil
||
!
pass
{
return
pass
,
err
// Stop recursive validation
return
pass
,
err
// Stop recursive validation
}
}
// Step 2: Validate struct's struct fields
// Step 2: Validate struct's struct fields
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment