fix: change directory and add readme

This commit is contained in:
vilet.yy 2021-06-10 14:29:56 +08:00
parent f4beaae3de
commit 619e954daa
5 changed files with 89 additions and 23 deletions

56
README.md Normal file
View File

@ -0,0 +1,56 @@
<!--
* @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy
* @LastEditTime: 2021-06-10 14:29:28
* @FilePath: /yolk/README.md
-->
# 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

View File

@ -1,28 +1,17 @@
/* /*
* @Date: 2021-03-12 17:37:03 * @Date: 2021-06-10 14:20:53
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-04-27 16:05:14 * @LastEditTime: 2021-06-10 14:21:09
* @FilePath: /yolk/helper.go * @FilePath: /yolk/convert/str_to.go
*/ */
package yolk package convert
import ( import (
"fmt" "fmt"
"math/rand"
"reflect" "reflect"
"strconv" "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 type StrTo string
func (f *StrTo) Set(v string) { func (f *StrTo) Set(v string) {

View File

@ -1,10 +1,10 @@
/* /*
* @Date: 2021-03-22 10:45:37 * @Date: 2021-03-22 10:45:37
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-04-29 11:44:54 * @LastEditTime: 2021-06-10 14:25:28
* @FilePath: /yolk/directory.go * @FilePath: /yolk/directory/directory.go
*/ */
package yolk package directory
import ( import (
"fmt" "fmt"
@ -24,7 +24,7 @@ func PathExists(path string) (bool, error) {
func IsDir(f string) bool { func IsDir(f string) bool {
fi, err := os.Stat(f) fi, err := os.Stat(f)
if err != nil { if err != nil {
return false return false
} }
return fi.IsDir() return fi.IsDir()

View File

@ -1,16 +1,18 @@
/* /*
* @Date: 2021-04-27 13:50:37 * @Date: 2021-04-27 13:50:37
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-04-27 14:31:42 * @LastEditTime: 2021-06-10 14:23:35
* @FilePath: /yolk/paginator.go * @FilePath: /yolk/paginator/paginator.go
*/ */
package yolk package paginator
import ( import (
"math" "math"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"github.com/viletyy/yolk/convert"
) )
type Paginator struct { type Paginator struct {
@ -40,7 +42,7 @@ func (p *Paginator) Nums() int64 {
} }
func (p *Paginator) SetNums(nums interface{}) { func (p *Paginator) SetNums(nums interface{}) {
p.nums, _ = ToInt64(nums) p.nums, _ = convert.ToInt64(nums)
} }
func (p *Paginator) Page() int { func (p *Paginator) Page() int {

19
random/random.go Normal file
View File

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