1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
dudaodong
0c4b512084 fmt: fix some gofmt issue 2021-11-29 13:01:46 +08:00
dudaodong
4848647918 add go.mod 2021-11-29 11:48:12 +08:00
dudaodong
45fc84d1f2 update readme file and remove go.mod 2021-11-29 11:47:36 +08:00
15 changed files with 51 additions and 50 deletions

View File

@@ -5,7 +5,6 @@
</p>
<div align="center" style="text-align: center;">
</div>
English | [简体中文](./README_zh-CN.md)
@@ -53,7 +52,7 @@ func main() {
### API Documentation
#### 1. convertor contains some functions for data convertion.
#### 1. convertor contains some functions for data convertion
- Support conversion between commonly used data types.
- Usage: import "github.com/duke-git/lancet/cryptor"
@@ -91,7 +90,7 @@ func ToString(value interface{}) string //convert value to string
func StructToMap(value interface{}) (map[string]interface{}, error) //convert struct to map, only convert exported field, tag `json` should be set
```
#### 2. cryptor is for data encryption and decryption.
#### 2. cryptor is for data encryption and decryption
- Support md5, hmac, aes, des, ras.
- Usage: import "github.com/duke-git/lancet/cryptor"
@@ -284,7 +283,7 @@ func HttpPatch(url string, params ...interface{}) (*http.Response, error) //http
func ConvertMapToQueryString(param map[string]interface{}) string //convert map to url query string
```
#### 7. random is for rand string and int generation.
#### 7. random is for rand string and int generation
- Generate random string and int.
- Usage: import "github.com/duke-git/lancet/random".

View File

@@ -20,7 +20,7 @@ func ToBool(s string) (bool, error) {
return strconv.ParseBool(s)
}
// ToBool convert interface to bytes
// ToBytes convert interface to bytes
func ToBytes(data interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)

View File

@@ -65,7 +65,7 @@ func AesCbcEncrypt(data, key []byte) []byte {
return encrypted
}
// AesEcbDecrypt decrypt data with key use AES CBC algorithm
// AesCbcDecrypt decrypt data with key use AES CBC algorithm
// len(key) should be 16, 24 or 32
func AesCbcDecrypt(encrypted, key []byte) []byte {
block, _ := aes.NewCipher(key)

View File

@@ -21,13 +21,13 @@ func Base64StdEncode(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}
// Base64StdEncode decode a base64 encoded string
// Base64StdDecode decode a base64 encoded string
func Base64StdDecode(s string) string {
b, _ := base64.StdEncoding.DecodeString(s)
return string(b)
}
// Md5Str return the md5 value of string
// Md5String return the md5 value of string
func Md5String(s string) string {
h := md5.New()
h.Write([]byte(s))

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by MIT license.
// Package datetime implements some functions to format date and time.
// Note:
// 1. `format` param in FormatTimeToStr function should be as flow:
//"yyyy-mm-dd hh:mm:ss"
@@ -23,7 +22,6 @@
//"mm"
//"hh:mm:ss"
//"mm:ss"
package datetime
import (

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by MIT license.
// Package fileutil implements some basic functions for file operations
package fileutil
import (
@@ -12,7 +11,7 @@ import (
"os"
)
// IsFileExists checks if a file or directory exists
// IsExist checks if a file or directory exists
func IsExist(path string) bool {
_, err := os.Stat(path)
if err == nil {
@@ -35,7 +34,7 @@ func CreateFile(path string) bool {
return true
}
// IsFileExists checks if the path is directy or not
// IsDir checks if the path is directory or not
func IsDir(path string) bool {
file, err := os.Stat(path)
if err != nil {
@@ -70,9 +69,8 @@ func CopyFile(srcFilePath string, dstFilePath string) error {
if err != nil {
if err == io.EOF {
return nil
} else {
return err
}
return err
}
}
}

View File

@@ -1,10 +1,11 @@
package fileutil
import (
"github.com/duke-git/lancet/utils"
"os"
"reflect"
"testing"
"github.com/duke-git/lancet/utils"
)
func TestIsExist(t *testing.T) {

View File

@@ -1,8 +1,9 @@
package formatter
import (
"github.com/duke-git/lancet/utils"
"testing"
"github.com/duke-git/lancet/utils"
)
func TestComma(t *testing.T) {

View File

@@ -18,7 +18,8 @@ func numString(value interface{}) string {
switch reflect.TypeOf(value).Kind() {
case reflect.Int, reflect.Int64, reflect.Float32, reflect.Float64:
return fmt.Sprintf("%v", value)
case reflect.String: {
case reflect.String:
{
sv := fmt.Sprintf("%v", value)
if strings.Contains(sv, ".") {
_, err := strconv.ParseFloat(sv, 64)

View File

@@ -47,6 +47,7 @@ func GetPublicIpInfo() (*PublicIpInfo, error) {
return &ip, nil
}
// PublicIpInfo public ip info: country, region, isp, city, lat, lon, ip
type PublicIpInfo struct {
Status string `json:"status"`
Country string `json:"country"`

View File

@@ -2,9 +2,10 @@ package netutil
import (
"fmt"
"github.com/duke-git/lancet/utils"
"net"
"testing"
"github.com/duke-git/lancet/utils"
)
func TestGetInternalIp(t *testing.T) {

View File

@@ -4,9 +4,10 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/duke-git/lancet/utils"
"log"
"testing"
"github.com/duke-git/lancet/utils"
)
func TestHttpGet(t *testing.T) {

View File

@@ -9,6 +9,7 @@ import (
"testing"
)
// LogFailedTestInfo log test failed info for internal use
func LogFailedTestInfo(t *testing.T, testCase, input, expected, result interface{}) {
errInfo := fmt.Sprintf("Test case %v: input is %+v, expected %v, but result is %v", testCase, input, expected, result)
t.Error(errInfo)

View File

@@ -191,4 +191,3 @@ func IsWeakPassword(password string) bool {
return (num || letter) && !special
}