Skip to content

Commit

Permalink
feat: add used demo
Browse files Browse the repository at this point in the history
  • Loading branch information
alonelucky committed Feb 1, 2024
1 parent 55d7d28 commit 00ac418
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# gocommon
golang common tools set
This repository relies only on standard libraries.

### crypto/aes
```go
var ecb128pkcs7 = aes.New([]byte("1234567890123456"))
ecb128pkcs7.Encrypt([]byte("msg"))
ecb128pkcs7.Bytes()
ecb128pkcs7.Error

var buf,e = aes.Encrypt([]byte("1234567890123456"), []byte("msg"))
```
### crypto/rsa
### injects
```go
package xxstore

type store struct{}

func init(){
injects.Service.Register(&store{}, &injects.Config{Name:"store:mysql", Step: 10})
}
```
### otp
```go

var totp = otp.NewTOTP("secret", otp.TOTPWithPeriod(60))
var code, _ = totp.Generate()
var ok, _ = totp.Validate(code)
var url = totp.URL("Gcommon", "testid") // return url string. encode qrcode for scan 2FA.
```
### encoding/json
```go
var buf = []byte(`{"a":1,"b":"hello","c":false,"d":{"a":1.234}}`)
var m,_ = json.Parse(buf)
// map[a:1 b:hello c:false d:map[a:1.234]]
buf,_ = json.Stringify(m)
// []byte({"d":{"a":1.234},"a":1,"b":"hello","c":false})
```

0 comments on commit 00ac418

Please sign in to comment.