本文整理匯總了Golang中github.com/cosiner/gohper/errors.Err函數的典型用法代碼示例。如果您正苦於以下問題:Golang Err函數的具體用法?Golang Err怎麽用?Golang Err使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Err函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestError
func TestError(t *testing.T) {
tt := testing2.Wrap(t)
err := errors.Err(`Duplicate entry '14d1b6c34a001-1648e0754a001' for key 'PRIMARY'`) // for combined primary key
tt.Eq(PRIMARY_KEY, duplicateKey(err))
err = errors.Err("CONSTRAINT `article_vote_ibfk_1` FOREIGN KEY (`article_id`) REFERENCES `article` (`article_id`)")
tt.Eq("article_id", foreignKey(err))
}
示例2: Init
// Init set up store and lifetime for session manager
func (sm *sessionManager) Init(store SessionStore, lifetime int64) error {
if store == nil {
return errors.Err("Empty session store")
}
if lifetime == 0 {
return errors.Err("Session lifetime is zero 0 no session will be stored")
}
sm.store = store
sm.lifetime = lifetime
return nil
}
示例3: TestFunc
func TestFunc(t *testing.T) {
tt := testing2.Wrap(t)
errReg := errors.Err("regexp not match")
r := Regexp{
Regexp: regexp.MustCompile("^\\d+$"),
Err: errReg,
}
tt.Nil(r.Validate("123"))
tt.Eq(errReg, r.Validate("123dqe"))
errLength := errors.Err("Wrong length")
errChars := errors.Err("Wrong chars")
length := Length{
Min: 3, Max: 10, Err: errLength,
}.Validate
chars := Chars{
Chars: "0123456789", Err: errChars,
}.Validate
single := Use(length, chars)
tt.Nil(single("023456"))
vc := UseMul(length, chars)
tt.Eq(vc("0"), errLength)
tt.Eq(vc("0000000000000000000000"), errLength)
tt.Nil(vc("000"))
tt.Eq(vc("abcde"), errChars)
// length process first, chars process remains
tt.Eq(vc("01", "abc"), errLength)
tt.Eq(vc("012", "abc"), errChars)
tt.Eq(vc("012", "a"), errChars)
tt.Nil(vc("012", "0"))
tt.Nil(vc("012", "0", "1111111111111111"))
// length process first, chars process remains
vc = UseMul(length, Use(length, chars))
tt.Eq(vc("012", "a"), errLength)
tt.Eq(vc("012", "0"), errLength)
tt.Eq(vc("012", "0", "1111111111111111"), errLength)
vc = UseStrictMul(length, chars)
tt.Nil(vc("abcd", "1234"))
defer tt.Recover()
vc("012", "0", "1111111111111111")
}
示例4: Init
func (j *JSONP) Init(zerver.Env) error {
if j.CallbackVar == "" {
return errors.Err("callback name should not be empty")
}
j.log = log.Derive("Filter", "JSONP")
return nil
}
示例5: TestValidateM
func TestValidateM(t *testing.T) {
tt := testing2.Wrap(t)
err := errors.Err("incorrect length")
v := ValidLength(3, 10, err).ValidateM
tt.Eq(err, v("a23", "a"))
tt.Nil(v("a23", "1234"))
}
示例6: main
func main() {
args := flag.Args()
path := "."
if len(args) != 0 {
path = args[0]
}
ext = "." + ext
wg := sync.WaitGroup{}
errors.Fatal(
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && filepath.Ext(info.Name()) == ext {
wg.Add(1)
go process(path, &wg)
}
return nil
}),
)
wg.Wait()
errors.CondDo(len(as.categories) == 0,
errors.Err("No files contains api in this dir or file"),
errors.FatalAnyln)
errors.CondDo(outputType != "md",
errors.Err("Sorry, currently only support markdown format"),
errors.FatalAnyln)
orders := slices.Strings(strings2.SplitAndTrim(order, orderSep)).Clear("")
if fname != "" {
errors.Fatalln(file.OpenOrCreate(fname, overwrite, func(fd *os.File) error {
as.WriteMarkDown(fd, orders)
return nil
}))
} else {
as.WriteMarkDown(os.Stdout, orders)
}
}
示例7: BenchmarkSimpleEmail
func BenchmarkSimpleEmail(b *testing.B) {
se := Use(
Length{
Min: 3,
Max: 10,
Err: errors.Err("aa"),
}.Validate,
SimpleEmail{
Err: errors.Err("Wrong email"),
}.Validate,
Chars{
Chars: "[email protected]",
Err: errors.Err("aa"),
}.Validate)
for i := 0; i < b.N; i++ {
_ = se("[email protected]")
}
}
示例8: NewS
func (c Code) NewS(err string) Error {
if err == "" {
return nil
}
return HTTPError{
error: errors.Err(err),
code: int(c),
}
}
示例9: TestSimpleEmail
func TestSimpleEmail(t *testing.T) {
tt := testing2.Wrap(t)
err := errors.Err("Wrong email")
se := &SimpleEmail{Err: err}
tt.Nil(se.Validate("[email protected]"))
tt.Eq(err, se.Validate("[email protected]"))
tt.Eq(err, se.Validate("@1.a"))
tt.Eq(err, se.Validate("[email protected]"))
tt.Eq(err, se.Validate("[email protected]"))
}
示例10: WriteGZIP
func WriteGZIP(w io.Writer, v interface{}) (err error) {
gw := gzip.NewWriter(w)
switch v := v.(type) {
case string:
_, err = gw.Write(unsafe2.Bytes(v))
case []byte:
_, err = gw.Write(v)
default:
err = errors.Err("Only support string and []byte")
}
gw.Close()
return
}
示例11: Init
func (m *Queue) Init(env zerver.Env) error {
if m.Processor == nil {
return errors.Err("message processor shouldn't be nil")
}
if m.TaskBufsize == 0 {
m.TaskBufsize = 256
}
if m.BytesPool == nil {
m.BytesPool = bytes2.NewFakePool()
}
m.queue = make(chan zerver.Task, m.TaskBufsize)
m.log = log.Derive("TaskHandler", "MessageQueue")
go m.start()
return nil
}
示例12: TestTrace
func TestTrace(t *testing.T) {
tt := testing2.Wrap(t)
tt.Nil(Trace(nil))
var e error = errors.Err("Error")
e2 := Trace(e)
es := "github.com/cosiner/gohper/errors/trace.TestTrace:trace_test.go:16:" + e.Error()
tt.Eq(es, e2.Error())
e2 = Trace(e2)
tt.Eq(es, e2.Error())
TraceEnabled = false
e2 = Trace(e)
tt.Eq(e2, e)
}
示例13: Init
func (x *Xsrf) Init(env zerver.Env) error {
if x.Secret == "" {
return errors.Err("xsrf secret can't be empty")
}
defval.Int64(&x.Timeout, _DEF_XSRF_TIMEOUT)
defval.Nil(&x.HashMethod, sha256.New)
defval.String(&x.Error, "xsrf token is invalid or not found")
if x.UsePool {
if x.Pool == nil {
x.Pool = bytes2.NewSyncPool(0, true)
}
} else {
x.Pool = bytes2.FakePool{}
}
defval.Nil(&x.TokenInfo, jsonToken{})
x.log = log.Derive("Component", "Xsrf")
return nil
}
示例14: Init
func (m *Queue) Init(env zerver.Environment) error {
if m.Processor == nil {
return errors.Err("message processor shouldn't be nil")
}
if m.TaskBufsize == 0 {
m.TaskBufsize = 256
}
if m.ErrorLogger == nil {
m.ErrorLogger = env.Logger()
}
m.ErrorLogger = m.ErrorLogger.Prefix("zerver/msq")
if m.BytesPool == nil {
m.BytesPool = bytes2.NewFakePool()
}
m.queue = make(chan zerver.Task, m.TaskBufsize)
go m.start()
return nil
}
示例15: Init
func (m *Queue) Init(zerver.Environment) error {
if m.Processor == nil {
return errors.Err("message processor shouldn't be nil")
}
if m.Bufsize == 0 {
m.Bufsize = 1024
}
m.queue = make(chan interface{}, m.Bufsize)
m.signal = make(chan struct{})
go func() {
for {
select {
case msg := <-m.queue:
m.Process(msg)
case <-m.signal:
return
}
}
}()
return nil
}