本文整理匯總了Golang中github.com/fcavani/e.Forward函數的典型用法代碼示例。如果您正苦於以下問題:Golang Forward函數的具體用法?Golang Forward怎麽用?Golang Forward使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Forward函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestInitClones
func TestInitClones(t *testing.T) {
connPool = &clones{
Num: 1,
MaxNum: 5,
}
err := connPool.Init()
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
connPoolErr := &clones{
Num: 0,
MaxNum: 5,
}
err = connPoolErr.Init()
if err != nil && !e.Equal(err, "number of clones invalid") {
t.Fatal(e.Trace(e.Forward(err)))
} else if err == nil {
t.Fatal("nil error")
}
connPoolErr = &clones{
Num: 10,
MaxNum: 5,
}
err = connPoolErr.Init()
if err != nil && !e.Equal(err, "number of streams is greater than max") {
t.Fatal(e.Trace(e.Forward(err)))
} else if err == nil {
t.Fatal("nil error")
}
}
示例2: TestAddPlainTextCredentials
func TestAddPlainTextCredentials(t *testing.T) {
ptc := NewPlainTextCredentials()
pt1 := &PlainText{"id", "pass1234"}
pt1b := &PlainText{"id", "pass1234"}
pt2 := &PlainText{"id2", "pass2345"}
hash := &Hashed{"a", "b"}
err := ptc.Add(pt1)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(pt2)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(pt1b)
if err != nil && !e.Equal(err, ErrCredExist) {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(hash)
if err != nil && !e.Equal(err, ErrNotComp) {
t.Fatal(e.Trace(e.Forward(err)))
}
}
示例3: TestBarrierWriterReaderPartial
func TestBarrierWriterReaderPartial(t *testing.T) {
buf := NewBuffer()
defer buf.Close()
b, err := rand.Bytes(1e6, "go")
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
n, err := buf.Write(b)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if n != len(b) {
t.Fatal("length invalid")
}
b2 := make([]byte, len(b))
count := 0
l := 100
for count < len(b) {
n, err = buf.Read(b2[count : count+l])
if err == io.EOF {
break
} else if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
count += n
}
if count != len(b) {
t.Fatal("length invalid", count, len(b))
}
if !bytes.Equal(b, b2) {
t.Fatal("not equal")
}
}
示例4: bind
func (a *Server) bind() (conn *net.UDPConn, err error) {
if !a.NotMulticast && a.iface.Flags&net.FlagMulticast == net.FlagMulticast {
gaddr, err := a.groupAddr()
if err != nil {
return nil, e.Forward(err)
}
conn, err = net.ListenMulticastUDP(a.Proto(), a.iface, gaddr)
if err != nil {
return nil, e.New(err)
}
} else {
server, err := net.ResolveUDPAddr(a.Proto(), ":"+a.Port)
if err != nil {
return nil, e.New(err)
}
conn, err = net.ListenUDP(a.Proto(), server)
if err != nil {
return nil, e.New(err)
}
}
a.ipver(conn.LocalAddr())
_, a.Port, err = utilNet.SplitHostPort(conn.LocalAddr().String())
if err != nil {
return nil, e.Forward(err)
}
return
}
示例5: TestDeletePlainTextCredentials
func TestDeletePlainTextCredentials(t *testing.T) {
ptc := NewPlainTextCredentials()
pt1 := &PlainText{"id", "pass1234"}
err := ptc.Add(pt1)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
_, err = ptc.Get("id")
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Delete("id")
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Delete("id")
if err != nil && !e.Equal(err, ErrCredNotExist) {
t.Fatal(e.Trace(e.Forward(err)))
}
_, err = ptc.Get("id")
if err != nil && !e.Equal(err, ErrCredNotExist) {
t.Fatal(e.Trace(e.Forward(err)))
}
}
示例6: TestProtoReqInst
func TestProtoReqInst(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
enc := msgpack.NewEncoder(buf)
dec := msgpack.NewDecoder(buf)
req := &ReqInst{
Inst: "inst",
Obj: "obj",
Args: []interface{}{"string", int(42)},
}
err := enc.Encode(req)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
recv := ReqInst{}
err = dec.Decode(&recv)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if recv.Inst != "inst" || recv.Obj != "obj" || len(recv.Args) != 2 || recv.Args[0].(string) != "string" || recv.Args[1].(int) != 42 {
t.Fatal("don't decode")
}
}
示例7: Discover
// Discover funtion discovers the server and returns the data sent by the server.
func (c *Client) Discover() (*Response, error) {
if c.Port == "" {
c.Port = "3456"
}
if c.BufSize <= 0 {
c.BufSize = 1024
}
if c.Timeout <= 0 {
c.Timeout = 2 * time.Minute
}
if c.Deadline <= 0 {
c.Deadline = 10 * time.Second
}
if c.Keepalive <= 0 {
c.Keepalive = 10 * time.Second
}
var err error
if c.Id == "" {
c.Id, err = rand.Uuid()
if err != nil {
return nil, e.Forward(err)
}
}
c.stopKa = make(chan chan struct{})
c.InitMCast()
err = c.getInt()
if err != nil {
return nil, e.Forward(err)
}
resp, err := c.getAddr()
if err != nil {
return nil, e.Forward(err)
}
return resp, nil
}
示例8: Hits
func (cd *CacheDisk) Hits(width, height uint, keys ...interface{}) (h uint32, err error) {
hash, err := hashKeys(keys...)
if err != nil {
return 0, e.Forward(err)
}
bufw := encLength(uint64(width))
bufh := encLength(uint64(height))
hitshash := []byte(string(hash) + string(bufw) + string(bufh))
err = cd.db.View(func(tx *bolt.Tx) error {
var err error
bhits := tx.Bucket([]byte(hits))
buf := bhits.Get(hitshash)
if buf == nil {
return e.New(ErrImageNotFound)
}
h, err = decHits(buf)
if err != nil {
return e.Forward(err)
}
return nil
})
err = e.Forward(err)
return
}
示例9: Put
func (c *CacheMem) Put(img Image, keys ...interface{}) error {
c.lck.Lock()
defer c.lck.Unlock()
num, err := c.numImages(keys...)
if err != nil {
return e.Forward(err)
}
if num >= c.maximages {
err = c.removeLFU(keys...)
if err != nil {
return e.Forward(err)
}
}
rect, err := img.Bounds()
if err != nil {
return e.Forward(err)
}
width := uint(rect.Max.X - rect.Min.X)
height := uint(rect.Max.Y - rect.Min.Y)
item, err := newItem(img, width, height, keys...)
if err != nil {
return e.Forward(err)
}
c.images.ReplaceOrInsert(item)
return nil
}
示例10: Init
func (c *client) Init() error {
var err error
c.session, err = openSession(c.Proto, c.Addr, c.TlsConfig, c.SessionName, c.Auth, c.DialTimeout, c.ConnTimeout)
if err != nil {
return e.Forward(err)
}
c.clones = &clones{
Num: c.NumClones,
MaxNum: c.MaxNumClones,
}
err = c.clones.Init()
if err != nil {
return e.Forward(err)
}
if c.KeepAlive == 0 {
return nil
}
go func() {
for {
time.Sleep(c.KeepAlive)
err := c.session.Keepalive()
if err != nil {
log.ProtoLevel().Tag("gormethods", "client", "keepalive").Printf("Keepalive failed: %v", err)
}
}
}()
return nil
}
示例11: Put
func (cd *CacheDisk) Put(img Image, keys ...interface{}) error {
err := cd.db.Update(func(tx *bolt.Tx) error {
hash, err := hashKeys(keys...)
if err != nil {
return e.Forward(err)
}
l := lenImg(tx, hash)
if l >= cd.images {
err = removeLFU(tx, hash)
if err != nil {
return e.Forward(err)
}
}
err = store(tx, img, hash)
if err != nil {
return e.Forward(err)
}
return nil
})
return e.Forward(err)
}
示例12: Commit
func (g *Generic) Commit(entry Entry) {
var err error
defer func() {
if err != nil {
CommitFail(entry, err)
}
}()
if g.r != nil && !g.r.Result(entry) {
return
}
if g.f == nil {
err = e.New("formater not set")
return
}
err = g.s.Tx(true, func(tx Transaction) error {
entry.Formatter(g.f)
err := tx.Put(entry.Date().Format(time.RFC3339Nano), entry)
if err != nil {
return e.Forward(err)
}
return nil
})
if err != nil {
err = e.Forward(err)
return
}
}
示例13: Transform
func (p *photo) Transform(crop image.Rectangle, width, height uint, dontenlarge bool, format string, resample resize.InterpolationFunction) (Image, error) {
img, err := p.Image()
if err != nil {
return nil, e.Forward(err)
}
imgResized := img
if !(width == 0 && height == 0) {
rect := img.Bounds()
w := uint(rect.Max.X - rect.Min.X)
h := uint(rect.Max.Y - rect.Min.Y)
if (width >= w || height >= h) && !dontenlarge {
imgResized = resize.Resize(width, height, img, resample)
} else if width < w && height < h {
imgResized = resize.Resize(width, height, img, resample)
}
}
b := make([]byte, 0, 1024)
buf := bytes.NewBuffer(b)
err = jpeg.Encode(buf, imgResized, nil)
if err != nil {
return nil, e.Forward(err)
}
return &photo{Buf: buf.Bytes()}, nil
}
示例14: PingHttp
// PingHttp connect a http or https server and try to
// receive something. If the server return a code different
// of 2xx, it will fail. Ignores insecure certificates.
func PingHttp(url *url.URL) error {
resp, err := httpClient.Get(url.String())
if e.Contains(err, "connection refused") {
return e.Push(e.New(err), "get failed: connection refused")
} else if err != nil {
return e.Push(e.New(err), "get failed")
}
defer resp.Body.Close()
buf := make([]byte, 4096)
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
n, err := resp.Body.Read(buf)
if err != nil && err != io.EOF {
return e.Forward(err)
}
buf = buf[:n]
//status.Log(status.Protocol, "PingHttp status code is %v and received it from server: %v", resp.StatusCode, string(buf))
log.ProtoLevel().Printf("PingHttp status code is %v and received it from server: %v", resp.StatusCode, string(buf))
return e.New("returned status code %v, expected 2xx", resp.StatusCode)
}
_, err = resp.Body.Read(buf)
if err != nil && err != io.EOF {
return e.Forward(err)
}
return nil
}
示例15: put
func put(t *testing.T, s Storer, num int) {
err := s.Tx(true, func(tx Transaction) error {
var err error
for i := 0; i < num; i++ {
key := strconv.Itoa(i)
err = tx.Put(key, &TestStruct{I: i, Key: key})
if err != nil {
return err
}
}
err = tx.Put("3a", &TestStruct{I: 3, Key: "3a"})
if err != nil {
return err
}
err = tx.Put("3a", &TestStruct{I: 3, Key: "3a"})
if err != nil {
return err
}
return nil
})
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
l, err := s.Len()
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if l != uint(num+1) {
t.Fatalf("wrong len %v %v", l, num)
}
}