1d8afdc9 by astaxie

gofmt -s & go_vet

1 parent 1592e9c0
...@@ -202,7 +202,7 @@ func (bc *MemoryCache) vaccuum() { ...@@ -202,7 +202,7 @@ func (bc *MemoryCache) vaccuum() {
202 if bc.items == nil { 202 if bc.items == nil {
203 return 203 return
204 } 204 }
205 for name, _ := range bc.items { 205 for name := range bc.items {
206 bc.item_expired(name) 206 bc.item_expired(name)
207 } 207 }
208 } 208 }
......
...@@ -324,7 +324,7 @@ func (d *dbBase) Read(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Lo ...@@ -324,7 +324,7 @@ func (d *dbBase) Read(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Lo
324 query := fmt.Sprintf("SELECT %s%s%s FROM %s%s%s WHERE %s%s%s = ?", Q, sels, Q, Q, mi.table, Q, Q, wheres, Q) 324 query := fmt.Sprintf("SELECT %s%s%s FROM %s%s%s WHERE %s%s%s = ?", Q, sels, Q, Q, mi.table, Q, Q, wheres, Q)
325 325
326 refs := make([]interface{}, colsNum) 326 refs := make([]interface{}, colsNum)
327 for i, _ := range refs { 327 for i := range refs {
328 var ref interface{} 328 var ref interface{}
329 refs[i] = &ref 329 refs[i] = &ref
330 } 330 }
...@@ -423,7 +423,7 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s ...@@ -423,7 +423,7 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s
423 Q := d.ins.TableQuote() 423 Q := d.ins.TableQuote()
424 424
425 marks := make([]string, len(names)) 425 marks := make([]string, len(names))
426 for i, _ := range marks { 426 for i := range marks {
427 marks[i] = "?" 427 marks[i] = "?"
428 } 428 }
429 429
...@@ -693,7 +693,7 @@ func (d *dbBase) DeleteBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con ...@@ -693,7 +693,7 @@ func (d *dbBase) DeleteBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
693 } 693 }
694 694
695 marks := make([]string, len(args)) 695 marks := make([]string, len(args))
696 for i, _ := range marks { 696 for i := range marks {
697 marks[i] = "?" 697 marks[i] = "?"
698 } 698 }
699 sql := fmt.Sprintf("IN (%s)", strings.Join(marks, ", ")) 699 sql := fmt.Sprintf("IN (%s)", strings.Join(marks, ", "))
...@@ -824,7 +824,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi ...@@ -824,7 +824,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
824 } 824 }
825 825
826 refs := make([]interface{}, colsNum) 826 refs := make([]interface{}, colsNum)
827 for i, _ := range refs { 827 for i := range refs {
828 var ref interface{} 828 var ref interface{}
829 refs[i] = &ref 829 refs[i] = &ref
830 } 830 }
...@@ -964,7 +964,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri ...@@ -964,7 +964,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri
964 switch operator { 964 switch operator {
965 case "in": 965 case "in":
966 marks := make([]string, len(params)) 966 marks := make([]string, len(params))
967 for i, _ := range marks { 967 for i := range marks {
968 marks[i] = "?" 968 marks[i] = "?"
969 } 969 }
970 sql = fmt.Sprintf("IN (%s)", strings.Join(marks, ", ")) 970 sql = fmt.Sprintf("IN (%s)", strings.Join(marks, ", "))
...@@ -1460,7 +1460,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond ...@@ -1460,7 +1460,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
1460 } 1460 }
1461 1461
1462 refs := make([]interface{}, len(cols)) 1462 refs := make([]interface{}, len(cols))
1463 for i, _ := range refs { 1463 for i := range refs {
1464 var ref interface{} 1464 var ref interface{}
1465 refs[i] = &ref 1465 refs[i] = &ref
1466 } 1466 }
......
...@@ -242,14 +242,14 @@ type User struct { ...@@ -242,14 +242,14 @@ type User struct {
242 242
243 func (u *User) TableIndex() [][]string { 243 func (u *User) TableIndex() [][]string {
244 return [][]string{ 244 return [][]string{
245 []string{"Id", "UserName"}, 245 {"Id", "UserName"},
246 []string{"Id", "Created"}, 246 {"Id", "Created"},
247 } 247 }
248 } 248 }
249 249
250 func (u *User) TableUnique() [][]string { 250 func (u *User) TableUnique() [][]string {
251 return [][]string{ 251 return [][]string{
252 []string{"UserName", "Email"}, 252 {"UserName", "Email"},
253 } 253 }
254 } 254 }
255 255
...@@ -287,7 +287,7 @@ type Post struct { ...@@ -287,7 +287,7 @@ type Post struct {
287 287
288 func (u *Post) TableIndex() [][]string { 288 func (u *Post) TableIndex() [][]string {
289 return [][]string{ 289 return [][]string{
290 []string{"Id", "Created"}, 290 {"Id", "Created"},
291 } 291 }
292 } 292 }
293 293
......
...@@ -585,7 +585,7 @@ func (o *rawSet) readValues(container interface{}, needCols []string) (int64, er ...@@ -585,7 +585,7 @@ func (o *rawSet) readValues(container interface{}, needCols []string) (int64, er
585 585
586 cols = columns 586 cols = columns
587 refs = make([]interface{}, len(cols)) 587 refs = make([]interface{}, len(cols))
588 for i, _ := range refs { 588 for i := range refs {
589 var ref sql.NullString 589 var ref sql.NullString
590 refs[i] = &ref 590 refs[i] = &ref
591 591
...@@ -711,7 +711,7 @@ func (o *rawSet) queryRowsTo(container interface{}, keyCol, valueCol string) (in ...@@ -711,7 +711,7 @@ func (o *rawSet) queryRowsTo(container interface{}, keyCol, valueCol string) (in
711 } else { 711 } else {
712 cols = columns 712 cols = columns
713 refs = make([]interface{}, len(cols)) 713 refs = make([]interface{}, len(cols))
714 for i, _ := range refs { 714 for i := range refs {
715 if keyCol == cols[i] { 715 if keyCol == cols[i] {
716 keyIndex = i 716 keyIndex = i
717 } 717 }
......
...@@ -586,29 +586,29 @@ func TestInsertTestData(t *testing.T) { ...@@ -586,29 +586,29 @@ func TestInsertTestData(t *testing.T) {
586 throwFail(t, AssertIs(id, 4)) 586 throwFail(t, AssertIs(id, 4))
587 587
588 tags := []*Tag{ 588 tags := []*Tag{
589 &Tag{Name: "golang", BestPost: &Post{Id: 2}}, 589 {Name: "golang", BestPost: &Post{Id: 2}},
590 &Tag{Name: "example"}, 590 {Name: "example"},
591 &Tag{Name: "format"}, 591 {Name: "format"},
592 &Tag{Name: "c++"}, 592 {Name: "c++"},
593 } 593 }
594 594
595 posts := []*Post{ 595 posts := []*Post{
596 &Post{User: users[0], Tags: []*Tag{tags[0]}, Title: "Introduction", Content: `Go is a new language. Although it borrows ideas from existing languages, it has unusual properties that make effective Go programs different in character from programs written in its relatives. A straightforward translation of a C++ or Java program into Go is unlikely to produce a satisfactory result—Java programs are written in Java, not Go. On the other hand, thinking about the problem from a Go perspective could produce a successful but quite different program. In other words, to write Go well, it's important to understand its properties and idioms. It's also important to know the established conventions for programming in Go, such as naming, formatting, program construction, and so on, so that programs you write will be easy for other Go programmers to understand. 596 {User: users[0], Tags: []*Tag{tags[0]}, Title: "Introduction", Content: `Go is a new language. Although it borrows ideas from existing languages, it has unusual properties that make effective Go programs different in character from programs written in its relatives. A straightforward translation of a C++ or Java program into Go is unlikely to produce a satisfactory result—Java programs are written in Java, not Go. On the other hand, thinking about the problem from a Go perspective could produce a successful but quite different program. In other words, to write Go well, it's important to understand its properties and idioms. It's also important to know the established conventions for programming in Go, such as naming, formatting, program construction, and so on, so that programs you write will be easy for other Go programmers to understand.
597 This document gives tips for writing clear, idiomatic Go code. It augments the language specification, the Tour of Go, and How to Write Go Code, all of which you should read first.`}, 597 This document gives tips for writing clear, idiomatic Go code. It augments the language specification, the Tour of Go, and How to Write Go Code, all of which you should read first.`},
598 &Post{User: users[1], Tags: []*Tag{tags[0], tags[1]}, Title: "Examples", Content: `The Go package sources are intended to serve not only as the core library but also as examples of how to use the language. Moreover, many of the packages contain working, self-contained executable examples you can run directly from the golang.org web site, such as this one (click on the word "Example" to open it up). If you have a question about how to approach a problem or how something might be implemented, the documentation, code and examples in the library can provide answers, ideas and background.`}, 598 {User: users[1], Tags: []*Tag{tags[0], tags[1]}, Title: "Examples", Content: `The Go package sources are intended to serve not only as the core library but also as examples of how to use the language. Moreover, many of the packages contain working, self-contained executable examples you can run directly from the golang.org web site, such as this one (click on the word "Example" to open it up). If you have a question about how to approach a problem or how something might be implemented, the documentation, code and examples in the library can provide answers, ideas and background.`},
599 &Post{User: users[1], Tags: []*Tag{tags[0], tags[2]}, Title: "Formatting", Content: `Formatting issues are the most contentious but the least consequential. People can adapt to different formatting styles but it's better if they don't have to, and less time is devoted to the topic if everyone adheres to the same style. The problem is how to approach this Utopia without a long prescriptive style guide. 599 {User: users[1], Tags: []*Tag{tags[0], tags[2]}, Title: "Formatting", Content: `Formatting issues are the most contentious but the least consequential. People can adapt to different formatting styles but it's better if they don't have to, and less time is devoted to the topic if everyone adheres to the same style. The problem is how to approach this Utopia without a long prescriptive style guide.
600 With Go we take an unusual approach and let the machine take care of most formatting issues. The gofmt program (also available as go fmt, which operates at the package level rather than source file level) reads a Go program and emits the source in a standard style of indentation and vertical alignment, retaining and if necessary reformatting comments. If you want to know how to handle some new layout situation, run gofmt; if the answer doesn't seem right, rearrange your program (or file a bug about gofmt), don't work around it.`}, 600 With Go we take an unusual approach and let the machine take care of most formatting issues. The gofmt program (also available as go fmt, which operates at the package level rather than source file level) reads a Go program and emits the source in a standard style of indentation and vertical alignment, retaining and if necessary reformatting comments. If you want to know how to handle some new layout situation, run gofmt; if the answer doesn't seem right, rearrange your program (or file a bug about gofmt), don't work around it.`},
601 &Post{User: users[2], Tags: []*Tag{tags[3]}, Title: "Commentary", Content: `Go provides C-style /* */ block comments and C++-style // line comments. Line comments are the norm; block comments appear mostly as package comments, but are useful within an expression or to disable large swaths of code. 601 {User: users[2], Tags: []*Tag{tags[3]}, Title: "Commentary", Content: `Go provides C-style /* */ block comments and C++-style // line comments. Line comments are the norm; block comments appear mostly as package comments, but are useful within an expression or to disable large swaths of code.
602 The program—and web server—godoc processes Go source files to extract documentation about the contents of the package. Comments that appear before top-level declarations, with no intervening newlines, are extracted along with the declaration to serve as explanatory text for the item. The nature and style of these comments determines the quality of the documentation godoc produces.`}, 602 The program—and web server—godoc processes Go source files to extract documentation about the contents of the package. Comments that appear before top-level declarations, with no intervening newlines, are extracted along with the declaration to serve as explanatory text for the item. The nature and style of these comments determines the quality of the documentation godoc produces.`},
603 } 603 }
604 604
605 comments := []*Comment{ 605 comments := []*Comment{
606 &Comment{Post: posts[0], Content: "a comment"}, 606 {Post: posts[0], Content: "a comment"},
607 &Comment{Post: posts[1], Content: "yes"}, 607 {Post: posts[1], Content: "yes"},
608 &Comment{Post: posts[1]}, 608 {Post: posts[1]},
609 &Comment{Post: posts[1]}, 609 {Post: posts[1]},
610 &Comment{Post: posts[2]}, 610 {Post: posts[2]},
611 &Comment{Post: posts[2]}, 611 {Post: posts[2]},
612 } 612 }
613 613
614 for _, tag := range tags { 614 for _, tag := range tags {
...@@ -1248,7 +1248,7 @@ func TestQueryM2M(t *testing.T) { ...@@ -1248,7 +1248,7 @@ func TestQueryM2M(t *testing.T) {
1248 post := Post{Id: 4} 1248 post := Post{Id: 4}
1249 m2m := dORM.QueryM2M(&post, "Tags") 1249 m2m := dORM.QueryM2M(&post, "Tags")
1250 1250
1251 tag1 := []*Tag{&Tag{Name: "TestTag1"}, &Tag{Name: "TestTag2"}} 1251 tag1 := []*Tag{{Name: "TestTag1"}, {Name: "TestTag2"}}
1252 tag2 := &Tag{Name: "TestTag3"} 1252 tag2 := &Tag{Name: "TestTag3"}
1253 tag3 := []interface{}{&Tag{Name: "TestTag4"}} 1253 tag3 := []interface{}{&Tag{Name: "TestTag4"}}
1254 1254
...@@ -1311,7 +1311,7 @@ func TestQueryM2M(t *testing.T) { ...@@ -1311,7 +1311,7 @@ func TestQueryM2M(t *testing.T) {
1311 1311
1312 m2m = dORM.QueryM2M(&tag, "Posts") 1312 m2m = dORM.QueryM2M(&tag, "Posts")
1313 1313
1314 post1 := []*Post{&Post{Title: "TestPost1"}, &Post{Title: "TestPost2"}} 1314 post1 := []*Post{{Title: "TestPost1"}, {Title: "TestPost2"}}
1315 post2 := &Post{Title: "TestPost3"} 1315 post2 := &Post{Title: "TestPost3"}
1316 post3 := []interface{}{&Post{Title: "TestPost4"}} 1316 post3 := []interface{}{&Post{Title: "TestPost4"}}
1317 1317
......
...@@ -195,7 +195,7 @@ func snakeString(s string) string { ...@@ -195,7 +195,7 @@ func snakeString(s string) string {
195 } 195 }
196 data = append(data, d) 196 data = append(data, d)
197 } 197 }
198 return strings.ToLower(string(data[:len(data)])) 198 return strings.ToLower(string(data[:]))
199 } 199 }
200 200
201 // camel string, xx_yy to XxYy 201 // camel string, xx_yy to XxYy
...@@ -220,7 +220,7 @@ func camelString(s string) string { ...@@ -220,7 +220,7 @@ func camelString(s string) string {
220 } 220 }
221 data = append(data, d) 221 data = append(data, d)
222 } 222 }
223 return string(data[:len(data)]) 223 return string(data[:])
224 } 224 }
225 225
226 type argString []string 226 type argString []string
......
...@@ -88,7 +88,7 @@ func (l *logFilter) Filter(ctx *beecontext.Context) bool { ...@@ -88,7 +88,7 @@ func (l *logFilter) Filter(ctx *beecontext.Context) bool {
88 if requestPath == "/favicon.ico" || requestPath == "/robots.txt" { 88 if requestPath == "/favicon.ico" || requestPath == "/robots.txt" {
89 return true 89 return true
90 } 90 }
91 for prefix, _ := range StaticDir { 91 for prefix := range StaticDir {
92 if strings.HasPrefix(requestPath, prefix) { 92 if strings.HasPrefix(requestPath, prefix) {
93 return true 93 return true
94 } 94 }
...@@ -171,7 +171,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM ...@@ -171,7 +171,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
171 p.addToRouter(m, pattern, route) 171 p.addToRouter(m, pattern, route)
172 } 172 }
173 } else { 173 } else {
174 for k, _ := range methods { 174 for k := range methods {
175 if k == "*" { 175 if k == "*" {
176 for _, m := range HTTPMETHOD { 176 for _, m := range HTTPMETHOD {
177 p.addToRouter(m, pattern, route) 177 p.addToRouter(m, pattern, route)
...@@ -332,7 +332,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) { ...@@ -332,7 +332,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) {
332 methods[strings.ToUpper(method)] = strings.ToUpper(method) 332 methods[strings.ToUpper(method)] = strings.ToUpper(method)
333 } 333 }
334 route.methods = methods 334 route.methods = methods
335 for k, _ := range methods { 335 for k := range methods {
336 if k == "*" { 336 if k == "*" {
337 for _, m := range HTTPMETHOD { 337 for _, m := range HTTPMETHOD {
338 p.addToRouter(m, pattern, route) 338 p.addToRouter(m, pattern, route)
......
...@@ -179,7 +179,6 @@ func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionSto ...@@ -179,7 +179,6 @@ func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionSto
179 } else { 179 } else {
180 client.Delete(oldsid) 180 client.Delete(oldsid)
181 item.Key = sid 181 item.Key = sid
182 item.Value = item.Value
183 item.Expiration = int32(rp.maxlifetime) 182 item.Expiration = int32(rp.maxlifetime)
184 client.Set(item) 183 client.Set(item)
185 contain = item.Value 184 contain = item.Value
......
...@@ -292,7 +292,7 @@ func qpEscape(dest []byte, c byte) { ...@@ -292,7 +292,7 @@ func qpEscape(dest []byte, c byte) {
292 const nums = "0123456789ABCDEF" 292 const nums = "0123456789ABCDEF"
293 dest[0] = '=' 293 dest[0] = '='
294 dest[1] = nums[(c&0xf0)>>4] 294 dest[1] = nums[(c&0xf0)>>4]
295 dest[2] = nums[(c&0xf)] 295 dest[2] = nums[(c & 0xf)]
296 } 296 }
297 297
298 // headerToBytes enumerates the key and values in the header, and writes the results to the IO Writer 298 // headerToBytes enumerates the key and values in the header, and writes the results to the IO Writer
......
...@@ -92,18 +92,18 @@ func (p *Paginator) Pages() []int { ...@@ -92,18 +92,18 @@ func (p *Paginator) Pages() []int {
92 case page >= pageNums-4 && pageNums > 9: 92 case page >= pageNums-4 && pageNums > 9:
93 start := pageNums - 9 + 1 93 start := pageNums - 9 + 1
94 pages = make([]int, 9) 94 pages = make([]int, 9)
95 for i, _ := range pages { 95 for i := range pages {
96 pages[i] = start + i 96 pages[i] = start + i
97 } 97 }
98 case page >= 5 && pageNums > 9: 98 case page >= 5 && pageNums > 9:
99 start := page - 5 + 1 99 start := page - 5 + 1
100 pages = make([]int, int(math.Min(9, float64(page+4+1)))) 100 pages = make([]int, int(math.Min(9, float64(page+4+1))))
101 for i, _ := range pages { 101 for i := range pages {
102 pages[i] = start + i 102 pages[i] = start + i
103 } 103 }
104 default: 104 default:
105 pages = make([]int, int(math.Min(9, float64(pageNums)))) 105 pages = make([]int, int(math.Min(9, float64(pageNums))))
106 for i, _ := range pages { 106 for i := range pages {
107 pages[i] = i + 1 107 pages[i] = i + 1
108 } 108 }
109 } 109 }
......
...@@ -51,7 +51,7 @@ func SliceRandList(min, max int) []int { ...@@ -51,7 +51,7 @@ func SliceRandList(min, max int) []int {
51 t0 := time.Now() 51 t0 := time.Now()
52 rand.Seed(int64(t0.Nanosecond())) 52 rand.Seed(int64(t0.Nanosecond()))
53 list := rand.Perm(length) 53 list := rand.Perm(length)
54 for index, _ := range list { 54 for index := range list {
55 list[index] += min 55 list[index] += min
56 } 56 }
57 return list 57 return list
......
...@@ -137,7 +137,7 @@ func getRegFuncs(tag, key string) (vfs []ValidFunc, str string, err error) { ...@@ -137,7 +137,7 @@ func getRegFuncs(tag, key string) (vfs []ValidFunc, str string, err error) {
137 if err != nil { 137 if err != nil {
138 return 138 return
139 } 139 }
140 vfs = []ValidFunc{ValidFunc{"Match", []interface{}{reg, key + ".Match"}}} 140 vfs = []ValidFunc{{"Match", []interface{}{reg, key + ".Match"}}}
141 str = strings.TrimSpace(tag[:index]) + strings.TrimSpace(tag[end+len("/)"):]) 141 str = strings.TrimSpace(tag[:index]) + strings.TrimSpace(tag[end+len("/)"):])
142 return 142 return
143 } 143 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!