mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 21:01:31 +00:00
gofmt -s & go_vet
This commit is contained in:
parent
1592e9c04d
commit
1d8afdc9c9
2
cache/memory.go
vendored
2
cache/memory.go
vendored
@ -202,7 +202,7 @@ func (bc *MemoryCache) vaccuum() {
|
|||||||
if bc.items == nil {
|
if bc.items == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for name, _ := range bc.items {
|
for name := range bc.items {
|
||||||
bc.item_expired(name)
|
bc.item_expired(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
orm/db.go
12
orm/db.go
@ -324,7 +324,7 @@ func (d *dbBase) Read(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Lo
|
|||||||
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)
|
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)
|
||||||
|
|
||||||
refs := make([]interface{}, colsNum)
|
refs := make([]interface{}, colsNum)
|
||||||
for i, _ := range refs {
|
for i := range refs {
|
||||||
var ref interface{}
|
var ref interface{}
|
||||||
refs[i] = &ref
|
refs[i] = &ref
|
||||||
}
|
}
|
||||||
@ -423,7 +423,7 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s
|
|||||||
Q := d.ins.TableQuote()
|
Q := d.ins.TableQuote()
|
||||||
|
|
||||||
marks := make([]string, len(names))
|
marks := make([]string, len(names))
|
||||||
for i, _ := range marks {
|
for i := range marks {
|
||||||
marks[i] = "?"
|
marks[i] = "?"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,7 +693,7 @@ func (d *dbBase) DeleteBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
marks := make([]string, len(args))
|
marks := make([]string, len(args))
|
||||||
for i, _ := range marks {
|
for i := range marks {
|
||||||
marks[i] = "?"
|
marks[i] = "?"
|
||||||
}
|
}
|
||||||
sql := fmt.Sprintf("IN (%s)", strings.Join(marks, ", "))
|
sql := fmt.Sprintf("IN (%s)", strings.Join(marks, ", "))
|
||||||
@ -824,7 +824,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
|
|||||||
}
|
}
|
||||||
|
|
||||||
refs := make([]interface{}, colsNum)
|
refs := make([]interface{}, colsNum)
|
||||||
for i, _ := range refs {
|
for i := range refs {
|
||||||
var ref interface{}
|
var ref interface{}
|
||||||
refs[i] = &ref
|
refs[i] = &ref
|
||||||
}
|
}
|
||||||
@ -964,7 +964,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri
|
|||||||
switch operator {
|
switch operator {
|
||||||
case "in":
|
case "in":
|
||||||
marks := make([]string, len(params))
|
marks := make([]string, len(params))
|
||||||
for i, _ := range marks {
|
for i := range marks {
|
||||||
marks[i] = "?"
|
marks[i] = "?"
|
||||||
}
|
}
|
||||||
sql = fmt.Sprintf("IN (%s)", strings.Join(marks, ", "))
|
sql = fmt.Sprintf("IN (%s)", strings.Join(marks, ", "))
|
||||||
@ -1460,7 +1460,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
|
|||||||
}
|
}
|
||||||
|
|
||||||
refs := make([]interface{}, len(cols))
|
refs := make([]interface{}, len(cols))
|
||||||
for i, _ := range refs {
|
for i := range refs {
|
||||||
var ref interface{}
|
var ref interface{}
|
||||||
refs[i] = &ref
|
refs[i] = &ref
|
||||||
}
|
}
|
||||||
|
@ -242,14 +242,14 @@ type User struct {
|
|||||||
|
|
||||||
func (u *User) TableIndex() [][]string {
|
func (u *User) TableIndex() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"Id", "UserName"},
|
{"Id", "UserName"},
|
||||||
[]string{"Id", "Created"},
|
{"Id", "Created"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) TableUnique() [][]string {
|
func (u *User) TableUnique() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"UserName", "Email"},
|
{"UserName", "Email"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ type Post struct {
|
|||||||
|
|
||||||
func (u *Post) TableIndex() [][]string {
|
func (u *Post) TableIndex() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"Id", "Created"},
|
{"Id", "Created"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,7 +585,7 @@ func (o *rawSet) readValues(container interface{}, needCols []string) (int64, er
|
|||||||
|
|
||||||
cols = columns
|
cols = columns
|
||||||
refs = make([]interface{}, len(cols))
|
refs = make([]interface{}, len(cols))
|
||||||
for i, _ := range refs {
|
for i := range refs {
|
||||||
var ref sql.NullString
|
var ref sql.NullString
|
||||||
refs[i] = &ref
|
refs[i] = &ref
|
||||||
|
|
||||||
@ -711,7 +711,7 @@ func (o *rawSet) queryRowsTo(container interface{}, keyCol, valueCol string) (in
|
|||||||
} else {
|
} else {
|
||||||
cols = columns
|
cols = columns
|
||||||
refs = make([]interface{}, len(cols))
|
refs = make([]interface{}, len(cols))
|
||||||
for i, _ := range refs {
|
for i := range refs {
|
||||||
if keyCol == cols[i] {
|
if keyCol == cols[i] {
|
||||||
keyIndex = i
|
keyIndex = i
|
||||||
}
|
}
|
||||||
|
@ -586,29 +586,29 @@ func TestInsertTestData(t *testing.T) {
|
|||||||
throwFail(t, AssertIs(id, 4))
|
throwFail(t, AssertIs(id, 4))
|
||||||
|
|
||||||
tags := []*Tag{
|
tags := []*Tag{
|
||||||
&Tag{Name: "golang", BestPost: &Post{Id: 2}},
|
{Name: "golang", BestPost: &Post{Id: 2}},
|
||||||
&Tag{Name: "example"},
|
{Name: "example"},
|
||||||
&Tag{Name: "format"},
|
{Name: "format"},
|
||||||
&Tag{Name: "c++"},
|
{Name: "c++"},
|
||||||
}
|
}
|
||||||
|
|
||||||
posts := []*Post{
|
posts := []*Post{
|
||||||
&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.
|
{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.
|
||||||
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.`},
|
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.`},
|
||||||
&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.`},
|
{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.`},
|
||||||
&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.
|
{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.
|
||||||
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.`},
|
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.`},
|
||||||
&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.
|
{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.
|
||||||
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.`},
|
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.`},
|
||||||
}
|
}
|
||||||
|
|
||||||
comments := []*Comment{
|
comments := []*Comment{
|
||||||
&Comment{Post: posts[0], Content: "a comment"},
|
{Post: posts[0], Content: "a comment"},
|
||||||
&Comment{Post: posts[1], Content: "yes"},
|
{Post: posts[1], Content: "yes"},
|
||||||
&Comment{Post: posts[1]},
|
{Post: posts[1]},
|
||||||
&Comment{Post: posts[1]},
|
{Post: posts[1]},
|
||||||
&Comment{Post: posts[2]},
|
{Post: posts[2]},
|
||||||
&Comment{Post: posts[2]},
|
{Post: posts[2]},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
@ -1248,7 +1248,7 @@ func TestQueryM2M(t *testing.T) {
|
|||||||
post := Post{Id: 4}
|
post := Post{Id: 4}
|
||||||
m2m := dORM.QueryM2M(&post, "Tags")
|
m2m := dORM.QueryM2M(&post, "Tags")
|
||||||
|
|
||||||
tag1 := []*Tag{&Tag{Name: "TestTag1"}, &Tag{Name: "TestTag2"}}
|
tag1 := []*Tag{{Name: "TestTag1"}, {Name: "TestTag2"}}
|
||||||
tag2 := &Tag{Name: "TestTag3"}
|
tag2 := &Tag{Name: "TestTag3"}
|
||||||
tag3 := []interface{}{&Tag{Name: "TestTag4"}}
|
tag3 := []interface{}{&Tag{Name: "TestTag4"}}
|
||||||
|
|
||||||
@ -1311,7 +1311,7 @@ func TestQueryM2M(t *testing.T) {
|
|||||||
|
|
||||||
m2m = dORM.QueryM2M(&tag, "Posts")
|
m2m = dORM.QueryM2M(&tag, "Posts")
|
||||||
|
|
||||||
post1 := []*Post{&Post{Title: "TestPost1"}, &Post{Title: "TestPost2"}}
|
post1 := []*Post{{Title: "TestPost1"}, {Title: "TestPost2"}}
|
||||||
post2 := &Post{Title: "TestPost3"}
|
post2 := &Post{Title: "TestPost3"}
|
||||||
post3 := []interface{}{&Post{Title: "TestPost4"}}
|
post3 := []interface{}{&Post{Title: "TestPost4"}}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ func snakeString(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return strings.ToLower(string(data[:len(data)]))
|
return strings.ToLower(string(data[:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// camel string, xx_yy to XxYy
|
// camel string, xx_yy to XxYy
|
||||||
@ -220,7 +220,7 @@ func camelString(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return string(data[:len(data)])
|
return string(data[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
type argString []string
|
type argString []string
|
||||||
|
@ -88,7 +88,7 @@ func (l *logFilter) Filter(ctx *beecontext.Context) bool {
|
|||||||
if requestPath == "/favicon.ico" || requestPath == "/robots.txt" {
|
if requestPath == "/favicon.ico" || requestPath == "/robots.txt" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for prefix, _ := range StaticDir {
|
for prefix := range StaticDir {
|
||||||
if strings.HasPrefix(requestPath, prefix) {
|
if strings.HasPrefix(requestPath, prefix) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
|
|||||||
p.addToRouter(m, pattern, route)
|
p.addToRouter(m, pattern, route)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for k, _ := range methods {
|
for k := range methods {
|
||||||
if k == "*" {
|
if k == "*" {
|
||||||
for _, m := range HTTPMETHOD {
|
for _, m := range HTTPMETHOD {
|
||||||
p.addToRouter(m, pattern, route)
|
p.addToRouter(m, pattern, route)
|
||||||
@ -332,7 +332,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) {
|
|||||||
methods[strings.ToUpper(method)] = strings.ToUpper(method)
|
methods[strings.ToUpper(method)] = strings.ToUpper(method)
|
||||||
}
|
}
|
||||||
route.methods = methods
|
route.methods = methods
|
||||||
for k, _ := range methods {
|
for k := range methods {
|
||||||
if k == "*" {
|
if k == "*" {
|
||||||
for _, m := range HTTPMETHOD {
|
for _, m := range HTTPMETHOD {
|
||||||
p.addToRouter(m, pattern, route)
|
p.addToRouter(m, pattern, route)
|
||||||
|
@ -179,7 +179,6 @@ func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionSto
|
|||||||
} else {
|
} else {
|
||||||
client.Delete(oldsid)
|
client.Delete(oldsid)
|
||||||
item.Key = sid
|
item.Key = sid
|
||||||
item.Value = item.Value
|
|
||||||
item.Expiration = int32(rp.maxlifetime)
|
item.Expiration = int32(rp.maxlifetime)
|
||||||
client.Set(item)
|
client.Set(item)
|
||||||
contain = item.Value
|
contain = item.Value
|
||||||
|
@ -292,7 +292,7 @@ func qpEscape(dest []byte, c byte) {
|
|||||||
const nums = "0123456789ABCDEF"
|
const nums = "0123456789ABCDEF"
|
||||||
dest[0] = '='
|
dest[0] = '='
|
||||||
dest[1] = nums[(c&0xf0)>>4]
|
dest[1] = nums[(c&0xf0)>>4]
|
||||||
dest[2] = nums[(c&0xf)]
|
dest[2] = nums[(c & 0xf)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// headerToBytes enumerates the key and values in the header, and writes the results to the IO Writer
|
// 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 {
|
|||||||
case page >= pageNums-4 && pageNums > 9:
|
case page >= pageNums-4 && pageNums > 9:
|
||||||
start := pageNums - 9 + 1
|
start := pageNums - 9 + 1
|
||||||
pages = make([]int, 9)
|
pages = make([]int, 9)
|
||||||
for i, _ := range pages {
|
for i := range pages {
|
||||||
pages[i] = start + i
|
pages[i] = start + i
|
||||||
}
|
}
|
||||||
case page >= 5 && pageNums > 9:
|
case page >= 5 && pageNums > 9:
|
||||||
start := page - 5 + 1
|
start := page - 5 + 1
|
||||||
pages = make([]int, int(math.Min(9, float64(page+4+1))))
|
pages = make([]int, int(math.Min(9, float64(page+4+1))))
|
||||||
for i, _ := range pages {
|
for i := range pages {
|
||||||
pages[i] = start + i
|
pages[i] = start + i
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
pages = make([]int, int(math.Min(9, float64(pageNums))))
|
pages = make([]int, int(math.Min(9, float64(pageNums))))
|
||||||
for i, _ := range pages {
|
for i := range pages {
|
||||||
pages[i] = i + 1
|
pages[i] = i + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func SliceRandList(min, max int) []int {
|
|||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
rand.Seed(int64(t0.Nanosecond()))
|
rand.Seed(int64(t0.Nanosecond()))
|
||||||
list := rand.Perm(length)
|
list := rand.Perm(length)
|
||||||
for index, _ := range list {
|
for index := range list {
|
||||||
list[index] += min
|
list[index] += min
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
|
@ -137,7 +137,7 @@ func getRegFuncs(tag, key string) (vfs []ValidFunc, str string, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vfs = []ValidFunc{ValidFunc{"Match", []interface{}{reg, key + ".Match"}}}
|
vfs = []ValidFunc{{"Match", []interface{}{reg, key + ".Match"}}}
|
||||||
str = strings.TrimSpace(tag[:index]) + strings.TrimSpace(tag[end+len("/)"):])
|
str = strings.TrimSpace(tag[:index]) + strings.TrimSpace(tag[end+len("/)"):])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user