Skip to content

sado0823/go-kitx

Repository files navigation

go-kitx

Some practical tools、 algorithms written in Go

// example
func test() {
    cc, err := grpc.Dial(r.Scheme()+":///test.server",
        grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, p2c.Name)))
    if err != nil {
        t.Fatalf("failed to dial: %v", err)
    }
    defer cc.Close()
}

supported operator

  • comparator: > >= < <= ==

  • bitwise: & | ^

  • bitwiseShift: << >>

  • additive: + -

  • multiplicative: * / %

  • prefix: !(NOT) -(NEGATE)

  • logic: && ||

  • func call: ( ) , func(do func call with build in function and custom function)

  • params type: Ident Number String Bool array, struct (DO Not support func )

  • recursive params call with .: map.mapKey.mapKey.arrayIndex.structFiledName (foo.bar.2.Name)

  • Link

// example
import (
    . "github.com/sado0823/go-kitx/kit/rule"
)

func main(){

    expr := `foo + 1 > bar`
	
    param := map[string]interface{}{
        "foo": 5,
        "bar": 6,
    }
	
    res, err := Do(context.Background(), expr, param)
    if err != nil {
        panic(err)
    }
}

img.png

import (
    "context"
    "sync"
    "testing"
    "time"
	
    "github.com/sado0823/go-kitx/transport/grpc"
    "github.com/sado0823/go-kitx/transport/http"
)

func Test_NewApp(t *testing.T) {

	var wg sync.WaitGroup

	wg.Add(1)
	go func() {
		hs := http.NewServer(http.WithServerAddress("0.0.0.0:7001"))
		gs := grpc.NewServer(grpc.WithServerAddress("0.0.0.0:7002"))

		app := New(
			WithName("demo.app"),
			WithVersion("v0.0.00001"),
			WithMetadata(map[string]string{}),
			WithServer(hs, gs),
		)

		wg.Done()
		err := app.Run()
		if err != nil {
			t.Log(err)
			return
		}
	}()
	wg.Wait()
	time.Sleep(time.Second)

	client, err := grpc.DialInsecure(context.Background(),
		//grpc.WithClientEndpoint("direct:///0.0.0.0:7002,0.0.0.0:7001"),
		//grpc.WithClientEndpoint("discovery:///foo"),
		grpc.WithClientEndpoint("0.0.0.0:7002"),
	)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(client.Target())

	err = client.Invoke(context.Background(), "/abc", 1, map[string]interface{}{})
	t.Log(err)
}
  1) consistent hash
  2) bbrtokenperiod ratelimit
  3) backoff and jitter retry func
  4) redis, sql orm
  5) log plugin
  6) go ast rule engine
❯ ./kitx -h   
    
NAME:
   kitx - ⭐️ cli command for go-kitx

USAGE:
   kitx [global options] command [command options] [arguments...]

VERSION:
   v0.0.1

COMMANDS:
   upgrade, u   upgrade kitx tools
   new, n       generate project from template
   complete, c  complete a task on the list
   help, h      Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help (default: false)
   --version, -v  print the version (default: false)
    

About

micro service web framework including http and grpc. some practical tools、 algorithms written in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages