本文整理匯總了Golang中github.com/fcavani/e.Push函數的典型用法代碼示例。如果您正苦於以下問題:Golang Push函數的具體用法?Golang Push怎麽用?Golang Push使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Push函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Read
func (b *buffers) Read(num uint32, buf []byte) (int, error) {
b.lck.Lock()
chBuf, found := b.buffers[num]
if !found {
b.lck.Unlock()
return 0, e.New(ErrStreamNotFound)
}
b.lck.Unlock()
delta := b.deadline.Sub(time.Now())
if b.deadline.IsZero() {
n, err := chBuf.Read(buf)
if err != nil {
return 0, e.Push(err, "conn close")
}
return n, nil
}
select {
case ret := <-chBuf.ReadChan(buf):
if ret.Err != nil {
return 0, e.Push(ret.Err, "conn close")
}
// TODO: reenviar o error para a fila em caso de conn close.
return ret.N, nil
case <-time.After(delta):
return 0, errors.New("io read timeout")
}
}
示例2: NamedInstance
func (p *protoSession) NamedInstance(inst string) (connInst, error) {
s, err := p.newstream()
if err != nil {
return nil, e.Push(err, "can't initiate a new connection with the server")
}
enc := msgpack.NewEncoder(s)
dec := msgpack.NewDecoder(s)
err = enc.Encode(&ReqInst{
Inst: inst,
})
if err != nil {
return nil, e.Push(err, "can't request instance")
}
var resp RespInst
err = dec.Decode(&resp)
if err != nil {
return nil, e.Push(err, "can't request instance")
}
if resp.Err != nil {
return nil, e.Push(err, "instance init failed")
}
return &protoInst{
s: s,
inst: resp.Inst,
enc: msgpack.NewEncoder(s),
dec: msgpack.NewDecoder(s),
}, nil
}
示例3: 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
}
示例4: CheckUrl
func CheckUrl(rawurl string, min, max int) error {
if len(rawurl) < min || len(rawurl) > max {
return e.Push(e.New(ErrInvUrl), e.New("invalid url length"))
}
for _, v := range rawurl {
if !uni.IsLetter(v) && !unicode.IsDigit(v) && v != '/' && v != ':' && v != '[' && v != ']' && v != '?' && v != '@' && v != '.' && v != '-' && v != '_' && v != ' ' && v != '+' && v != '%' && v != '#' {
return e.Push(e.New(ErrInvUrl), e.New("the character '%v' in redirect is invalid", string([]byte{byte(v)})))
}
}
return nil
}
示例5: encode
func (c *Client) encode(typ msgType, val interface{}, dst *net.UDPAddr) error {
log.ProtoLevel().Tag("client", "discover").Printf("Send request (%v) to %v from %v.", typ, dst, c.conn.LocalAddr())
reqBuf := bytes.NewBuffer([]byte{})
buf := make([]byte, binary.MaxVarintLen16)
binary.PutUvarint(buf, uint64(typ))
n, err := reqBuf.Write(buf)
if err != nil {
return e.Push(err, "error enconding message type")
}
if n != len(buf) {
return e.Push(err, "error enconding message type")
}
enc := gob.NewEncoder(reqBuf)
err = enc.Encode(val)
if err != nil {
return e.Push(err, e.New("error encoding"))
}
msg, err := NewMsg(c.Name, c.ServerName, c.PrivateKey, c.ServerKey, reqBuf.Bytes())
if err != nil {
return e.Push(err, "erro cryptographing the value")
}
reqBuf = bytes.NewBuffer([]byte{})
enc = gob.NewEncoder(reqBuf)
err = enc.Encode(msg)
if err != nil {
return e.Push(err, e.New("error encoding"))
}
if reqBuf.Len() > c.BufSize {
return e.New("value to encode is too big %v", reqBuf.Len())
}
err = c.conn.SetDeadline(time.Now().Add(c.Deadline))
if err != nil {
return e.New(err)
}
_, _, err = c.conn.WriteMsgUDP(reqBuf.Bytes(), nil, dst)
if err != nil {
return e.New(err)
}
err = c.conn.SetDeadline(time.Time{})
if err != nil {
return e.New(err)
}
return nil
}
示例6: TestRetval
func (t *TestExportClient) TestRetval() (arg0 ResultInt) {
_err_ := t.init()
if _err_ != nil {
t.log(e.Trace(e.Forward(_err_)))
t._err_ = e.Push(t._err_, _err_)
return
}
_err_ = t.client.Call("TestRetval", []reflect.Value{}, []reflect.Value{reflect.ValueOf(&arg0)})
if _err_ != nil {
t.log(e.Trace(_err_))
t._err_ = e.Push(t._err_, _err_)
return
}
return
}
示例7: Calc
func (r *ResultClient) Calc() (arg0 int) {
_err_ := r.init()
if _err_ != nil {
r.log(e.Trace(e.Forward(_err_)))
r._err_ = e.Push(r._err_, _err_)
return
}
_err_ = r.client.Call("Calc", []reflect.Value{}, []reflect.Value{reflect.ValueOf(&arg0)})
if _err_ != nil {
r.log(e.Trace(_err_))
r._err_ = e.Push(r._err_, _err_)
return
}
return
}
示例8: Recv
func (t *TestChannelClient) Recv(x <-chan int) (arg0 int) {
_err_ := t.init()
if _err_ != nil {
t.log(e.Trace(e.Forward(_err_)))
t._err_ = e.Push(t._err_, _err_)
return
}
_err_ = t.client.Call("Recv", []reflect.Value{reflect.ValueOf(x)}, []reflect.Value{reflect.ValueOf(&arg0)})
if _err_ != nil {
t.log(e.Trace(_err_))
t._err_ = e.Push(t._err_, _err_)
return
}
return
}
示例9: Send
func (t *TestChannelClient) Send(x chan<- int) {
_err_ := t.init()
if _err_ != nil {
t.log(e.Trace(e.Forward(_err_)))
t._err_ = e.Push(t._err_, _err_)
return
}
_err_ = t.client.Call("Send", []reflect.Value{reflect.ValueOf(x)}, []reflect.Value{})
if _err_ != nil {
t.log(e.Trace(_err_))
t._err_ = e.Push(t._err_, _err_)
return
}
return
}
示例10: sendResp
func (a *Server) sendResp(resp *Response, to string, tokey *rsa.PublicKey, addr *net.UDPAddr) {
log.ProtoLevel().Tag("server", "discover").Printf("Send response from %v to %v", a.conn.LocalAddr(), addr)
respBuf := bytes.NewBuffer([]byte{})
enc := gob.NewEncoder(respBuf)
err := enc.Encode(resp)
if err != nil {
log.Tag("discover", "server").Printf("Server - Protocol fail for %v with error: %v", addr, e.Trace(e.New(err)))
a.sendErr(addr, e.Push(err, e.New("error enconding response")))
return
}
msg, err := NewMsg(a.Name, to, a.PrivateKey, tokey, respBuf.Bytes())
if err != nil {
log.Tag("discover", "server").Printf("Server - Protocol fail for %v with error: %v", addr, e.Trace(e.New(err)))
a.sendErr(addr, e.Push(err, e.New("error creating new response message")))
return
}
respBuf = bytes.NewBuffer([]byte{})
enc = gob.NewEncoder(respBuf)
err = enc.Encode(msg)
if err != nil {
log.Tag("discover", "server").Printf("Server - Protocol fail for %v with error: %v", addr, e.Trace(e.New(err)))
a.sendErr(addr, e.Push(err, e.New("error enconding response")))
return
}
if respBuf.Len() > a.BufSize {
log.Tag("discover", "server").Printf("Server - Protocol fail for %v message is too big (%v).", addr, respBuf.Len())
a.sendErr(addr, e.Push(err, e.New("response is too long %v", respBuf.Len())))
return
}
n, oob, err := a.conn.WriteMsgUDP(respBuf.Bytes(), nil, addr)
if e.Contains(err, "use of closed network connection") {
return
} else if err != nil {
log.Tag("discover", "server").Printf("Server - WriteMsgUDP (%v) failed: %v", addr, e.Trace(e.New(err)))
return
}
if oob != 0 {
log.Tag("discover", "server").Printf("Server - WriteMsgUDP to %v failed: %v, %v", addr, n, oob)
return
}
if n != respBuf.Len() {
log.Tag("discover", "server").Printf("Server - WriteMsgUDP to %v failed: %v, %v", addr, n, oob)
return
}
}
示例11: response
func (c *Client) response() (*Response, error) {
log.ProtoLevel().Tag("client", "discover").Printf("Waiting response...")
buf := make([]byte, c.BufSize)
err := c.conn.SetDeadline(time.Now().Add(c.Deadline))
if err != nil {
return nil, e.New(err)
}
n, addr, err := c.conn.ReadFromUDP(buf)
if err != nil {
return nil, e.New(err)
}
log.ProtoLevel().Tag("client", "discover").Printf("Response from %v with size %v.", addr, n)
err = c.conn.SetDeadline(time.Time{})
if err != nil {
return nil, e.New(err)
}
dec := gob.NewDecoder(bytes.NewReader(buf[:n]))
var msg Msg
err = dec.Decode(&msg)
if err != nil {
return nil, e.Push(err, e.New("error decoding response"))
}
if msg.Err != nil {
return nil, e.Forward(msg.Err)
}
if msg.From != c.ServerName {
return nil, e.New("wrong server name")
}
if msg.To != c.Name {
return nil, e.New("message isn't for me")
}
buf, err = msg.Message(c.ServerKey, c.PrivateKey)
if err != nil {
return nil, e.Push(err, e.New("error decrypting response"))
}
dec = gob.NewDecoder(bytes.NewReader(buf))
var resp Response
err = dec.Decode(&resp)
if err != nil {
return nil, e.Push(err, e.New("error decoding response"))
}
return &resp, nil
}
示例12: do
func (c *client) do(method, path, params string, body []byte) (int, []byte, error) {
url := utilUrl.Copy(c.url)
url.Path += path
url.RawQuery = params
var buf io.Reader
if len(body) > 0 {
buf = bytes.NewBuffer(body)
}
req, err := http.NewRequest(method, url.String(), buf)
if err != nil {
return 0, nil, e.New("can't create request")
}
if c.url.User != nil {
req.Header.Set("Authorization", authorizationHeader(url.User.String()))
}
req.Header.Set("Content-Type", "application/json")
resp, err := HttpClient.Do(req)
if err != nil {
return 0, nil, e.Push(err, "can't put")
}
defer resp.Body.Close()
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
return resp.StatusCode, nil, e.New("wrong status code - %v: %v", resp.StatusCode, resp.Status)
}
var data []byte
data, _ = ioutil.ReadAll(resp.Body)
return resp.StatusCode, data, nil
}
示例13: NewChValueInstance
func (i *Instances) NewChValueInstance(sess, inst string, ch reflect.Value, dir reflect.ChanDir, owners auth.Validator) error {
i.lck.Lock()
defer i.lck.Unlock()
s, found := i.Insts[sess]
if !found {
s = &Session{
Insts: map[string]Valuer{
inst: &ChannelValue{
ch: ch,
dir: dir,
},
},
Owners: owners,
}
i.Insts[sess] = s
return nil
}
if err := s.Owners.Equal(owners); err != nil {
return e.Push(err, ErrOwnerNotMatch)
}
_, found = s.Insts[inst]
if !found {
s.Insts[inst] = &ChannelValue{
ch: ch,
dir: dir,
}
return nil
}
return e.New(ErrInstExists)
}
示例14: restartProcess
func (d *Daemon) restartProcess() error {
d.status.Log(status.Verbose, "Process %v is about to restart.", d.DaemonName)
err := d.exec(d.RestartCmd, d.RestartArgs...)
if e.Contains(err, "exit status") {
d.status.Log(status.Verbose, "Restart command %v failed for %v with error: %v.", d.RestartCmd, d.DaemonName, e.Trace(e.Forward(err)))
if d.ForceKillCmd != "" {
err := d.forceKill()
if err != nil {
return e.Push(err, ErrGiveUpRestart)
}
} else {
err := d.kill(syscall.SIGTERM)
if e.Equal(err, ErrNoPid) {
d.status.Log(status.Verbose, "Starting force kill for %v.", d.DaemonName)
err := d.forceKill()
if err != nil {
return e.Push(err, ErrGiveUpRestart)
}
} else if err != nil {
err := d.kill(syscall.SIGKILL)
if err != nil {
d.status.Log(status.Verbose, "Starting force kill for %v.", d.DaemonName)
err := d.forceKill()
if err != nil {
return e.Push(err, ErrGiveUpRestart)
}
}
}
}
d.status.Log(status.Verbose, "Process %v is about to restart.", d.DaemonName)
err = d.exec(d.RestartCmd, d.RestartArgs...)
if err != nil {
err := d.forceKill()
if err != nil {
return e.Push(err, ErrGiveUpRestart)
}
d.status.Log(status.Verbose, "Process %v is about to restart, for the last time.", d.DaemonName)
err = d.exec(d.RestartCmd, d.RestartArgs...)
if err != nil {
return e.Push(err, ErrGiveUpRestart)
}
}
} else if err != nil {
return e.Forward(err)
}
return nil
}
示例15: CheckObjectName
func CheckObjectName(name string) error {
for _, v := range name {
if !uni.IsLetter(v) && !unicode.IsDigit(v) && v != '-' && v != '_' && v != '*' && v != '{' && v != '}' && v != '/' && v != '.' && v != '[' && v != ']' {
return e.Push(e.New(text.ErrInvCharacter), e.New("the character '%v' in object name is invalid", string([]byte{byte(v)})))
}
}
return nil
}