diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c19cc1 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ + +# Yolk + +[![viletyy yolk](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/viletyy/yolk) + +Go项目公共包 + +在开发项目中,经常使用的方法。 + +本公共包包含以下内容: + +1. 数据类型转换。 +2. 常用加解密算法。 +3. 文件夹辅助方法。 +4. 分页。 +5. 随机字符串。 + +## 内容列表 + +- [Yolk](#yolk) + - [内容列表](#内容列表) + - [安装](#安装) + - [使用说明](#使用说明) + - [如何贡献](#如何贡献) + - [使用许可](#使用许可) + +## 安装 + +这个项目使用 [go](https://golang.org/) 。请确保你本地安装了它。 + +```sh +$ tar -C /usr/local -xzf go1.4.linux-amd64.tar.gz +$ export PATH=$PATH:/usr/local/go/bin +``` + +## 使用说明 + +```sh +$ go get -u github.com/viletyy/yolk +$ go mod tidy +$ go mod vendor +``` + +## 如何贡献 + +非常欢迎你的加入![提一个 Issue](https://github.com/viletyy/yolk/issues/new) 或者提交一个 Pull Request。 + + +## 使用许可 + +[MIT](LICENSE) © Viletyy diff --git a/helper.go b/convert/convert.go similarity index 90% rename from helper.go rename to convert/convert.go index ebde5c8..a0e6a08 100644 --- a/helper.go +++ b/convert/convert.go @@ -1,28 +1,17 @@ /* - * @Date: 2021-03-12 17:37:03 + * @Date: 2021-06-10 14:20:53 * @LastEditors: viletyy - * @LastEditTime: 2021-04-27 16:05:14 - * @FilePath: /yolk/helper.go + * @LastEditTime: 2021-06-10 14:21:09 + * @FilePath: /yolk/convert/str_to.go */ -package yolk +package convert import ( "fmt" - "math/rand" "reflect" "strconv" ) -func GetRandomString(n int) string { - const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - var bytes = make([]byte, n) - rand.Read(bytes) - for i, b := range bytes { - bytes[i] = alphanum[b%byte(len(alphanum))] - } - return string(bytes) -} - type StrTo string func (f *StrTo) Set(v string) { diff --git a/directory.go b/directory/directory.go similarity index 84% rename from directory.go rename to directory/directory.go index 5592cf6..c1b6b58 100644 --- a/directory.go +++ b/directory/directory.go @@ -1,10 +1,10 @@ /* * @Date: 2021-03-22 10:45:37 * @LastEditors: viletyy - * @LastEditTime: 2021-04-29 11:44:54 - * @FilePath: /yolk/directory.go + * @LastEditTime: 2021-06-10 14:25:28 + * @FilePath: /yolk/directory/directory.go */ -package yolk +package directory import ( "fmt" @@ -24,7 +24,7 @@ func PathExists(path string) (bool, error) { func IsDir(f string) bool { fi, err := os.Stat(f) - if err != nil { + if err != nil { return false } return fi.IsDir() diff --git a/paginator.go b/paginator/paginator.go similarity index 94% rename from paginator.go rename to paginator/paginator.go index 3ce1c14..f24bf1d 100644 --- a/paginator.go +++ b/paginator/paginator.go @@ -1,16 +1,18 @@ /* * @Date: 2021-04-27 13:50:37 * @LastEditors: viletyy - * @LastEditTime: 2021-04-27 14:31:42 - * @FilePath: /yolk/paginator.go + * @LastEditTime: 2021-06-10 14:23:35 + * @FilePath: /yolk/paginator/paginator.go */ -package yolk +package paginator import ( "math" "net/http" "net/url" "strconv" + + "github.com/viletyy/yolk/convert" ) type Paginator struct { @@ -40,7 +42,7 @@ func (p *Paginator) Nums() int64 { } func (p *Paginator) SetNums(nums interface{}) { - p.nums, _ = ToInt64(nums) + p.nums, _ = convert.ToInt64(nums) } func (p *Paginator) Page() int { diff --git a/random/random.go b/random/random.go new file mode 100644 index 0000000..9e9578d --- /dev/null +++ b/random/random.go @@ -0,0 +1,19 @@ +/* + * @Date: 2021-06-10 14:24:22 + * @LastEditors: viletyy + * @LastEditTime: 2021-06-10 14:24:36 + * @FilePath: /yolk/random/random.go + */ +package random + +import "crypto/rand" + +func RandomString(n int) string { + const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + var bytes = make([]byte, n) + rand.Read(bytes) + for i, b := range bytes { + bytes[i] = alphanum[b%byte(len(alphanum))] + } + return string(bytes) +}