1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 08:30:54 +00:00

gofmt -s & go_vet

This commit is contained in:
astaxie 2015-03-19 22:29:01 -07:00
parent 1592e9c04d
commit 1d8afdc9c9
13 changed files with 239 additions and 240 deletions

2
cache/memory.go vendored
View File

@ -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)
} }
} }

View File

@ -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
} }

View File

@ -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"},
} }
} }

View File

@ -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
} }

View File

@ -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 resultJava 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 resultJava 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 programand web servergodoc 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 programand web servergodoc 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"}}

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -1,199 +1,199 @@
// Copyright 2014 beego Author. All Rights Reserved. // Copyright 2014 beego Author. All Rights Reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package session package session
import ( import (
"container/list" "container/list"
"net/http" "net/http"
"sync" "sync"
"time" "time"
) )
var mempder = &MemProvider{list: list.New(), sessions: make(map[string]*list.Element)} var mempder = &MemProvider{list: list.New(), sessions: make(map[string]*list.Element)}
// memory session store. // memory session store.
// it saved sessions in a map in memory. // it saved sessions in a map in memory.
type MemSessionStore struct { type MemSessionStore struct {
sid string //session id sid string //session id
timeAccessed time.Time //last access time timeAccessed time.Time //last access time
value map[interface{}]interface{} //session store value map[interface{}]interface{} //session store
lock sync.RWMutex lock sync.RWMutex
} }
// set value to memory session // set value to memory session
func (st *MemSessionStore) Set(key, value interface{}) error { func (st *MemSessionStore) Set(key, value interface{}) error {
st.lock.Lock() st.lock.Lock()
defer st.lock.Unlock() defer st.lock.Unlock()
st.value[key] = value st.value[key] = value
return nil return nil
} }
// get value from memory session by key // get value from memory session by key
func (st *MemSessionStore) Get(key interface{}) interface{} { func (st *MemSessionStore) Get(key interface{}) interface{} {
st.lock.RLock() st.lock.RLock()
defer st.lock.RUnlock() defer st.lock.RUnlock()
if v, ok := st.value[key]; ok { if v, ok := st.value[key]; ok {
return v return v
} else { } else {
return nil return nil
} }
} }
// delete in memory session by key // delete in memory session by key
func (st *MemSessionStore) Delete(key interface{}) error { func (st *MemSessionStore) Delete(key interface{}) error {
st.lock.Lock() st.lock.Lock()
defer st.lock.Unlock() defer st.lock.Unlock()
delete(st.value, key) delete(st.value, key)
return nil return nil
} }
// clear all values in memory session // clear all values in memory session
func (st *MemSessionStore) Flush() error { func (st *MemSessionStore) Flush() error {
st.lock.Lock() st.lock.Lock()
defer st.lock.Unlock() defer st.lock.Unlock()
st.value = make(map[interface{}]interface{}) st.value = make(map[interface{}]interface{})
return nil return nil
} }
// get this id of memory session store // get this id of memory session store
func (st *MemSessionStore) SessionID() string { func (st *MemSessionStore) SessionID() string {
return st.sid return st.sid
} }
// Implement method, no used. // Implement method, no used.
func (st *MemSessionStore) SessionRelease(w http.ResponseWriter) { func (st *MemSessionStore) SessionRelease(w http.ResponseWriter) {
} }
type MemProvider struct { type MemProvider struct {
lock sync.RWMutex // locker lock sync.RWMutex // locker
sessions map[string]*list.Element // map in memory sessions map[string]*list.Element // map in memory
list *list.List // for gc list *list.List // for gc
maxlifetime int64 maxlifetime int64
savePath string savePath string
} }
// init memory session // init memory session
func (pder *MemProvider) SessionInit(maxlifetime int64, savePath string) error { func (pder *MemProvider) SessionInit(maxlifetime int64, savePath string) error {
pder.maxlifetime = maxlifetime pder.maxlifetime = maxlifetime
pder.savePath = savePath pder.savePath = savePath
return nil return nil
} }
// get memory session store by sid // get memory session store by sid
func (pder *MemProvider) SessionRead(sid string) (SessionStore, error) { func (pder *MemProvider) SessionRead(sid string) (SessionStore, error) {
pder.lock.RLock() pder.lock.RLock()
if element, ok := pder.sessions[sid]; ok { if element, ok := pder.sessions[sid]; ok {
go pder.SessionUpdate(sid) go pder.SessionUpdate(sid)
pder.lock.RUnlock() pder.lock.RUnlock()
return element.Value.(*MemSessionStore), nil return element.Value.(*MemSessionStore), nil
} else { } else {
pder.lock.RUnlock() pder.lock.RUnlock()
pder.lock.Lock() pder.lock.Lock()
newsess := &MemSessionStore{sid: sid, timeAccessed: time.Now(), value: make(map[interface{}]interface{})} newsess := &MemSessionStore{sid: sid, timeAccessed: time.Now(), value: make(map[interface{}]interface{})}
element := pder.list.PushBack(newsess) element := pder.list.PushBack(newsess)
pder.sessions[sid] = element pder.sessions[sid] = element
pder.lock.Unlock() pder.lock.Unlock()
return newsess, nil return newsess, nil
} }
} }
// check session store exist in memory session by sid // check session store exist in memory session by sid
func (pder *MemProvider) SessionExist(sid string) bool { func (pder *MemProvider) SessionExist(sid string) bool {
pder.lock.RLock() pder.lock.RLock()
defer pder.lock.RUnlock() defer pder.lock.RUnlock()
if _, ok := pder.sessions[sid]; ok { if _, ok := pder.sessions[sid]; ok {
return true return true
} else { } else {
return false return false
} }
} }
// generate new sid for session store in memory session // generate new sid for session store in memory session
func (pder *MemProvider) SessionRegenerate(oldsid, sid string) (SessionStore, error) { func (pder *MemProvider) SessionRegenerate(oldsid, sid string) (SessionStore, error) {
pder.lock.RLock() pder.lock.RLock()
if element, ok := pder.sessions[oldsid]; ok { if element, ok := pder.sessions[oldsid]; ok {
go pder.SessionUpdate(oldsid) go pder.SessionUpdate(oldsid)
pder.lock.RUnlock() pder.lock.RUnlock()
pder.lock.Lock() pder.lock.Lock()
element.Value.(*MemSessionStore).sid = sid element.Value.(*MemSessionStore).sid = sid
pder.sessions[sid] = element pder.sessions[sid] = element
delete(pder.sessions, oldsid) delete(pder.sessions, oldsid)
pder.lock.Unlock() pder.lock.Unlock()
return element.Value.(*MemSessionStore), nil return element.Value.(*MemSessionStore), nil
} else { } else {
pder.lock.RUnlock() pder.lock.RUnlock()
pder.lock.Lock() pder.lock.Lock()
newsess := &MemSessionStore{sid: sid, timeAccessed: time.Now(), value: make(map[interface{}]interface{})} newsess := &MemSessionStore{sid: sid, timeAccessed: time.Now(), value: make(map[interface{}]interface{})}
element := pder.list.PushBack(newsess) element := pder.list.PushBack(newsess)
pder.sessions[sid] = element pder.sessions[sid] = element
pder.lock.Unlock() pder.lock.Unlock()
return newsess, nil return newsess, nil
} }
} }
// delete session store in memory session by id // delete session store in memory session by id
func (pder *MemProvider) SessionDestroy(sid string) error { func (pder *MemProvider) SessionDestroy(sid string) error {
pder.lock.Lock() pder.lock.Lock()
defer pder.lock.Unlock() defer pder.lock.Unlock()
if element, ok := pder.sessions[sid]; ok { if element, ok := pder.sessions[sid]; ok {
delete(pder.sessions, sid) delete(pder.sessions, sid)
pder.list.Remove(element) pder.list.Remove(element)
return nil return nil
} }
return nil return nil
} }
// clean expired session stores in memory session // clean expired session stores in memory session
func (pder *MemProvider) SessionGC() { func (pder *MemProvider) SessionGC() {
pder.lock.RLock() pder.lock.RLock()
for { for {
element := pder.list.Back() element := pder.list.Back()
if element == nil { if element == nil {
break break
} }
if (element.Value.(*MemSessionStore).timeAccessed.Unix() + pder.maxlifetime) < time.Now().Unix() { if (element.Value.(*MemSessionStore).timeAccessed.Unix() + pder.maxlifetime) < time.Now().Unix() {
pder.lock.RUnlock() pder.lock.RUnlock()
pder.lock.Lock() pder.lock.Lock()
pder.list.Remove(element) pder.list.Remove(element)
delete(pder.sessions, element.Value.(*MemSessionStore).sid) delete(pder.sessions, element.Value.(*MemSessionStore).sid)
pder.lock.Unlock() pder.lock.Unlock()
pder.lock.RLock() pder.lock.RLock()
} else { } else {
break break
} }
} }
pder.lock.RUnlock() pder.lock.RUnlock()
} }
// get count number of memory session // get count number of memory session
func (pder *MemProvider) SessionAll() int { func (pder *MemProvider) SessionAll() int {
return pder.list.Len() return pder.list.Len()
} }
// expand time of session store by id in memory session // expand time of session store by id in memory session
func (pder *MemProvider) SessionUpdate(sid string) error { func (pder *MemProvider) SessionUpdate(sid string) error {
pder.lock.Lock() pder.lock.Lock()
defer pder.lock.Unlock() defer pder.lock.Unlock()
if element, ok := pder.sessions[sid]; ok { if element, ok := pder.sessions[sid]; ok {
element.Value.(*MemSessionStore).timeAccessed = time.Now() element.Value.(*MemSessionStore).timeAccessed = time.Now()
pder.list.MoveToFront(element) pder.list.MoveToFront(element)
return nil return nil
} }
return nil return nil
} }
func init() { func init() {
Register("memory", mempder) Register("memory", mempder)
} }

View File

@ -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

View File

@ -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
} }
} }

View File

@ -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

View File

@ -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
} }