Skip to content

Commit

Permalink
Merge branch 'develop' into add-gosimple
Browse files Browse the repository at this point in the history
  • Loading branch information
astaxie authored Mar 18, 2017
2 parents 37c1ffc + 8dbf9eb commit d956444
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: go

go:
- 1.6
- 1.5.3
- 1.4.3
- 1.7
- 1.8
services:
- redis-server
- mysql
Expand Down Expand Up @@ -34,6 +34,7 @@ install:
- go get github.com/cloudflare/golz4
- go get github.com/gogo/protobuf/proto
- go get -u honnef.co/go/tools/cmd/gosimple
- go get -u github.com/mdempsky/unconvert
before_script:
- psql --version
- sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi"
Expand All @@ -49,5 +50,6 @@ after_script:
script:
- go test -v ./...
- gosimple -ignore "$(cat .gosimpleignore)" $(go list ./... | grep -v /vendor/)
- unconvert $(go list ./... | grep -v /vendor/)
addons:
postgresql: "9.4"
4 changes: 2 additions & 2 deletions cache/ssdb/ssdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (rc *Cache) GetMulti(keys []string) []interface{} {
resSize := len(res)
if err == nil {
for i := 1; i < resSize; i += 2 {
values = append(values, string(res[i+1]))
values = append(values, res[i+1])
}
return values
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (rc *Cache) ClearAll() error {
}
keys := []string{}
for i := 1; i < size; i += 2 {
keys = append(keys, string(resp[i]))
keys = append(keys, resp[i])
}
_, e := rc.conn.Do("multi_del", keys)
if e != nil {
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func assignSingleConfig(p interface{}, ac config.Configer) {
case reflect.String:
pf.SetString(ac.DefaultString(name, pf.String()))
case reflect.Int, reflect.Int64:
pf.SetInt(int64(ac.DefaultInt64(name, pf.Int())))
pf.SetInt(ac.DefaultInt64(name, pf.Int()))
case reflect.Bool:
pf.SetBool(ac.DefaultBool(name, pf.Bool()))
case reflect.Struct:
Expand Down
2 changes: 1 addition & 1 deletion logs/alils/log.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func sovLog(x uint64) (n int) {
return n
}
func sozLog(x uint64) (n int) {
return sovLog(uint64((x << 1) ^ uint64((int64(x) >> 63))))
return sovLog((x << 1) ^ (x >> 63))
}
func (m *Log) Unmarshal(data []byte) error {
var hasFields [1]uint64
Expand Down
2 changes: 1 addition & 1 deletion logs/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *SMTPWriter) sendMail(hostAddressWithPort string, auth smtp.Auth, fromAd
if err != nil {
return err
}
_, err = w.Write([]byte(msgContent))
_, err = w.Write(msgContent)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions orm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func (f StrTo) Int64() (int64, error) {
i := new(big.Int)
ni, ok := i.SetString(f.String(), 10) // octal
if !ok {
return int64(v), err
return v, err
}
return ni.Int64(), nil
}
return int64(v), err
return v, err
}

// Uint string to uint
Expand Down Expand Up @@ -130,11 +130,11 @@ func (f StrTo) Uint64() (uint64, error) {
i := new(big.Int)
ni, ok := i.SetString(f.String(), 10)
if !ok {
return uint64(v), err
return v, err
}
return ni.Uint64(), nil
}
return uint64(v), err
return v, err
}

// String string to string
Expand Down
2 changes: 1 addition & 1 deletion session/ledis/ledis_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (lp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error)
if len(kvs) == 0 {
kv = make(map[interface{}]interface{})
} else {
kv, err = session.DecodeGob([]byte(kvs))
kv, err = session.DecodeGob(kvs)
if err != nil {
return nil, err
}
Expand Down
30 changes: 12 additions & 18 deletions templatefunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,25 @@ func Substr(s string, start, length int) string {

// HTML2str returns escaping text convert from html.
func HTML2str(html string) string {
src := string(html)

re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
src = re.ReplaceAllStringFunc(src, strings.ToLower)
html = re.ReplaceAllStringFunc(html, strings.ToLower)

//remove STYLE
re, _ = regexp.Compile("\\<style[\\S\\s]+?\\</style\\>")
src = re.ReplaceAllString(src, "")
html = re.ReplaceAllString(html, "")

//remove SCRIPT
re, _ = regexp.Compile("\\<script[\\S\\s]+?\\</script\\>")
src = re.ReplaceAllString(src, "")
html = re.ReplaceAllString(html, "")

re, _ = regexp.Compile("\\<[\\S\\s]+?\\>")
src = re.ReplaceAllString(src, "\n")
html = re.ReplaceAllString(html, "\n")

re, _ = regexp.Compile("\\s{2,}")
src = re.ReplaceAllString(src, "\n")
html = re.ReplaceAllString(html, "\n")

return strings.TrimSpace(src)
return strings.TrimSpace(html)
}

// DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
Expand Down Expand Up @@ -193,16 +192,14 @@ func Str2html(raw string) template.HTML {
}

// Htmlquote returns quoted html string.
func Htmlquote(src string) string {
func Htmlquote(text string) string {
//HTML编码为实体符号
/*
Encodes `text` for raw use in HTML.
>>> htmlquote("<'&\\">")
'&lt;&#39;&amp;&quot;&gt;'
*/

text := string(src)

text = strings.Replace(text, "&", "&amp;", -1) // Must be done first!
text = strings.Replace(text, "<", "&lt;", -1)
text = strings.Replace(text, ">", "&gt;", -1)
Expand All @@ -216,7 +213,7 @@ func Htmlquote(src string) string {
}

// Htmlunquote returns unquoted html string.
func Htmlunquote(src string) string {
func Htmlunquote(text string) string {
//实体符号解释为HTML
/*
Decodes `text` that's HTML quoted.
Expand All @@ -227,7 +224,6 @@ func Htmlunquote(src string) string {
// strings.Replace(s, old, new, n)
// 在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换

text := string(src)
text = strings.Replace(text, "&nbsp;", " ", -1)
text = strings.Replace(text, "&rdquo;", "”", -1)
text = strings.Replace(text, "&ldquo;", "“", -1)
Expand Down Expand Up @@ -262,19 +258,17 @@ func URLFor(endpoint string, values ...interface{}) string {
}

// AssetsJs returns script tag with src string.
func AssetsJs(src string) template.HTML {
text := string(src)
func AssetsJs(text string) template.HTML {

text = "<script src=\"" + src + "\"></script>"
text = "<script src=\"" + text + "\"></script>"

return template.HTML(text)
}

// AssetsCSS returns stylesheet link tag with src string.
func AssetsCSS(src string) template.HTML {
text := string(src)
func AssetsCSS(text string) template.HTML {

text = "<link href=\"" + src + "\" rel=\"stylesheet\" />"
text = "<link href=\"" + text + "\" rel=\"stylesheet\" />"

return template.HTML(text)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/captcha/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func randomBrightness(c color.RGBA, max uint8) color.RGBA {
uint8(int(c.R) + n),
uint8(int(c.G) + n),
uint8(int(c.B) + n),
uint8(c.A),
c.A,
}
}

Expand Down

0 comments on commit d956444

Please sign in to comment.