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
dc28e376
Commit
dc28e376
authored
Nov 09, 2015
by
JessonChan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into fargo
parents
1f2f0b30
821b2f83
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
96 additions
and
53 deletions
+96
-53
admin.go
admin.go
+1
-1
app.go
app.go
+11
-8
config.go
config.go
+5
-6
context.go
context/context.go
+0
-1
output.go
context/output.go
+13
-1
controller.go
controller.go
+2
-2
memzipfile.go
memzipfile.go
+3
-3
cmd_utils.go
orm/cmd_utils.go
+3
-1
db.go
orm/db.go
+2
-1
models_boot.go
orm/models_boot.go
+4
-1
models_info_f.go
orm/models_info_f.go
+5
-0
router.go
router.go
+7
-26
router_test.go
router_test.go
+12
-0
staticfile.go
staticfile.go
+1
-2
validators.go
validation/validators.go
+27
-0
No files found.
admin.go
View file @
dc28e376
...
@@ -107,7 +107,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
...
@@ -107,7 +107,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
m
[
"SessionGCMaxLifetime"
]
=
SessionGCMaxLifetime
m
[
"SessionGCMaxLifetime"
]
=
SessionGCMaxLifetime
m
[
"SessionProviderConfig"
]
=
SessionProviderConfig
m
[
"SessionProviderConfig"
]
=
SessionProviderConfig
m
[
"SessionCookieLifeTime"
]
=
SessionCookieLifeTime
m
[
"SessionCookieLifeTime"
]
=
SessionCookieLifeTime
m
[
"Enab
elFcgi"
]
=
Enabel
Fcgi
m
[
"Enab
leFcgi"
]
=
Enable
Fcgi
m
[
"MaxMemory"
]
=
MaxMemory
m
[
"MaxMemory"
]
=
MaxMemory
m
[
"EnableGzip"
]
=
EnableGzip
m
[
"EnableGzip"
]
=
EnableGzip
m
[
"DirectoryIndex"
]
=
DirectoryIndex
m
[
"DirectoryIndex"
]
=
DirectoryIndex
...
...
app.go
View file @
dc28e376
...
@@ -64,7 +64,7 @@ func (app *App) Run() {
...
@@ -64,7 +64,7 @@ func (app *App) Run() {
)
)
endRunning
:=
make
(
chan
bool
,
1
)
endRunning
:=
make
(
chan
bool
,
1
)
if
Enab
el
Fcgi
{
if
Enab
le
Fcgi
{
if
EnableStdIo
{
if
EnableStdIo
{
err
=
fcgi
.
Serve
(
nil
,
app
.
Handlers
)
// standard I/O
err
=
fcgi
.
Serve
(
nil
,
app
.
Handlers
)
// standard I/O
if
err
==
nil
{
if
err
==
nil
{
...
@@ -89,6 +89,7 @@ func (app *App) Run() {
...
@@ -89,6 +89,7 @@ func (app *App) Run() {
}
}
}
else
{
}
else
{
if
Graceful
{
if
Graceful
{
httpsAddr
:=
addr
app
.
Server
.
Addr
=
addr
app
.
Server
.
Addr
=
addr
app
.
Server
.
Handler
=
app
.
Handlers
app
.
Server
.
Handler
=
app
.
Handlers
app
.
Server
.
ReadTimeout
=
time
.
Duration
(
HTTPServerTimeOut
)
*
time
.
Second
app
.
Server
.
ReadTimeout
=
time
.
Duration
(
HTTPServerTimeOut
)
*
time
.
Second
...
@@ -97,11 +98,12 @@ func (app *App) Run() {
...
@@ -97,11 +98,12 @@ func (app *App) Run() {
go
func
()
{
go
func
()
{
time
.
Sleep
(
20
*
time
.
Microsecond
)
time
.
Sleep
(
20
*
time
.
Microsecond
)
if
HTTPSPort
!=
0
{
if
HTTPSPort
!=
0
{
a
ddr
=
fmt
.
Sprintf
(
"%s:%d"
,
HTTPAddr
,
HTTPSPort
)
httpsA
ddr
=
fmt
.
Sprintf
(
"%s:%d"
,
HTTPAddr
,
HTTPSPort
)
app
.
Server
.
Addr
=
a
ddr
app
.
Server
.
Addr
=
httpsA
ddr
}
}
server
:=
grace
.
NewServer
(
addr
,
app
.
Handlers
)
server
:=
grace
.
NewServer
(
httpsAddr
,
app
.
Handlers
)
server
.
Server
=
app
.
Server
server
.
Server
.
ReadTimeout
=
app
.
Server
.
ReadTimeout
server
.
Server
.
WriteTimeout
=
app
.
Server
.
WriteTimeout
err
:=
server
.
ListenAndServeTLS
(
HTTPCertFile
,
HTTPKeyFile
)
err
:=
server
.
ListenAndServeTLS
(
HTTPCertFile
,
HTTPKeyFile
)
if
err
!=
nil
{
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServeTLS: "
,
err
,
fmt
.
Sprintf
(
"%d"
,
os
.
Getpid
()))
BeeLogger
.
Critical
(
"ListenAndServeTLS: "
,
err
,
fmt
.
Sprintf
(
"%d"
,
os
.
Getpid
()))
...
@@ -113,8 +115,9 @@ func (app *App) Run() {
...
@@ -113,8 +115,9 @@ func (app *App) Run() {
if
EnableHTTPListen
{
if
EnableHTTPListen
{
go
func
()
{
go
func
()
{
server
:=
grace
.
NewServer
(
addr
,
app
.
Handlers
)
server
:=
grace
.
NewServer
(
addr
,
app
.
Handlers
)
server
.
Server
=
app
.
Server
server
.
Server
.
ReadTimeout
=
app
.
Server
.
ReadTimeout
if
ListenTCP4
&&
HTTPAddr
==
""
{
server
.
Server
.
WriteTimeout
=
app
.
Server
.
WriteTimeout
if
ListenTCP4
{
server
.
Network
=
"tcp4"
server
.
Network
=
"tcp4"
}
}
err
:=
server
.
ListenAndServe
()
err
:=
server
.
ListenAndServe
()
...
@@ -151,7 +154,7 @@ func (app *App) Run() {
...
@@ -151,7 +154,7 @@ func (app *App) Run() {
go
func
()
{
go
func
()
{
app
.
Server
.
Addr
=
addr
app
.
Server
.
Addr
=
addr
BeeLogger
.
Info
(
"http server Running on %s"
,
app
.
Server
.
Addr
)
BeeLogger
.
Info
(
"http server Running on %s"
,
app
.
Server
.
Addr
)
if
ListenTCP4
&&
HTTPAddr
==
""
{
if
ListenTCP4
{
ln
,
err
:=
net
.
Listen
(
"tcp4"
,
app
.
Server
.
Addr
)
ln
,
err
:=
net
.
Listen
(
"tcp4"
,
app
.
Server
.
Addr
)
if
err
!=
nil
{
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
...
...
config.go
View file @
dc28e376
...
@@ -60,15 +60,15 @@ var (
...
@@ -60,15 +60,15 @@ var (
EnableDocs
bool
EnableDocs
bool
// EnableErrorsShow wheather show errors in page. if true, show error and trace info in page rendered with error template.
// EnableErrorsShow wheather show errors in page. if true, show error and trace info in page rendered with error template.
EnableErrorsShow
bool
EnableErrorsShow
bool
// Enab
el
Fcgi turn on the fcgi Listen, default is false
// Enab
le
Fcgi turn on the fcgi Listen, default is false
Enab
el
Fcgi
bool
Enab
le
Fcgi
bool
// EnableGzip means gzip the response
// EnableGzip means gzip the response
EnableGzip
bool
EnableGzip
bool
// EnableHTTPListen represent whether turn on the HTTP, default is true
// EnableHTTPListen represent whether turn on the HTTP, default is true
EnableHTTPListen
bool
EnableHTTPListen
bool
// EnableHTTPTLS represent whether turn on the HTTPS, default is true
// EnableHTTPTLS represent whether turn on the HTTPS, default is true
EnableHTTPTLS
bool
EnableHTTPTLS
bool
// EnableStdIo works with Enab
el
Fcgi Use FCGI via standard I/O
// EnableStdIo works with Enab
le
Fcgi Use FCGI via standard I/O
EnableStdIo
bool
EnableStdIo
bool
// EnableXSRF whether turn on xsrf. default is false
// EnableXSRF whether turn on xsrf. default is false
EnableXSRF
bool
EnableXSRF
bool
...
@@ -435,8 +435,8 @@ func ParseConfig() (err error) {
...
@@ -435,8 +435,8 @@ func ParseConfig() (err error) {
SessionCookieLifeTime
=
sesscookielifetime
SessionCookieLifeTime
=
sesscookielifetime
}
}
if
enab
elFcgi
,
err
:=
AppConfig
.
Bool
(
"Enabel
Fcgi"
);
err
==
nil
{
if
enab
leFcgi
,
err
:=
AppConfig
.
Bool
(
"Enable
Fcgi"
);
err
==
nil
{
Enab
elFcgi
=
enabel
Fcgi
Enab
leFcgi
=
enable
Fcgi
}
}
if
enablegzip
,
err
:=
AppConfig
.
Bool
(
"EnableGzip"
);
err
==
nil
{
if
enablegzip
,
err
:=
AppConfig
.
Bool
(
"EnableGzip"
);
err
==
nil
{
...
@@ -529,7 +529,6 @@ func ParseConfig() (err error) {
...
@@ -529,7 +529,6 @@ func ParseConfig() (err error) {
if
ext
==
""
{
if
ext
==
""
{
continue
continue
}
}
ext
=
strings
.
ToLower
(
ext
)
if
!
strings
.
HasPrefix
(
ext
,
"."
)
{
if
!
strings
.
HasPrefix
(
ext
,
"."
)
{
ext
=
"."
+
ext
ext
=
"."
+
ext
}
}
...
...
context/context.go
View file @
dc28e376
...
@@ -55,7 +55,6 @@ func (ctx *Context) Redirect(status int, localurl string) {
...
@@ -55,7 +55,6 @@ func (ctx *Context) Redirect(status int, localurl string) {
// Abort stops this request.
// Abort stops this request.
// if beego.ErrorMaps exists, panic body.
// if beego.ErrorMaps exists, panic body.
func
(
ctx
*
Context
)
Abort
(
status
int
,
body
string
)
{
func
(
ctx
*
Context
)
Abort
(
status
int
,
body
string
)
{
ctx
.
ResponseWriter
.
WriteHeader
(
status
)
panic
(
body
)
panic
(
body
)
}
}
...
...
context/output.go
View file @
dc28e376
...
@@ -103,7 +103,19 @@ func (output *BeegoOutput) Cookie(name string, value string, others ...interface
...
@@ -103,7 +103,19 @@ func (output *BeegoOutput) Cookie(name string, value string, others ...interface
//fix cookie not work in IE
//fix cookie not work in IE
if
len
(
others
)
>
0
{
if
len
(
others
)
>
0
{
switch
v
:=
others
[
0
]
.
(
type
)
{
switch
v
:=
others
[
0
]
.
(
type
)
{
case
int
,
int32
,
int64
:
case
int
:
if
v
>
0
{
fmt
.
Fprintf
(
&
b
,
"; Expires=%s; Max-Age=%d"
,
time
.
Now
()
.
Add
(
time
.
Duration
(
v
)
*
time
.
Second
)
.
UTC
()
.
Format
(
time
.
RFC1123
),
v
)
}
else
if
v
<=
0
{
fmt
.
Fprintf
(
&
b
,
"; Max-Age=0"
)
}
case
int64
:
if
v
>
0
{
fmt
.
Fprintf
(
&
b
,
"; Expires=%s; Max-Age=%d"
,
time
.
Now
()
.
Add
(
time
.
Duration
(
v
)
*
time
.
Second
)
.
UTC
()
.
Format
(
time
.
RFC1123
),
v
)
}
else
if
v
<=
0
{
fmt
.
Fprintf
(
&
b
,
"; Max-Age=0"
)
}
case
int32
:
if
v
>
0
{
if
v
>
0
{
fmt
.
Fprintf
(
&
b
,
"; Expires=%s; Max-Age=%d"
,
time
.
Now
()
.
Add
(
time
.
Duration
(
v
)
*
time
.
Second
)
.
UTC
()
.
Format
(
time
.
RFC1123
),
v
)
fmt
.
Fprintf
(
&
b
,
"; Expires=%s; Max-Age=%d"
,
time
.
Now
()
.
Add
(
time
.
Duration
(
v
)
*
time
.
Second
)
.
UTC
()
.
Format
(
time
.
RFC1123
),
v
)
}
else
if
v
<=
0
{
}
else
if
v
<=
0
{
...
...
controller.go
View file @
dc28e376
...
@@ -647,8 +647,8 @@ func (c *Controller) CheckXSRFCookie() bool {
...
@@ -647,8 +647,8 @@ func (c *Controller) CheckXSRFCookie() bool {
// XSRFFormHTML writes an input field contains xsrf token value.
// XSRFFormHTML writes an input field contains xsrf token value.
func
(
c
*
Controller
)
XSRFFormHTML
()
string
{
func
(
c
*
Controller
)
XSRFFormHTML
()
string
{
return
"<input type=
\"
hidden
\"
name=
\"
_xsrf
\"
value=
\"
"
+
return
`<input type="hidden" name="_xsrf" value="`
+
c
.
_xsrfToken
+
"
\"
/>"
c
.
XSRFToken
()
+
`" />`
}
}
// GetControllerAndAction gets the executing controller name and action name.
// GetControllerAndAction gets the executing controller name and action name.
...
...
memzipfile.go
View file @
dc28e376
...
@@ -219,9 +219,9 @@ func getAcceptEncodingZip(r *http.Request) string {
...
@@ -219,9 +219,9 @@ func getAcceptEncodingZip(r *http.Request) string {
ss
=
strings
.
ToLower
(
ss
)
ss
=
strings
.
ToLower
(
ss
)
if
strings
.
Contains
(
ss
,
"gzip"
)
{
if
strings
.
Contains
(
ss
,
"gzip"
)
{
return
"gzip"
return
"gzip"
}
}
else
if
strings
.
Contains
(
ss
,
"deflate"
)
{
if
strings
.
Contains
(
ss
,
"deflate"
)
{
return
"deflate"
return
"deflate"
}
else
{
return
""
}
}
return
""
}
}
orm/cmd_utils.go
View file @
dc28e376
...
@@ -45,13 +45,14 @@ func getDbDropSQL(al *alias) (sqls []string) {
...
@@ -45,13 +45,14 @@ func getDbDropSQL(al *alias) (sqls []string) {
func
getColumnTyp
(
al
*
alias
,
fi
*
fieldInfo
)
(
col
string
)
{
func
getColumnTyp
(
al
*
alias
,
fi
*
fieldInfo
)
(
col
string
)
{
T
:=
al
.
DbBaser
.
DbTypes
()
T
:=
al
.
DbBaser
.
DbTypes
()
fieldType
:=
fi
.
fieldType
fieldType
:=
fi
.
fieldType
fieldSize
:=
fi
.
size
checkColumn
:
checkColumn
:
switch
fieldType
{
switch
fieldType
{
case
TypeBooleanField
:
case
TypeBooleanField
:
col
=
T
[
"bool"
]
col
=
T
[
"bool"
]
case
TypeCharField
:
case
TypeCharField
:
col
=
fmt
.
Sprintf
(
T
[
"string"
],
fi
.
s
ize
)
col
=
fmt
.
Sprintf
(
T
[
"string"
],
fi
eldS
ize
)
case
TypeTextField
:
case
TypeTextField
:
col
=
T
[
"string-text"
]
col
=
T
[
"string-text"
]
case
TypeDateField
:
case
TypeDateField
:
...
@@ -89,6 +90,7 @@ checkColumn:
...
@@ -89,6 +90,7 @@ checkColumn:
}
}
case
RelForeignKey
,
RelOneToOne
:
case
RelForeignKey
,
RelOneToOne
:
fieldType
=
fi
.
relModelInfo
.
fields
.
pk
.
fieldType
fieldType
=
fi
.
relModelInfo
.
fields
.
pk
.
fieldType
fieldSize
=
fi
.
relModelInfo
.
fields
.
pk
.
size
goto
checkColumn
goto
checkColumn
}
}
...
...
orm/db.go
View file @
dc28e376
...
@@ -488,7 +488,8 @@ func (d *dbBase) Update(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.
...
@@ -488,7 +488,8 @@ func (d *dbBase) Update(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.
d
.
ins
.
ReplaceMarks
(
&
query
)
d
.
ins
.
ReplaceMarks
(
&
query
)
if
res
,
err
:=
q
.
Exec
(
query
,
setValues
...
);
err
==
nil
{
res
,
err
:=
q
.
Exec
(
query
,
setValues
...
)
if
err
==
nil
{
return
res
.
RowsAffected
()
return
res
.
RowsAffected
()
}
}
return
0
,
err
return
0
,
err
...
...
orm/models_boot.go
View file @
dc28e376
...
@@ -266,7 +266,10 @@ func bootStrap() {
...
@@ -266,7 +266,10 @@ func bootStrap() {
if
found
==
false
{
if
found
==
false
{
mForC
:
mForC
:
for
_
,
ffi
:=
range
fi
.
relModelInfo
.
fields
.
fieldsByType
[
RelManyToMany
]
{
for
_
,
ffi
:=
range
fi
.
relModelInfo
.
fields
.
fieldsByType
[
RelManyToMany
]
{
if
ffi
.
relModelInfo
==
mi
{
conditions
:=
fi
.
relThrough
!=
""
&&
fi
.
relThrough
==
ffi
.
relThrough
||
fi
.
relTable
!=
""
&&
fi
.
relTable
==
ffi
.
relTable
||
fi
.
relThrough
==
""
&&
fi
.
relTable
==
""
if
ffi
.
relModelInfo
==
mi
&&
conditions
{
found
=
true
found
=
true
fi
.
reverseField
=
ffi
.
reverseFieldInfoTwo
.
name
fi
.
reverseField
=
ffi
.
reverseFieldInfoTwo
.
name
...
...
orm/models_info_f.go
View file @
dc28e376
...
@@ -223,6 +223,11 @@ checkType:
...
@@ -223,6 +223,11 @@ checkType:
break
checkType
break
checkType
case
"many"
:
case
"many"
:
fieldType
=
RelReverseMany
fieldType
=
RelReverseMany
if
tv
:=
tags
[
"rel_table"
];
tv
!=
""
{
fi
.
relTable
=
tv
}
else
if
tv
:=
tags
[
"rel_through"
];
tv
!=
""
{
fi
.
relThrough
=
tv
}
break
checkType
break
checkType
default
:
default
:
err
=
fmt
.
Errorf
(
"error"
)
err
=
fmt
.
Errorf
(
"error"
)
...
...
router.go
View file @
dc28e376
...
@@ -15,10 +15,7 @@
...
@@ -15,10 +15,7 @@
package
beego
package
beego
import
(
import
(
"bufio"
"errors"
"fmt"
"fmt"
"net"
"net/http"
"net/http"
"os"
"os"
"path"
"path"
...
@@ -353,7 +350,7 @@ func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...
...
@@ -353,7 +350,7 @@ func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...
route
.
handler
=
h
route
.
handler
=
h
if
len
(
options
)
>
0
{
if
len
(
options
)
>
0
{
if
_
,
ok
:=
options
[
0
]
.
(
bool
);
ok
{
if
_
,
ok
:=
options
[
0
]
.
(
bool
);
ok
{
pattern
=
path
.
Join
(
pattern
,
"?:all"
)
pattern
=
path
.
Join
(
pattern
,
"?:all
(.*)
"
)
}
}
}
}
for
_
,
m
:=
range
HTTPMETHOD
{
for
_
,
m
:=
range
HTTPMETHOD
{
...
@@ -581,7 +578,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -581,7 +578,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
var
runMethod
string
var
runMethod
string
var
routerInfo
*
controllerInfo
var
routerInfo
*
controllerInfo
w
:=
&
responseWriter
{
writer
:
rw
}
w
:=
&
responseWriter
{
rw
,
false
,
0
}
if
RunMode
==
"dev"
{
if
RunMode
==
"dev"
{
w
.
Header
()
.
Set
(
"Server"
,
BeegoServerName
)
w
.
Header
()
.
Set
(
"Server"
,
BeegoServerName
)
...
@@ -856,7 +853,7 @@ Admin:
...
@@ -856,7 +853,7 @@ Admin:
// Call WriteHeader if status code has been set changed
// Call WriteHeader if status code has been set changed
if
context
.
Output
.
Status
!=
0
{
if
context
.
Output
.
Status
!=
0
{
w
.
writer
.
WriteHeader
(
context
.
Output
.
Status
)
w
.
WriteHeader
(
context
.
Output
.
Status
)
}
}
}
}
...
@@ -895,14 +892,14 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
...
@@ -895,14 +892,14 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
//responseWriter is a wrapper for the http.ResponseWriter
//responseWriter is a wrapper for the http.ResponseWriter
//started set to true if response was written to then don't execute other handler
//started set to true if response was written to then don't execute other handler
type
responseWriter
struct
{
type
responseWriter
struct
{
writer
http
.
ResponseWriter
http
.
ResponseWriter
started
bool
started
bool
status
int
status
int
}
}
// Header returns the header map that will be sent by WriteHeader.
// Header returns the header map that will be sent by WriteHeader.
func
(
w
*
responseWriter
)
Header
()
http
.
Header
{
func
(
w
*
responseWriter
)
Header
()
http
.
Header
{
return
w
.
w
riter
.
Header
()
return
w
.
ResponseW
riter
.
Header
()
}
}
// Write writes the data to the connection as part of an HTTP reply,
// Write writes the data to the connection as part of an HTTP reply,
...
@@ -910,7 +907,7 @@ func (w *responseWriter) Header() http.Header {
...
@@ -910,7 +907,7 @@ func (w *responseWriter) Header() http.Header {
// started means the response has sent out.
// started means the response has sent out.
func
(
w
*
responseWriter
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
func
(
w
*
responseWriter
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
w
.
started
=
true
w
.
started
=
true
return
w
.
w
riter
.
Write
(
p
)
return
w
.
ResponseW
riter
.
Write
(
p
)
}
}
// WriteHeader sends an HTTP response header with status code,
// WriteHeader sends an HTTP response header with status code,
...
@@ -918,23 +915,7 @@ func (w *responseWriter) Write(p []byte) (int, error) {
...
@@ -918,23 +915,7 @@ func (w *responseWriter) Write(p []byte) (int, error) {
func
(
w
*
responseWriter
)
WriteHeader
(
code
int
)
{
func
(
w
*
responseWriter
)
WriteHeader
(
code
int
)
{
w
.
status
=
code
w
.
status
=
code
w
.
started
=
true
w
.
started
=
true
w
.
writer
.
WriteHeader
(
code
)
w
.
ResponseWriter
.
WriteHeader
(
code
)
}
// hijacker for http
func
(
w
*
responseWriter
)
Hijack
()
(
net
.
Conn
,
*
bufio
.
ReadWriter
,
error
)
{
hj
,
ok
:=
w
.
writer
.
(
http
.
Hijacker
)
if
!
ok
{
return
nil
,
nil
,
errors
.
New
(
"webserver doesn't support hijacking"
)
}
return
hj
.
Hijack
()
}
func
(
w
*
responseWriter
)
Flush
()
{
f
,
ok
:=
w
.
writer
.
(
http
.
Flusher
)
if
ok
{
f
.
Flush
()
}
}
}
func
tourl
(
params
map
[
string
]
string
)
string
{
func
tourl
(
params
map
[
string
]
string
)
string
{
...
...
router_test.go
View file @
dc28e376
...
@@ -333,6 +333,18 @@ func TestRouterHandler(t *testing.T) {
...
@@ -333,6 +333,18 @@ func TestRouterHandler(t *testing.T) {
}
}
}
}
func
TestRouterHandlerAll
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/sayhi/a/b/c"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegister
()
handler
.
Handler
(
"/sayhi"
,
http
.
HandlerFunc
(
sayhello
),
true
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"sayhello"
{
t
.
Errorf
(
"TestRouterHandler can't run"
)
}
}
//
//
// Benchmarks NewApp:
// Benchmarks NewApp:
//
//
...
...
staticfile.go
View file @
dc28e376
...
@@ -96,9 +96,8 @@ func serverStaticRouter(ctx *context.Context) {
...
@@ -96,9 +96,8 @@ func serverStaticRouter(ctx *context.Context) {
}
}
isStaticFileToCompress
:=
false
isStaticFileToCompress
:=
false
lowerFileName
:=
strings
.
ToLower
(
filePath
)
for
_
,
statExtension
:=
range
StaticExtensionsToGzip
{
for
_
,
statExtension
:=
range
StaticExtensionsToGzip
{
if
strings
.
HasSuffix
(
lowerFileName
,
statExtension
)
{
if
strings
.
HasSuffix
(
strings
.
ToLower
(
filePath
),
strings
.
ToLower
(
statExtension
)
)
{
isStaticFileToCompress
=
true
isStaticFileToCompress
=
true
break
break
}
}
...
...
validation/validators.go
View file @
dc28e376
...
@@ -74,6 +74,33 @@ func (r Required) IsSatisfied(obj interface{}) bool {
...
@@ -74,6 +74,33 @@ func (r Required) IsSatisfied(obj interface{}) bool {
if
i
,
ok
:=
obj
.
(
int
);
ok
{
if
i
,
ok
:=
obj
.
(
int
);
ok
{
return
i
!=
0
return
i
!=
0
}
}
if
i
,
ok
:=
obj
.
(
uint
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
int8
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
uint8
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
int16
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
uint16
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
uint32
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
int32
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
int64
);
ok
{
return
i
!=
0
}
if
i
,
ok
:=
obj
.
(
uint64
);
ok
{
return
i
!=
0
}
if
t
,
ok
:=
obj
.
(
time
.
Time
);
ok
{
if
t
,
ok
:=
obj
.
(
time
.
Time
);
ok
{
return
!
t
.
IsZero
()
return
!
t
.
IsZero
()
}
}
...
...
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