Skip to content

jarvanstack/go_utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go_utils

quick start

go get -u github.com/jarvanstack/go_utils

see the **_test file to learn how to use.

utils

1. testu

test_util loop time + time cost + ops (QPS)

How to use?

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 try catch the error can print stack error to help you find where is error happen.

3. string_util

  1. string_util (1) get random string,(2) md5 ...

4. syscall_util

expose some unsafe pointer or fd to help you to do syscall call.

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"))
		}()
	}
}