Codebase list golang-github-unknwon-com / 1b180991-92d6-46c1-a943-549fb7202180/main
New upstream snapshot. Debian Janitor 2 years ago
17 changed file(s) with 130 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
0 # Compiled Object files, Static and Dynamic libs (Shared Objects)
1 *.o
2 *.a
3 *.so
4
5 # Folders
6 _obj
7 _test
8 .idea
9
10 # Architecture specific extensions/prefixes
11 *.[568vq]
12 [568vq].out
13
14 *.cgo1.go
15 *.cgo2.c
16 _cgo_defun.c
17 _cgo_gotypes.go
18 _cgo_export.*
19
20 _testmain.go
21
22 *.exe
23 *.iml
00 language: go
11
22 go:
3 - 1.2
4 - 1.3
5 - 1.4
6 - tip
3 - 1.3.x
4 - 1.4.x
5 - 1.5.x
6 - 1.6.x
7 - 1.7.x
8 - 1.8.x
9 - 1.9.x
10 - 1.10.x
11 - 1.11.x
12 - 1.12.x
713
814 install: go get -v -t
9
10 notifications:
11 email:
12 - u@gogs.io
00 Common Functions
11 ================
22
3 [![Build Status](https://travis-ci.org/Unknwon/com.svg)](https://travis-ci.org/Unknwon/com) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/com)
3 [![Build Status](https://travis-ci.org/unknwon/com.svg)](https://travis-ci.org/unknwon/com) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/unknwon/com)
44
55 This is an open source project for commonly used functions for the Go programming language.
66
7 This package need >= **go 1.2**
7 This package need >= **go 1.3**
88
9 Code Convention: based on [Go Code Convention](https://github.com/Unknwon/go-code-convention).
9 Code Convention: based on [Go Code Convention](https://github.com/unknwon/go-code-convention).
1010
1111 ## Contribute
1212
0 // +build go1.2
0 // +build go1.3
11
22 // Copyright 2013 com authors
33 //
2222 type StrTo string
2323
2424 func (f StrTo) Exist() bool {
25 return string(f) != string(0x1E)
25 return string(f) != string(rune(0x1E))
2626 }
2727
2828 func (f StrTo) Uint8() (uint8, error) {
155155
156156 c := "?"
157157 if r >= 0 && r <= 9 {
158 c = string(r + '0')
158 c = string(rune(r + '0'))
159159 } else {
160 c = string(r + 'a' - 10)
160 c = string(rune(r + 'a' - 10))
161161 }
162162 hex = c + hex
163163 num = num / 16
0 golang-github-unknwon-com (2+git20200817.1.b41c64a-1) UNRELEASED; urgency=low
1
2 * New upstream snapshot.
3
4 -- Debian Janitor <janitor@jelmer.uk> Mon, 27 Sep 2021 08:10:25 -0000
5
06 golang-github-unknwon-com (1+git20170819.7677a1d-2) unstable; urgency=medium
17
28 * Team upload.
3131 return f.IsDir()
3232 }
3333
34 func statDir(dirPath, recPath string, includeDir, isDirOnly bool) ([]string, error) {
34 func statDir(dirPath, recPath string, includeDir, isDirOnly, followSymlinks bool) ([]string, error) {
3535 dir, err := os.Open(dirPath)
3636 if err != nil {
3737 return nil, err
5555 if includeDir {
5656 statList = append(statList, relPath+"/")
5757 }
58 s, err := statDir(curPath, relPath, includeDir, isDirOnly)
58 s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks)
5959 if err != nil {
6060 return nil, err
6161 }
6262 statList = append(statList, s...)
6363 } else if !isDirOnly {
6464 statList = append(statList, relPath)
65 } else if followSymlinks && fi.Mode()&os.ModeSymlink != 0 {
66 link, err := os.Readlink(curPath)
67 if err != nil {
68 return nil, err
69 }
70
71 if IsDir(link) {
72 if includeDir {
73 statList = append(statList, relPath+"/")
74 }
75 s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks)
76 if err != nil {
77 return nil, err
78 }
79 statList = append(statList, s...)
80 }
6581 }
6682 }
6783 return statList, nil
8399 if len(includeDir) >= 1 {
84100 isIncludeDir = includeDir[0]
85101 }
86 return statDir(rootPath, "", isIncludeDir, false)
102 return statDir(rootPath, "", isIncludeDir, false, false)
103 }
104
105 // LstatDir gathers information of given directory by depth-first.
106 // It returns slice of file list, follows symbolic links and includes subdirectories if enabled;
107 // it returns error and nil slice when error occurs in underlying functions,
108 // or given path is not a directory or does not exist.
109 //
110 // Slice does not include given path itself.
111 // If subdirectories is enabled, they will have suffix '/'.
112 func LstatDir(rootPath string, includeDir ...bool) ([]string, error) {
113 if !IsDir(rootPath) {
114 return nil, errors.New("not a directory or does not exist: " + rootPath)
115 }
116
117 isIncludeDir := false
118 if len(includeDir) >= 1 {
119 isIncludeDir = includeDir[0]
120 }
121 return statDir(rootPath, "", isIncludeDir, false, true)
87122 }
88123
89124 // GetAllSubDirs returns all subdirectories of given root path.
92127 if !IsDir(rootPath) {
93128 return nil, errors.New("not a directory or does not exist: " + rootPath)
94129 }
95 return statDir(rootPath, "", true, true)
130 return statDir(rootPath, "", true, true, false)
131 }
132
133 // LgetAllSubDirs returns all subdirectories of given root path, including
134 // following symbolic links, if any.
135 // Slice does not include given path itself.
136 func LgetAllSubDirs(rootPath string) ([]string, error) {
137 if !IsDir(rootPath) {
138 return nil, errors.New("not a directory or does not exist: " + rootPath)
139 }
140 return statDir(rootPath, "", true, true, true)
96141 }
97142
98143 // GetFileListBySuffix returns an ordered list of file paths.
1818 "io/ioutil"
1919 "net/http"
2020
21 "github.com/Unknwon/com"
21 "github.com/unknwon/com"
2222 )
2323
2424 // ------------------------------
7070 }
7171
7272 func ExampleGetSrcPath() {
73 srcPath, err := com.GetSrcPath("github.com/Unknwon/com")
73 srcPath, err := com.GetSrcPath("github.com/unknwon/com")
7474 if err != nil {
7575 fmt.Println(err)
7676 return
143143 "subdomain": "github.com",
144144 }
145145 s := "http://{domain}/{subdomain}/{0}/{1}"
146 fmt.Println(com.Expand(s, match, "Unknwon", "gowalker"))
147 // Output: http://gowalker.org/github.com/Unknwon/gowalker
146 fmt.Println(com.Expand(s, match, "unknwon", "gowalker"))
147 // Output: http://gowalker.org/github.com/unknwon/gowalker
148148 }
149149
150150 // ------------- END ------------
0 module github.com/unknwon/com
1
2 require (
3 github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
4 github.com/jtolds/gls v4.2.1+incompatible // indirect
5 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
6 github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c
7 )
0 github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
1 github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
2 github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
3 github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
4 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY=
5 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
6 github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w=
7 github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
3535 return html.EscapeString(str)
3636 }
3737
38 // decode string to html chars
38 // HtmlDecode decodes string to html chars
3939 func HtmlDecode(str string) string {
4040 return html.UnescapeString(str)
4141 }
176176 return nil
177177 }
178178
179 // FetchFiles uses command `curl` to fetch files specified by the rawURL field in parallel.
179 // FetchFilesCurl uses command `curl` to fetch files specified by the rawURL field in parallel.
180180 func FetchFilesCurl(files []RawFile, curlOptions ...string) error {
181181 ch := make(chan error, len(files))
182182 for i := range files {
1313
1414 package com
1515
16 // PowInt is int type of math.Pow function.
16 // PowInt is int type of math.Pow function.
1717 func PowInt(x int, y int) int {
1818 if y <= 0 {
1919 return 1
2020 } else {
21 if y % 2 == 0 {
21 if y%2 == 0 {
2222 sqrt := PowInt(x, y/2)
2323 return sqrt * sqrt
2424 } else {
5555
5656 func BenchmarkGetSrcPath(b *testing.B) {
5757 for i := 0; i < b.N; i++ {
58 GetSrcPath("github.com/Unknwon/com")
58 GetSrcPath("github.com/unknwon/com")
5959 }
6060 }
6161
3636 regex_url = regexp.MustCompile(regex_url_pattern)
3737 }
3838
39 // validate string is an email address, if not return false
39 // IsEmail validates string is an email address, if not return false
4040 // basically validation can match 99% cases
4141 func IsEmail(email string) bool {
4242 return regex_email.MatchString(email)
4343 }
4444
45 // validate string is an email address, if not return false
45 // IsEmailRFC validates string is an email address, if not return false
4646 // this validation omits RFC 2822
4747 func IsEmailRFC(email string) bool {
4848 return regex_strict_email.MatchString(email)
4949 }
5050
51 // validate string is a url link, if not return false
51 // IsUrl validates string is a url link, if not return false
5252 // simple validation can match 99% cases
5353 func IsUrl(url string) bool {
5454 return regex_url.MatchString(url)
4343 return true
4444 }
4545
46 // CompareSliceStr compares two 'string' type slices.
46 // CompareSliceStrU compares two 'string' type slices.
4747 // It returns true if elements are the same, and ignores the order.
4848 func CompareSliceStrU(s1, s2 []string) bool {
4949 if len(s1) != len(s2) {
1414 package com
1515
1616 import (
17 "bytes"
18 "crypto/rand"
1719 "testing"
1820
1921 . "github.com/smartystreets/goconvey/convey"
20 "crypto/rand"
21 "bytes"
2222 )
2323
2424 func TestAESEncrypt(t *testing.T) {
8888 "subdomain": "github.com",
8989 }
9090 s := "http://{domain}/{subdomain}/{0}/{1}"
91 sR := "http://gowalker.org/github.com/Unknwon/gowalker"
92 if Expand(s, match, "Unknwon", "gowalker") != sR {
91 sR := "http://gowalker.org/github.com/unknwon/gowalker"
92 if Expand(s, match, "unknwon", "gowalker") != sR {
9393 t.Errorf("Expand:\n Expect => %s\n Got => %s\n", sR, s)
9494 }
9595 }
117117 "TW": "tw",
118118 "_C": "_c",
119119
120 " sentence case ": "__sentence_case__",
120 " sentence case ": "__sentence_case__",
121121 " Mixed-hyphen case _and SENTENCE_case and UPPER-case": "_mixed_hyphen_case__and_sentence_case_and_upper_case",
122122 }
123123 Convey("Convert string into snake case", t, func() {