https://github.com/jarvanstack/go_utils
my useful go utils.
https://github.com/jarvanstack/go_utils
Last synced: 6 months ago
JSON representation
my useful go utils.
- Host: GitHub
- URL: https://github.com/jarvanstack/go_utils
- Owner: jarvanstack
- Created: 2021-05-30T04:18:21.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-08T13:35:25.000Z (about 3 years ago)
- Last Synced: 2023-07-27T22:03:02.071Z (almost 3 years ago)
- Language: HTML
- Size: 87.9 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## go_utils
### quick start
```bash
go get -u github.com/jarvanstack/go_utils
```
see the **_test file to learn how to use.
### utils
#### 1. testu
[test_util](testu/) loop time + time cost + ops (QPS)
How to use?
```go
package main
import (
"github.com/jarvanstack/go_utils/test_util"
"testing"
"time"
)
func Test_test_util(t *testing.T) {
tu := test_util.NewTestUtil(1000)
tu.Start()
for i := 0; i < 1000; i++ {
time.Sleep(time.Millisecond)
}
tu.End()
}
```
#### 2. throw_util
[throw_util](erru) try catch the error can print stack error to help you find where is error happen.
#### 3. string_util
3. [string_util](stringu) (1) get random string,(2) md5 ...
### 4. syscall_util
expose some unsafe pointer or fd to help you to do syscall call.
```bash
import (
"fmt"
"github.com/jarvanstack/go_utils/syscall_util"
"github.com/jarvanstack/go_utils/throw_util"
)
func main() {
var err error
listen, err := sysu.Listen(9999)
erru.Throw(err)
for {
conn, err := listen.Accept()
erru.Throw(err)
go func() {
defer conn.Close()
fmt.Printf("conn.ClientFd=%#v\n", conn.ClientFd)
fmt.Printf("conn.ServerFd=%#v\n", conn.ServerFd)
conn.Write([]byte("hi,syscall_util"))
}()
}
}
```