Commit 8dbf9eb0 authored by astaxie's avatar astaxie Committed by GitHub

Merge pull request #2512 from sergeylanzman/add-unconvert

add unconverted support
parents faa981fb 856fde28
...@@ -33,6 +33,7 @@ install: ...@@ -33,6 +33,7 @@ install:
- go get github.com/ssdb/gossdb/ssdb - go get github.com/ssdb/gossdb/ssdb
- go get github.com/cloudflare/golz4 - go get github.com/cloudflare/golz4
- go get github.com/gogo/protobuf/proto - go get github.com/gogo/protobuf/proto
- go get -u github.com/mdempsky/unconvert
before_script: before_script:
- psql --version - psql --version
- sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi" - sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi"
...@@ -47,5 +48,6 @@ after_script: ...@@ -47,5 +48,6 @@ after_script:
- rm -rf ./res/var/* - rm -rf ./res/var/*
script: script:
- go test -v ./... - go test -v ./...
- unconvert $(go list ./... | grep -v /vendor/)
addons: addons:
postgresql: "9.4" postgresql: "9.4"
...@@ -53,7 +53,7 @@ func (rc *Cache) GetMulti(keys []string) []interface{} { ...@@ -53,7 +53,7 @@ func (rc *Cache) GetMulti(keys []string) []interface{} {
resSize := len(res) resSize := len(res)
if err == nil { if err == nil {
for i := 1; i < resSize; i += 2 { for i := 1; i < resSize; i += 2 {
values = append(values, string(res[i+1])) values = append(values, res[i+1])
} }
return values return values
} }
...@@ -175,7 +175,7 @@ func (rc *Cache) ClearAll() error { ...@@ -175,7 +175,7 @@ func (rc *Cache) ClearAll() error {
} }
keys := []string{} keys := []string{}
for i := 1; i < size; i += 2 { 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) _, e := rc.conn.Do("multi_del", keys)
if e != nil { if e != nil {
......
...@@ -345,7 +345,7 @@ func assignSingleConfig(p interface{}, ac config.Configer) { ...@@ -345,7 +345,7 @@ func assignSingleConfig(p interface{}, ac config.Configer) {
case reflect.String: case reflect.String:
pf.SetString(ac.DefaultString(name, pf.String())) pf.SetString(ac.DefaultString(name, pf.String()))
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
pf.SetInt(int64(ac.DefaultInt64(name, pf.Int()))) pf.SetInt(ac.DefaultInt64(name, pf.Int()))
case reflect.Bool: case reflect.Bool:
pf.SetBool(ac.DefaultBool(name, pf.Bool())) pf.SetBool(ac.DefaultBool(name, pf.Bool()))
case reflect.Struct: case reflect.Struct:
......
...@@ -395,7 +395,7 @@ func sovLog(x uint64) (n int) { ...@@ -395,7 +395,7 @@ func sovLog(x uint64) (n int) {
return n return n
} }
func sozLog(x uint64) (n int) { 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 { func (m *Log) Unmarshal(data []byte) error {
var hasFields [1]uint64 var hasFields [1]uint64
......
...@@ -106,7 +106,7 @@ func (s *SMTPWriter) sendMail(hostAddressWithPort string, auth smtp.Auth, fromAd ...@@ -106,7 +106,7 @@ func (s *SMTPWriter) sendMail(hostAddressWithPort string, auth smtp.Auth, fromAd
if err != nil { if err != nil {
return err return err
} }
_, err = w.Write([]byte(msgContent)) _, err = w.Write(msgContent)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -92,11 +92,11 @@ func (f StrTo) Int64() (int64, error) { ...@@ -92,11 +92,11 @@ func (f StrTo) Int64() (int64, error) {
i := new(big.Int) i := new(big.Int)
ni, ok := i.SetString(f.String(), 10) // octal ni, ok := i.SetString(f.String(), 10) // octal
if !ok { if !ok {
return int64(v), err return v, err
} }
return ni.Int64(), nil return ni.Int64(), nil
} }
return int64(v), err return v, err
} }
// Uint string to uint // Uint string to uint
...@@ -130,11 +130,11 @@ func (f StrTo) Uint64() (uint64, error) { ...@@ -130,11 +130,11 @@ func (f StrTo) Uint64() (uint64, error) {
i := new(big.Int) i := new(big.Int)
ni, ok := i.SetString(f.String(), 10) ni, ok := i.SetString(f.String(), 10)
if !ok { if !ok {
return uint64(v), err return v, err
} }
return ni.Uint64(), nil return ni.Uint64(), nil
} }
return uint64(v), err return v, err
} }
// String string to string // String string to string
......
...@@ -150,7 +150,7 @@ func (lp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) ...@@ -150,7 +150,7 @@ func (lp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error)
if len(kvs) == 0 { if len(kvs) == 0 {
kv = make(map[interface{}]interface{}) kv = make(map[interface{}]interface{})
} else { } else {
kv, err = session.DecodeGob([]byte(kvs)) kv, err = session.DecodeGob(kvs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -46,26 +46,25 @@ func Substr(s string, start, length int) string { ...@@ -46,26 +46,25 @@ func Substr(s string, start, length int) string {
// HTML2str returns escaping text convert from html. // HTML2str returns escaping text convert from html.
func HTML2str(html string) string { func HTML2str(html string) string {
src := string(html)
re, _ := regexp.Compile("\\<[\\S\\s]+?\\>") re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
src = re.ReplaceAllStringFunc(src, strings.ToLower) html = re.ReplaceAllStringFunc(html, strings.ToLower)
//remove STYLE //remove STYLE
re, _ = regexp.Compile("\\<style[\\S\\s]+?\\</style\\>") re, _ = regexp.Compile("\\<style[\\S\\s]+?\\</style\\>")
src = re.ReplaceAllString(src, "") html = re.ReplaceAllString(html, "")
//remove SCRIPT //remove SCRIPT
re, _ = regexp.Compile("\\<script[\\S\\s]+?\\</script\\>") re, _ = regexp.Compile("\\<script[\\S\\s]+?\\</script\\>")
src = re.ReplaceAllString(src, "") html = re.ReplaceAllString(html, "")
re, _ = regexp.Compile("\\<[\\S\\s]+?\\>") re, _ = regexp.Compile("\\<[\\S\\s]+?\\>")
src = re.ReplaceAllString(src, "\n") html = re.ReplaceAllString(html, "\n")
re, _ = regexp.Compile("\\s{2,}") 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" // DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
...@@ -193,7 +192,7 @@ func Str2html(raw string) template.HTML { ...@@ -193,7 +192,7 @@ func Str2html(raw string) template.HTML {
} }
// Htmlquote returns quoted html string. // Htmlquote returns quoted html string.
func Htmlquote(src string) string { func Htmlquote(text string) string {
//HTML编码为实体符号 //HTML编码为实体符号
/* /*
Encodes `text` for raw use in HTML. Encodes `text` for raw use in HTML.
...@@ -201,8 +200,6 @@ func Htmlquote(src string) string { ...@@ -201,8 +200,6 @@ func Htmlquote(src string) string {
'&lt;&#39;&amp;&quot;&gt;' '&lt;&#39;&amp;&quot;&gt;'
*/ */
text := string(src)
text = strings.Replace(text, "&", "&amp;", -1) // Must be done first! text = strings.Replace(text, "&", "&amp;", -1) // Must be done first!
text = strings.Replace(text, "<", "&lt;", -1) text = strings.Replace(text, "<", "&lt;", -1)
text = strings.Replace(text, ">", "&gt;", -1) text = strings.Replace(text, ">", "&gt;", -1)
...@@ -216,7 +213,7 @@ func Htmlquote(src string) string { ...@@ -216,7 +213,7 @@ func Htmlquote(src string) string {
} }
// Htmlunquote returns unquoted html string. // Htmlunquote returns unquoted html string.
func Htmlunquote(src string) string { func Htmlunquote(text string) string {
//实体符号解释为HTML //实体符号解释为HTML
/* /*
Decodes `text` that's HTML quoted. Decodes `text` that's HTML quoted.
...@@ -227,7 +224,6 @@ func Htmlunquote(src string) string { ...@@ -227,7 +224,6 @@ func Htmlunquote(src string) string {
// strings.Replace(s, old, new, n) // strings.Replace(s, old, new, n)
// 在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换 // 在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换
text := string(src)
text = strings.Replace(text, "&nbsp;", " ", -1) text = strings.Replace(text, "&nbsp;", " ", -1)
text = strings.Replace(text, "&rdquo;", "”", -1) text = strings.Replace(text, "&rdquo;", "”", -1)
text = strings.Replace(text, "&ldquo;", "“", -1) text = strings.Replace(text, "&ldquo;", "“", -1)
...@@ -262,19 +258,17 @@ func URLFor(endpoint string, values ...interface{}) string { ...@@ -262,19 +258,17 @@ func URLFor(endpoint string, values ...interface{}) string {
} }
// AssetsJs returns script tag with src string. // AssetsJs returns script tag with src string.
func AssetsJs(src string) template.HTML { func AssetsJs(text string) template.HTML {
text := string(src)
text = "<script src=\"" + src + "\"></script>" text = "<script src=\"" + text + "\"></script>"
return template.HTML(text) return template.HTML(text)
} }
// AssetsCSS returns stylesheet link tag with src string. // AssetsCSS returns stylesheet link tag with src string.
func AssetsCSS(src string) template.HTML { func AssetsCSS(text string) template.HTML {
text := string(src)
text = "<link href=\"" + src + "\" rel=\"stylesheet\" />" text = "<link href=\"" + text + "\" rel=\"stylesheet\" />"
return template.HTML(text) return template.HTML(text)
} }
......
...@@ -474,7 +474,7 @@ func randomBrightness(c color.RGBA, max uint8) color.RGBA { ...@@ -474,7 +474,7 @@ func randomBrightness(c color.RGBA, max uint8) color.RGBA {
uint8(int(c.R) + n), uint8(int(c.R) + n),
uint8(int(c.G) + n), uint8(int(c.G) + n),
uint8(int(c.B) + n), uint8(int(c.B) + n),
uint8(c.A), c.A,
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment