kitx

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 14 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, s AppI) context.Context

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *App

func (*App) Endpoint

func (a *App) Endpoint() []string

func (*App) ID

func (a *App) ID() string

func (*App) Metadata

func (a *App) Metadata() map[string]string

func (*App) Name

func (a *App) Name() string

func (*App) Run

func (a *App) Run() error

func (*App) Stop

func (a *App) Stop() error

func (*App) Version

func (a *App) Version() string

type AppI

type AppI interface {
	ID() string
	Name() string
	Version() string
	Metadata() map[string]string
	Endpoint() []string
}

func FromContext

func FromContext(ctx context.Context) (s AppI, ok bool)

type Option

type Option func(o *option)

func WithContext

func WithContext(ctx context.Context) Option

func WithEndpoint

func WithEndpoint(endpoints ...*url.URL) Option

func WithID

func WithID(id string) Option

WithID id should be unique

func WithLogger

func WithLogger(logger log.Logger) Option

func WithMetadata

func WithMetadata(md map[string]string) Option

func WithName

func WithName(name string) Option

func WithRegistrar

func WithRegistrar(r registry.Registrar) Option

WithRegistrar with service registry.

func WithRegistrarTimeout

func WithRegistrarTimeout(t time.Duration) Option

WithRegistrarTimeout with registrar timeout.

func WithServer

func WithServer(srv ...transport.Server) Option

func WithSignal

func WithSignal(sigs ...os.Signal) Option

WithSignal with exit signals.

func WithStopTimeout

func WithStopTimeout(t time.Duration) Option

WithStopTimeout with app stop timeout.

func WithVersion

func WithVersion(version string) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL