Example #1
0
func ExampleFlag() {
	// we define our flags
	var (
		BadInput      = utils.New("BadInput", 1)
		NotAuthorized = utils.New("NotAuthorized", 2)
		InternalError = utils.New("InternalError", 3)
		// aggregat of flags
		UserError = utils.Join("UserError", BadInput, NotAuthorized)
	)

	// error flagged
	type MyError struct {
		flag utils.Flag
		Msg  string
	}
	// MyError with flag BadInput
	match := MyError{flag: BadInput, Msg: "json wanted"}
	// MyError with flag InternalError
	dontmatch := MyError{flag: InternalError, Msg: "server error"}

	// will print
	if utils.Intersect(match.flag, UserError) {
		fmt.Printf("user error happened '[%s] %s'\n",
			match.flag.String(), match.Msg)
	}

	// will not print
	if utils.Intersect(dontmatch.flag, UserError) {
		fmt.Printf("user error happened '[%s] %s'\n",
			dontmatch.flag.String(), dontmatch.Msg)
	}
	// Output:
	// user error happened '[BadInput] json wanted'
}
Example #2
0
func (u *ErrorChecker) CheckFlag(element string, mask ParserError) bool {

	if index := u.findElement(element); index == -1 {
		return utils.Intersect(u.defaultErrorFlag, mask.Flag())
	} else {
		return utils.Intersect(u.elementErrors[index].flag, mask.Flag())
	}
	return false
}
Example #3
0
func ExampleCounter() {
	var c utils.Counter = 0

	var (
		BadInput      = utils.InitFlag(&c, "BadInput")
		NotAuthorized = utils.InitFlag(&c, "NotAuthorized")
		InternalError = utils.InitFlag(&c, "InternalError")
	)

	if !utils.Intersect(BadInput, NotAuthorized) && !utils.Intersect(NotAuthorized, InternalError) && !utils.Intersect(InternalError, BadInput) {
		fmt.Printf("None of them match!")
	}

	// Output:
	// None of them match!
}
Example #4
0
File: error.go Project: apognu/xml
func (s Error) ErrorWithCode(f utils.Flag) utils.ErrorFlagged {
	if utils.Intersect(f, s.flag) {
		return s
	}
	return nil
}