modulepackage
0.0.0-20181126045345-a86b05b01c1e
Repository: https://github.com/typa01/go-utils.git
Documentation: pkg.go.dev
# README
Go utils
Some of frequently used utils.
intro
file | function |
---|---|
id_generator | GUID, UUID |
json | StructToJson, JsonToStruct |
log | CheckAndPrintError |
signer | HmacSha256Base64Signer, Md5Signer |
string | Trim, Replace, Contains, ToArray, ToInt, ToInt64, ToFloat, Substring, Append, StringBuilder, Clear, Remove,RemoveLast |
string_builder | StringBuilder,Append,Replace,RemoveLast |
interface_builder | InterfaceBuilder, Append, Clear |
time | Millisecond, EpochTime, IsoTime, UTC, StringToTime, TimeToString |
other,utils_test | IIIOperator, symbol, test |
Installation
$ go get -u github.com/typa01/go-utils
Usage
More info see: utils_test.go
import (
tsgutils "github.com/typa01/go-utils"
)
str1 := tsgutils.NewString("13990521234")
str2 := tsgutils.NewString("14")
str3 := str1.Substring(0, 2).Append(str2).AppendString("520")
println(str1.ToString())
println(str2.ToString())
println(str3.ToString())
builder := NewStringBuilder()
builder.Append("a").Append("b").Append("c")
str := builder.ToString()
func (user *User) Rows2struct(rows *mysql.Rows) {
var users []User
builder := tsgutils.NewInterfaceBuilder()
for rows.Next() {
builder.Clear()
builder.Append(&user.Host).Append(&user.User)
builder.Append(&user.AuthenticationString)
err := rows.Scan(builder.ToInterfaces()...)
tsgutils.CheckAndPrintError("MySQL query rows scan error", err)
users = append(users, *user)
}
if rows != nil {
defer rows.Close()
}
user.Users = users
}
The future will continue to be updated.
https://blog.csdn.net/typa01_kk/article/category/7629914
# Functions
[9 9 8 4 2 9 1 7 - a 5 4 b - 3 3 1 6 - c d f 3 - 8 7 d 9 f b 5 7] -> "99842917-a54b-3316-cdf3-87d9fb57"
*/.
If there is an error print it, pass it
*/.
Get a epoch time
eg: 1521221737.376
*/.
No description provided by the author
No description provided by the author
first = false: "aaa_bbb_ccc" -> "aaaBbbCcc"
first = true: "aaa_bbb_ccc" -> "AaaBbbCcc"
*/.
No description provided by the author
return eg: 4725f5ae6a350b1c45687c9934456e6f
*/.
signing a message
using: hmac sha256 + base64
eg:
message = Pre_hash function comment
secretKey = E65791902180E9EF4510DB6A77F6EBAE
return signed string = TO6uwdqz+31SIPkd4I+9NiZGmVH74dXi+Fd5X0EzzSQ=
*/.
ternary operator, replace other language: a == b ? c : d
*/.
No description provided by the author
No description provided by the author
Get a iso time
eg: 2018-03-16T18:02:48.284Z
*/.
No description provided by the author
iso time change to time.Time
eg: "2018-11-18T16:51:55.933Z" -> 2018-11-18 16:51:55.000000933 +0000 UTC
*/.
Convert json string to struct
eg:
jsonString := "{\"field1\":\"Welcome to time space chain ...\",\"field2\":\"1688\",\"field3\":\"1314.521\"}"
var info Info
Json2Struct(jsonString, &info)
println(info.Field1)
print:
Welcome to time space chain ..
md5 sign: "123" -> "202cb962ac59075b964b07152d234b70"
*/.
get system current time's millisecond
*/.
get system current time's nanosecond
*/.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
the pre hash string
eg:
timestamp = 2018-03-08T10:59:25.789Z
method = POST
request_path = /orders?before=2&limit=30
body = {"product_id":"BTC-USD-0309","order_id":"377454671037440"}
return pre hash string = 2018-03-08T10:59:25.789ZPOST/orders?before=2&limit=30{"product_id":"BTC-USD-0309","order_id":"377454671037440"}
*/.
No description provided by the author
No description provided by the author
get system current time's second
*/.
No description provided by the author
No description provided by the author
*
Convert struct to json string
eg:
type Info struct {
Field1 string `json:"field1"`
Field2 int64 `json:"field2,string"`
Field3 float64 `json:"field3,string"`
}
var info Info
info.Field1 = "Welcome to time space chain ..."
info.Field2 = 1688
info.Field3 = 1314.521
return:
{"field1":"Welcome to time space chain ...","field2":"1688","field3":"1314.521"}
*/.
No description provided by the author
Get a UTC time string
eg: 2018-04-08 16:16:06.327540712 +0000 UTC
*/.
return eg: e7486845-9f24-c3d8-0db1-fe61e25c88a2
*/.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
# Structs
test struct
*/.
No description provided by the author
String struct.
StringBuilder struct.