本文整理汇总了Golang中github.com/uber-go/zap.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newBot
func newBot() (b MMJira) {
b = MMJira{l: zap.NewJSON(zap.DebugLevel), reg: metrics.NewRegistry()}
data, err := ioutil.ReadFile("config.yaml")
if err != nil {
b.l.Panic("not able to read the file", zap.Error(err))
}
var config InstanceConfig
if err = yaml.Unmarshal(data, &config); err != nil {
b.l.Panic("not able to marshal the file", zap.Error(err))
}
b.c = &config
if !b.c.Debug {
b.l.SetLevel(zap.ErrorLevel)
}
mmpost, err := mmcontroller.NewController(b.c.MMicon, b.c.MMuser, b.c.Hooks, b.c.Debug, metrics.NewPrefixedChildRegistry(b.reg, "mmc."))
if err != nil {
panic(err)
}
b.m = mmpost
b.l.Debug("outputting config", zap.Object("config", b.c))
b.r = mux.NewRouter()
b.r.HandleFunc("/", b.homeHandler)
b.r.HandleFunc("/hooks/", b.getHandler).Methods("GET")
b.r.HandleFunc("/hooks/{hookid}", b.postHandler).Methods("POST")
b.r.Handle("/metrics", exp.ExpHandler(b.reg))
b.r.HandleFunc("/config/", b.configGetHandler).Methods("GET")
return b
}
示例2: reader
func (conn *Connection) reader(responses chan<- Response, logger zap.Logger) {
buffer := make([]byte, 6)
for {
n, err := conn.conn.Read(buffer)
if err != nil && n < 6 {
logger.Info("APNS: Connection error before reading complete response",
zap.Int("connectionId", conn.id),
zap.Int("n", n),
zap.Error(err),
)
conn.shouldReconnect <- true
return
} else if err != nil {
logger.Info("APNS: Connection error before reading complete response",
zap.Int("connectionId", conn.id),
zap.Error(err),
)
}
command := uint8(buffer[0])
if command != 8 {
logger.Info("APNS: Something went wrong in a connection - Command should have been 8 but it had other value instead",
zap.Int("connectionId", conn.id),
zap.Object("commandValue", command),
)
}
resp := newResponse()
resp.Identifier = binary.BigEndian.Uint32(buffer[2:6])
resp.Status = uint8(buffer[1])
responses <- resp
conn.shouldReconnect <- true
return
}
}
示例3: Serve
func (s *Server) Serve() error {
s.globalWsChan = make(chan *Ws)
if s.H2SleepToRunSecond == 0 {
s.H2SleepToRunSecond = 2
}
if s.H2BufSize == 0 {
s.H2BufSize = 64 << 10
}
if s.WsBufSize == 0 {
s.WsBufSize = 65 << 10
}
if s.PingSecond == 0 {
s.PingSecond = 45
}
s.upgrader.ReadBufferSize = s.WsBufSize
s.upgrader.WriteBufferSize = s.WsBufSize
if s.H2RetryMaxSecond == 0 {
s.H2RetryMaxSecond = 30
}
info, err := json.Marshal(map[string]interface{}{
"PingSecond": s.PingSecond,
})
if err != nil {
Log.Error("compute server info", zap.Error(err))
return err
}
if s.TCP == 0 {
s.dbox, err = newDropbox(s.DropboxAccessToken, s.DropboxDomainKey)
if err != nil {
Log.Error("create dropbox client", zap.Error(err))
return err
}
}
if _, err = s.loadPac(); err != nil {
return err
}
s.info = info
if s.TCP == 0 {
s.challengeProvider = new(wrapperChallengeProvider)
s.httpServer = s.newHttpServer()
go s.listenAndServeH2All()
return s.httpServer.ListenAndServe()
}
s.listenAndServeH2All()
return errors.New("TCP server failed")
}
示例4: connect
func (conn *Connection) connect(logger zap.Logger) error {
if conn.conn != nil {
conn.conn.Close()
}
if conn.connAux != nil {
conn.connAux.Close()
}
var cert tls.Certificate
var err error
if len(conn.CertificateBase64) == 0 && len(conn.KeyBase64) == 0 {
// The user did not specify raw block contents, so check the filesystem.
cert, err = tls.LoadX509KeyPair(conn.CertificateFile, conn.KeyFile)
} else {
// The user provided the raw block contents, so use that.
cert, err = tls.X509KeyPair([]byte(conn.CertificateBase64), []byte(conn.KeyBase64))
}
if err != nil {
logger.Fatal("APNS: Failed to obtain certificate",
zap.Error(err),
)
return err
}
conf := &tls.Config{
Certificates: []tls.Certificate{cert},
ServerName: strings.Split(conn.Gateway, ":")[0],
}
connAux, err := net.Dial("tcp", conn.Gateway)
if err != nil {
logger.Fatal("APNS: Failed while dialing gateway",
zap.String("gateway", conn.Gateway),
zap.Error(err),
)
return err
}
tlsConn := tls.Client(connAux, conf)
err = tlsConn.Handshake()
if err != nil {
logger.Fatal("APNS: Failed while handshaking",
zap.Error(err),
)
_ = tlsConn.Close()
return err
}
conn.conn = tlsConn
conn.connAux = connAux
//Start reader goroutine
go conn.reader(conn.responses, logger)
return nil
}
示例5: newH2TlsConfig
func (s *Server) newH2TlsConfig() (*tls.Config, error) {
if s.TCP != 0 {
// 1. LoadServerCert
cert, err := tls.LoadX509KeyPair("server.crt", "server.key")
if err != nil {
Log.Error("loading server certificate", zap.Error(err))
return nil, err
}
// 2. LoadCACert
caCert, err := ioutil.ReadFile("chain.pem")
if err != nil {
Log.Error("loading CA certificate", zap.Error(err))
return nil, err
}
caPool := x509.NewCertPool()
caPool.AppendCertsFromPEM(caCert)
config := tls.Config{
Certificates: []tls.Certificate{cert},
ClientCAs: caPool,
ClientAuth: tls.RequireAndVerifyClientCert,
MinVersion: tls.VersionTLS12,
NextProtos: []string{http2.NextProtoTLS},
}
return &config, nil
}
w, err := acmewrapper.New(acmewrapper.Config{
Domains: []string{s.AcmeDomain},
TLSCertFile: fmt.Sprintf("/%s/%s", s.AcmeDomain, "cert.pem"),
TLSKeyFile: fmt.Sprintf("/%s/%s", s.AcmeDomain, "key.pem"),
RegistrationFile: fmt.Sprintf("/%s/%s", s.AcmeDomain, "user.reg"),
PrivateKeyFile: fmt.Sprintf("/%s/%s", s.AcmeDomain, "user.pem"),
TOSCallback: acmewrapper.TOSAgree,
HTTP01ChallengeProvider: s.challengeProvider,
SaveFileCallback: s.dbox.SaveFile,
LoadFileCallback: s.dbox.LoadFile,
})
if err != nil {
Log.Error("acmewrapper failed", zap.Error(err))
return nil, err
}
return w.TLSConfig(), nil
}
示例6: spinUntilReconnect
func (c *Connection) spinUntilReconnect(logger zap.Logger) {
var backoff = time.Duration(100)
for {
logger.Info("APNS: Connection lost. Reconnecting",
zap.Int("connectionId", c.id),
)
err := c.connect(logger)
if err != nil {
//Exponential backoff up to a limit
logger.Info("APNS: Error connecting to server",
zap.Int("connectionId", c.id),
zap.Error(err),
)
backoff = backoff * 2
if backoff > maxBackoff {
backoff = maxBackoff
}
time.Sleep(backoff)
} else {
backoff = 100
logger.Info("APNS: New connection established",
zap.Int("connectionId", c.id),
)
break
}
}
}
示例7: newH2Server
func (s *Server) newH2Server(tlsConfig *tls.Config, laddr string) (*http.Server, func(error)) {
var mu sync.Mutex
var h2sleep time.Duration = 1
h2Server := &http.Server{
Addr: laddr,
Handler: http.HandlerFunc(s.serveH2),
TLSConfig: tlsConfig,
ConnState: func(c net.Conn, s http.ConnState) {
if s == http.StateNew {
mu.Lock()
h2sleep = 1
mu.Unlock()
}
},
}
http2.ConfigureServer(h2Server, &http2.Server{
MaxReadFrameSize: s.H2BufSize,
})
afterServeError := func(err error) {
Log.Error("h2 server failed", zap.Error(err))
mu.Lock()
if h2sleep < s.H2RetryMaxSecond {
h2sleep++
}
sec := h2sleep
mu.Unlock()
time.Sleep(time.Second * sec)
}
return h2Server, afterServeError
}
示例8: listenAndServeH2
func (s *Server) listenAndServeH2(tlsConfig *tls.Config, tcp bool) {
var laddr string
var tlsListener net.Listener
var err error
if tcp {
if s.TCP == 0 {
return
}
laddr = fmt.Sprintf(":%d", s.TCP)
tlsListener, err = tls.Listen("tcp", laddr, tlsConfig)
if err != nil {
Log.Error("tcp tlsListener failed", zap.Error(err))
return
}
} else {
laddr = ":8444"
tlsListener = tls.NewListener(newGlobalWsListener(s.globalWsChan), tlsConfig)
}
h2Server, afterServeError := s.newH2Server(tlsConfig, laddr)
for {
err = h2Server.Serve(tlsListener)
afterServeError(err)
}
}
示例9: serveH2r
func (s *Server) serveH2r(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
w.WriteHeader(http.StatusInternalServerError)
Log.Error("REVERSE failed", zap.Object("err", err))
} else {
w.WriteHeader(http.StatusOK)
}
}()
remote, err := net.DialTimeout("tcp", r.Host, time.Second*10)
if err != nil {
Log.Error("dail failed", zap.Error(err), zap.String("host", r.Host))
w.WriteHeader(http.StatusNotImplemented)
return
}
defer remote.Close()
go io.Copy(remote, r.Body)
// go io.Copy(remote, io.TeeReader(r.Body, os.Stdout))
resr := io.TeeReader(remote, w)
// resr = io.TeeReader(resr, os.Stdout)
res, err := http.ReadResponse(bufio.NewReader(resr), nil)
if err != nil {
return
}
if res.Body != nil {
defer res.Body.Close()
io.Copy(ioutil.Discard, res.Body)
}
}
示例10: serveH2c
func (s *Server) serveH2c(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
w.WriteHeader(http.StatusInternalServerError)
Log.Error("CONNECT failed", zap.Object("err", err))
}
}()
remote, err := net.DialTimeout("tcp", r.Host, time.Second*10)
if err != nil {
Log.Error("dail failed", zap.Error(err), zap.String("host", r.Host))
w.WriteHeader(http.StatusNotImplemented)
return
}
defer remote.Close()
fw := &flushWriter{w}
fw.FlushHeader(http.StatusOK)
go io.Copy(remote, r.Body)
srcRemote := &TryReader{
c: remote,
ignore: 3,
maxRetry: 2,
tryDur: time.Millisecond * 600,
timeout: time.Second * 15,
}
io.Copy(fw, srcRemote)
}
示例11: electionLoop
func (s *Sentinel) electionLoop() {
for {
log.Info("Trying to acquire sentinels leadership")
electedCh, errCh := s.candidate.RunForElection()
for {
select {
case elected := <-electedCh:
s.leaderMutex.Lock()
if elected {
log.Info("sentinel leadership acquired")
s.leader = true
s.leadershipCount++
} else {
if s.leader {
log.Info("sentinel leadership lost")
}
s.leader = false
}
s.leaderMutex.Unlock()
case err := <-errCh:
if err != nil {
log.Error("election loop error", zap.Error(err))
}
goto end
case <-s.stop:
log.Debug("stopping election Loop")
return
}
}
end:
time.Sleep(10 * time.Second)
}
}
示例12: main
func main() {
logLevel := zap.LevelFlag("v", zap.InfoLevel, "log level: all, debug, info, warn, error, panic, fatal, none")
flag.StringVar(&botName, "botname", "satpam_bot", "bot name")
flag.StringVar(&adminID, "admin", "", "admin id")
flag.Parse()
// setup logger
log.SetLevel(*logLevel)
bot.SetLogger(log)
log.Info("STARTED", zap.String("version", VERSION), zap.String("buildtime", BUILDTIME))
key := os.Getenv("TELEGRAM_KEY")
if key == "" {
log.Fatal("TELEGRAM_KEY can not be empty")
}
startedAt = time.Now()
telegram := bot.NewTelegram(key)
plugin := satpamBot{t: telegram}
if err := telegram.AddPlugin(&plugin); err != nil {
log.Fatal("Failed AddPlugin", zap.Error(err))
}
plugin.start()
telegram.Start()
}
示例13: Start
func (c *ClusterChecker) Start() error {
endPollonProxyCh := make(chan error)
checkCh := make(chan error)
timerCh := time.NewTimer(0).C
for true {
select {
case <-timerCh:
go func() {
checkCh <- c.Check()
}()
case err := <-checkCh:
if err != nil {
log.Debug("check reported error", zap.Error(err))
}
if err != nil {
return fmt.Errorf("checker fatal error: %v", err)
}
timerCh = time.NewTimer(cluster.DefaultProxyCheckInterval).C
case err := <-endPollonProxyCh:
if err != nil {
return fmt.Errorf("proxy error: %v", err)
}
}
}
return nil
}
示例14: updatePGState
func (p *PostgresKeeper) updatePGState(pctx context.Context) {
p.pgStateMutex.Lock()
defer p.pgStateMutex.Unlock()
pgState, err := p.GetPGState(pctx)
if err != nil {
log.Error("failed to get pg state", zap.Error(err))
return
}
p.lastPGState = pgState
}
示例15: topicListConsumer
func (cg *ConsumerGroup) topicListConsumer(topics []string, logger zap.Logger) {
for {
select {
case <-cg.stopper:
return
default:
}
consumers, consumerChanges, err := cg.group.WatchInstances()
if err != nil {
logger.Fatal("KAFKA: FAILED to get list of registered consumer instances for replica",
zap.Int("replicaId", cg.replicaId),
zap.Error(err),
)
return
}
cg.consumers = consumers
logger.Info("KAFKA: Got currently registered consumers for replica",
zap.Int("replicaId", cg.replicaId),
zap.Int("numRegisteredConsumers", len(cg.consumers)),
)
stopper := make(chan struct{})
for _, topic := range topics {
cg.wg.Add(1)
go cg.topicConsumer(topic, cg.messages, cg.errors, stopper, logger)
}
select {
case <-cg.stopper:
close(stopper)
return
case event := <-consumerChanges:
if event.Err == zk.ErrSessionExpired || event.Err == zk.ErrConnectionClosed {
logger.Info("KAFKA: Session was expired, reloading consumer for replica",
zap.Int("replicaId", cg.replicaId),
)
go cg.reload(logger)
<-cg.stopper
close(stopper)
return
} else {
logger.Info("KAFKA: Triggering rebalance due to consumer list change in replica",
zap.Int("replicaId", cg.replicaId),
)
close(stopper)
cg.wg.Wait()
}
}
}
}