本文整理汇总了Golang中github.com/cosiner/gohper/errors.Err函数的典型用法代码示例。如果您正苦于以下问题:Golang Err函数的具体用法?Golang Err怎么用?Golang Err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Err函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
}
开发者ID:zhangyuchen0411,项目名称:gomodel,代码行数:8,代码来源:error_test.go
示例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
}
开发者ID:snowsnail,项目名称:zerver,代码行数:12,代码来源:session.go
示例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")
}
开发者ID:snowsnail,项目名称:gohper,代码行数:49,代码来源:validate_test.go
示例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
}
开发者ID:jacobzheng,项目名称:zerver,代码行数:7,代码来源:jsonp.go
示例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"))
}
开发者ID:snowsnail,项目名称:gohper,代码行数:8,代码来源:validate_test.go
示例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)
}
}
开发者ID:peternoyes,项目名称:apidoc,代码行数:45,代码来源:apidoc.go
示例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]")
}
}
开发者ID:amphisbe,项目名称:gohper,代码行数:18,代码来源:validator_test.go
示例8: NewS
func (c Code) NewS(err string) Error {
if err == "" {
return nil
}
return HTTPError{
error: errors.Err(err),
code: int(c),
}
}
开发者ID:sshitaime,项目名称:gohper,代码行数:10,代码来源:httperrors.go
示例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]"))
}
开发者ID:snowsnail,项目名称:gohper,代码行数:11,代码来源:validate_test.go
示例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
}
开发者ID:amphisbe,项目名称:gohper,代码行数:14,代码来源:codec.go
示例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
}
开发者ID:jacobzheng,项目名称:zerver,代码行数:16,代码来源:msq.go
示例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)
}
开发者ID:yyljlyy,项目名称:gohper,代码行数:17,代码来源:trace_test.go
示例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
}
开发者ID:jacobzheng,项目名称:zerver,代码行数:20,代码来源:xsrf.go
示例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
}
开发者ID:snowsnail,项目名称:zerver,代码行数:20,代码来源:msq.go
示例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
}
开发者ID:gaowenbin,项目名称:zerver,代码行数:24,代码来源:msq.go
示例16: NewCipher
package token
import (
"bytes"
"crypto/hmac"
"encoding/binary"
"hash"
"time"
"github.com/cosiner/gohper/encoding"
"github.com/cosiner/gohper/errors"
"github.com/cosiner/gohper/time2"
)
const (
ErrBadKey = errors.Err("bad key")
ErrExpiredKey = errors.Err("expired key")
ErrInvalidSignature = errors.Err("invalid signature")
)
type Cipher struct {
signKey []byte
ttl time.Duration
hash func() hash.Hash
sigLen int
hdrLen int
}
func NewCipher(signKey []byte, ttl time.Duration, hash func() hash.Hash, encs ...encoding.Encoding) encoding.Encoding {
sigLen := hash().Size() / 3
return encoding.Pipe(encs).Prepend(&Cipher{
开发者ID:sshitaime,项目名称:gohper,代码行数:31,代码来源:token.go
示例17:
import (
"bytes"
"fmt"
"html/template"
"net/smtp"
"strings"
"github.com/cosiner/gohper/bytes2"
"github.com/cosiner/gohper/errors"
"github.com/cosiner/gohper/strings2"
"github.com/cosiner/gohper/unsafe2"
)
const (
ErrNoTemplate = errors.Err("no template for this type")
)
type mailTemplate struct {
Subject string
*template.Template
}
type Mail struct {
From string
To []string
Subject string
Type string
Data interface{}
开发者ID:sshitaime,项目名称:gohper,代码行数:29,代码来源:mail.go
示例18: ParseHuman
if nano%base >= base/2 {
ms++
}
return strconv.Itoa(ms) + "ms"
}
base *= 1000
var s = int(nano / base)
if nano%base >= base/2 {
s++
}
return strconv.Itoa(s) + "s"
}
const (
ErrWrongHumanTimeFormat = errors.Err("wrong human time format")
)
// ParseHuman convert human time format to duration.
// support:
// 'H': hour,
// 'M': minute,
// 'S': second,
// 'm': millsecond,
// 'u': microsecond,
// 'n': nanosecond
func ParseHuman(timestr string) (time.Duration, error) {
var t, counter time.Duration
for i, l := 0, len(timestr); i < l; i++ {
c := timestr[i]
if c >= '0' && c <= '9' {
开发者ID:snowsnail,项目名称:gohper,代码行数:31,代码来源:time.go
示例19: New
package validate
import (
"github.com/cosiner/gohper/errors"
)
const (
ErrParamsCountNotMatch = errors.Err("parameters count not matched with validators")
)
type Validator func(string) error
type ValidChain []Validator
func New(validators ...Validator) ValidChain {
return ValidChain(validators)
}
func Use(vc ...Validator) Validator {
return New(vc...).Validate
}
func UseMul(vc ...Validator) func(...string) error {
return New(vc...).ValidateM
}
func UseStrictMul(vc ...Validator) func(...string) error {
return New(vc...).StrictValidateM
}
// Validate string with validators, return first error or nil
func (vc ValidChain) Validate(s string) error {
开发者ID:amphisbe,项目名称:gohper,代码行数:31,代码来源:validate.go
示例20: ScanURLVar
// ScanURLVars scan values into variable addresses
// if address is nil, skip it
func (v *urlVarIndexer) ScanURLVar(name string, addr interface{}) error {
if index, has := v.vars[name]; has {
return reflect2.UnmarshalPrimitive(v.values[index], reflect.ValueOf(addr))
}
return errors.Err("No this variable: " + name)
}
开发者ID:fanbuchi,项目名称:zerver,代码行数:8,代码来源:urlvarindexer.go
注:本文中的github.com/cosiner/gohper/errors.Err函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论