callback

package
v0.0.0-...-017a818 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEBUG          = os.Getenv("SQLCHAOS_DEBUG") != ""
	SQLCHAOS_DEBUG = func(format string, args ...interface{}) {
		if DEBUG {
			fmt.Fprintf(os.Stdout, "SQLCHAOS:"+format+"\n", args...)
		}
	}
	SQLCHAOS_ERROR = func(format string, args ...interface{}) { fmt.Fprintf(os.Stderr, "SQLCHAOS:"+format+"\n", args...) }
)

Functions

func ApplyRule

func ApplyRule(rule *ChaosRule, stmt *gorm.Statement) (applied bool)

func ApplyValuesIfMatch

func ApplyValuesIfMatch(stmt *gorm.Statement, matcher Matcher, applier Applier) (applied bool)

func Canonical

func Canonical(schema *schema.Schema, v map[string]interface{})

Canonical converts struct field name to database column name

Types

type Applier

type Applier map[string]string

func ParseThenStatement

func ParseThenStatement(then string) (Applier, error)

ParseThenStatement parses then clause to appliers. NOTE: then clause spec be like: column1=value1, column2=value2

func (Applier) Apply

func (applier Applier) Apply(by ApplyBy) bool

type ApplyBy

type ApplyBy interface {
	Apply(values map[string]string) bool
}

type ApplyByInterface

type ApplyByInterface map[string]interface{}

func (ApplyByInterface) Apply

func (m ApplyByInterface) Apply(values map[string]string) bool

type ApplyByReflectValue

type ApplyByReflectValue map[string]reflect.Value

func (ApplyByReflectValue) Apply

func (vm ApplyByReflectValue) Apply(values map[string]string) (applied bool)

type Callback

type Callback struct {
	DBName       string
	RuleProvider RuleProvider
}

func (*Callback) BeforeCreate

func (c *Callback) BeforeCreate() func(*gorm.DB)

func (*Callback) BeforeUpdate

func (c *Callback) BeforeUpdate() func(*gorm.DB)

func (*Callback) GetTableRule

func (c *Callback) GetTableRule(ctx context.Context, table, dml string) (rule *ChaosRule, err error)

type ChaosRule

type ChaosRule struct {
	DML  string `json:"dml"`
	When string `json:"when"`
	Then string `json:"then"`
}

type Match

type Match func(actual interface{}) bool

type MatchBy

type MatchBy interface {
	Match(matches map[string]Match) bool
}

type MatchByInterface

type MatchByInterface map[string]interface{}

func (MatchByInterface) Match

func (m MatchByInterface) Match(matches map[string]Match) bool

type MatchByReflectValue

type MatchByReflectValue map[string]reflect.Value

func (MatchByReflectValue) Match

func (vm MatchByReflectValue) Match(matches map[string]Match) bool

type Matcher

type Matcher map[string]Match

func ParseWhenStatement

func ParseWhenStatement(when string) (Matcher, error)

ParseWhenStatement parses when clause to matchers NOTE: when clause spec be like: column1=value1 AND column2>=value2

func (Matcher) Match

func (matcher Matcher) Match(by MatchBy) bool

type RuleProvider

type RuleProvider interface {
	Rule(ctx context.Context, dbname, table string) (*ChaosRule, error)
}

Jump to

Keyboard shortcuts

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