Skip to content

Commit b0e2bbc

Browse files
authored
Merge pull request beego#3391 from astaxie/develop
V1.11.0
2 parents 053a075 + 7a50ea7 commit b0e2bbc

File tree

596 files changed

+343087
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

596 files changed

+343087
-176
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
language: go
22

33
go:
4-
- "1.9.7"
5-
- "1.10.3"
4+
- "1.9.x"
5+
- "1.10.x"
6+
- "1.11.x"
67
services:
78
- redis-server
89
- mysql
@@ -34,6 +35,7 @@ install:
3435
- go get github.com/gogo/protobuf/proto
3536
- go get github.com/Knetic/govaluate
3637
- go get github.com/casbin/casbin
38+
- go get github.com/elazarl/go-bindata-assetfs
3739
- go get -u honnef.co/go/tools/cmd/gosimple
3840
- go get -u github.com/mdempsky/unconvert
3941
- go get -u github.com/gordonklaus/ineffassign

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
beego is used for rapid development of RESTful APIs, web apps and backend services in Go.
55
It is inspired by Tornado, Sinatra and Flask. beego has some Go-specific features such as interfaces and struct embedding.
66

7+
Response time ranking: [web-frameworks](https://github.com/the-benchmarker/web-frameworks).
8+
79
###### More info at [beego.me](http://beego.me).
810

911
## Quick Start

admin.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
var beeAdminApp *adminApp
3636

3737
// FilterMonitorFunc is default monitor filter when admin module is enable.
38-
// if this func returns, admin module records qbs for this request by condition of this function logic.
38+
// if this func returns, admin module records qps for this request by condition of this function logic.
3939
// usage:
4040
// func MyFilterMonitor(method, requestPath string, t time.Duration, pattern string, statusCode int) bool {
4141
// if method == "POST" {
@@ -67,18 +67,18 @@ func init() {
6767

6868
// AdminIndex is the default http.Handler for admin module.
6969
// it matches url pattern "/".
70-
func adminIndex(rw http.ResponseWriter, r *http.Request) {
70+
func adminIndex(rw http.ResponseWriter, _ *http.Request) {
7171
execTpl(rw, map[interface{}]interface{}{}, indexTpl, defaultScriptsTpl)
7272
}
7373

74-
// QpsIndex is the http.Handler for writing qbs statistics map result info in http.ResponseWriter.
75-
// it's registered with url pattern "/qbs" in admin module.
76-
func qpsIndex(rw http.ResponseWriter, r *http.Request) {
74+
// QpsIndex is the http.Handler for writing qps statistics map result info in http.ResponseWriter.
75+
// it's registered with url pattern "/qps" in admin module.
76+
func qpsIndex(rw http.ResponseWriter, _ *http.Request) {
7777
data := make(map[interface{}]interface{})
7878
data["Content"] = toolbox.StatisticsMap.GetMap()
7979

8080
// do html escape before display path, avoid xss
81-
if content, ok := (data["Content"]).(map[string]interface{}); ok {
81+
if content, ok := (data["Content"]).(M); ok {
8282
if resultLists, ok := (content["Data"]).([][]string); ok {
8383
for i := range resultLists {
8484
if len(resultLists[i]) > 0 {
@@ -104,7 +104,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
104104
data := make(map[interface{}]interface{})
105105
switch command {
106106
case "conf":
107-
m := make(map[string]interface{})
107+
m := make(M)
108108
list("BConfig", BConfig, m)
109109
m["AppConfigPath"] = appConfigPath
110110
m["AppConfigProvider"] = appConfigProvider
@@ -128,14 +128,14 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
128128
execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
129129
case "filter":
130130
var (
131-
content = map[string]interface{}{
131+
content = M{
132132
"Fields": []string{
133133
"Router Pattern",
134134
"Filter Function",
135135
},
136136
}
137137
filterTypes = []string{}
138-
filterTypeData = make(map[string]interface{})
138+
filterTypeData = make(M)
139139
)
140140

141141
if BeeApp.Handlers.enableFilter {
@@ -173,7 +173,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
173173
}
174174
}
175175

176-
func list(root string, p interface{}, m map[string]interface{}) {
176+
func list(root string, p interface{}, m M) {
177177
pt := reflect.TypeOf(p)
178178
pv := reflect.ValueOf(p)
179179
if pt.Kind() == reflect.Ptr {
@@ -196,11 +196,11 @@ func list(root string, p interface{}, m map[string]interface{}) {
196196
}
197197

198198
// PrintTree prints all registered routers.
199-
func PrintTree() map[string]interface{} {
199+
func PrintTree() M {
200200
var (
201-
content = map[string]interface{}{}
201+
content = M{}
202202
methods = []string{}
203-
methodsData = make(map[string]interface{})
203+
methodsData = make(M)
204204
)
205205
for method, t := range BeeApp.Handlers.routers {
206206

@@ -291,12 +291,12 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
291291

292292
// Healthcheck is a http.Handler calling health checking and showing the result.
293293
// it's in "/healthcheck" pattern in admin module.
294-
func healthcheck(rw http.ResponseWriter, req *http.Request) {
294+
func healthcheck(rw http.ResponseWriter, _ *http.Request) {
295295
var (
296296
result []string
297297
data = make(map[interface{}]interface{})
298298
resultList = new([][]string)
299-
content = map[string]interface{}{
299+
content = M{
300300
"Fields": []string{"Name", "Message", "Status"},
301301
}
302302
)
@@ -344,7 +344,7 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
344344
}
345345

346346
// List Tasks
347-
content := make(map[string]interface{})
347+
content := make(M)
348348
resultList := new([][]string)
349349
var fields = []string{
350350
"Task Name",

admin_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func TestList_01(t *testing.T) {
9-
m := make(map[string]interface{})
9+
m := make(M)
1010
list("BConfig", BConfig, m)
1111
t.Log(m)
1212
om := oldMap()
@@ -18,8 +18,8 @@ func TestList_01(t *testing.T) {
1818
}
1919
}
2020

21-
func oldMap() map[string]interface{} {
22-
m := make(map[string]interface{})
21+
func oldMap() M {
22+
m := make(M)
2323
m["BConfig.AppName"] = BConfig.AppName
2424
m["BConfig.RunMode"] = BConfig.RunMode
2525
m["BConfig.RouterCaseSensitive"] = BConfig.RouterCaseSensitive

beego.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ import (
2323

2424
const (
2525
// VERSION represent beego web framework version.
26-
VERSION = "1.10.1"
26+
VERSION = "1.11.0"
2727

2828
// DEV is for develop
2929
DEV = "dev"
3030
// PROD is for production
3131
PROD = "prod"
3232
)
3333

34-
//hook function to run
34+
// M is Map shortcut
35+
type M map[string]interface{}
36+
37+
// Hook function to run
3538
type hookfunc func() error
3639

3740
var (

cache/memory.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,17 @@ func (bc *MemoryCache) StartAndGC(config string) error {
203203
dur := time.Duration(cf["interval"]) * time.Second
204204
bc.Every = cf["interval"]
205205
bc.dur = dur
206-
go bc.vaccuum()
206+
go bc.vacuum()
207207
return nil
208208
}
209209

210210
// check expiration.
211-
func (bc *MemoryCache) vaccuum() {
212-
if bc.Every < 1 {
211+
func (bc *MemoryCache) vacuum() {
212+
bc.RLock()
213+
every := bc.Every
214+
bc.RUnlock()
215+
216+
if every < 1 {
213217
return
214218
}
215219
for {

cache/redis/redis.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/gomodule/redigo/redis"
4040

4141
"github.com/astaxie/beego/cache"
42+
"strings"
4243
)
4344

4445
var (
@@ -164,6 +165,14 @@ func (rc *Cache) StartAndGC(config string) error {
164165
if _, ok := cf["conn"]; !ok {
165166
return errors.New("config has no conn key")
166167
}
168+
169+
// Format redis://<password>@<host>:<port>
170+
cf["conn"] = strings.Replace(cf["conn"], "redis://", "", 1)
171+
if i := strings.Index(cf["conn"], "@"); i > -1 {
172+
cf["password"] = cf["conn"][0:i]
173+
cf["conn"] = cf["conn"][i+1:]
174+
}
175+
167176
if _, ok := cf["dbNum"]; !ok {
168177
cf["dbNum"] = "0"
169178
}

config/ini.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,37 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
7878
}
7979
}
8080
section := defaultSection
81+
tmpBuf := bytes.NewBuffer(nil)
8182
for {
82-
line, _, err := buf.ReadLine()
83-
if err == io.EOF {
84-
break
83+
tmpBuf.Reset()
84+
85+
shouldBreak := false
86+
for {
87+
tmp, isPrefix, err := buf.ReadLine()
88+
if err == io.EOF {
89+
shouldBreak = true
90+
break
91+
}
92+
93+
//It might be a good idea to throw a error on all unknonw errors?
94+
if _, ok := err.(*os.PathError); ok {
95+
return nil, err
96+
}
97+
98+
tmpBuf.Write(tmp)
99+
if isPrefix {
100+
continue
101+
}
102+
103+
if !isPrefix {
104+
break
105+
}
85106
}
86-
//It might be a good idea to throw a error on all unknonw errors?
87-
if _, ok := err.(*os.PathError); ok {
88-
return nil, err
107+
if shouldBreak {
108+
break
89109
}
110+
111+
line := tmpBuf.Bytes()
90112
line = bytes.TrimSpace(line)
91113
if bytes.Equal(line, bEmpty) {
92114
continue

config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ func TestAssignConfig_02(t *testing.T) {
4848
_BConfig := &Config{}
4949
bs, _ := json.Marshal(newBConfig())
5050

51-
jsonMap := map[string]interface{}{}
51+
jsonMap := M{}
5252
json.Unmarshal(bs, &jsonMap)
5353

54-
configMap := map[string]interface{}{}
54+
configMap := M{}
5555
for k, v := range jsonMap {
5656
if reflect.TypeOf(v).Kind() == reflect.Map {
57-
for k1, v1 := range v.(map[string]interface{}) {
57+
for k1, v1 := range v.(M) {
5858
if reflect.TypeOf(v1).Kind() == reflect.Map {
59-
for k2, v2 := range v1.(map[string]interface{}) {
59+
for k2, v2 := range v1.(M) {
6060
configMap[k2] = v2
6161
}
6262
} else {

context/context.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ import (
3838
"github.com/astaxie/beego/utils"
3939
)
4040

41+
//commonly used mime-types
42+
const (
43+
ApplicationJSON = "application/json"
44+
ApplicationXML = "application/xml"
45+
ApplicationYAML = "application/x-yaml"
46+
TextXML = "text/xml"
47+
)
48+
4149
// NewContext return the Context with Input and Output
4250
func NewContext() *Context {
4351
return &Context{
@@ -244,3 +252,11 @@ func (r *Response) CloseNotify() <-chan bool {
244252
}
245253
return nil
246254
}
255+
256+
// Pusher http.Pusher
257+
func (r *Response) Pusher() (pusher http.Pusher) {
258+
if pusher, ok := r.ResponseWriter.(http.Pusher); ok {
259+
return pusher
260+
}
261+
return nil
262+
}

0 commit comments

Comments
 (0)