本文整理汇总了Golang中github.com/uber-go/zap.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:tixu,项目名称:mmjira,代码行数:32,代码来源:main.go
示例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
}
}
开发者ID:topfreegames,项目名称:apns-go,代码行数:33,代码来源:connection.go
示例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")
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:54,代码来源:server.go
示例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
}
开发者ID:topfreegames,项目名称:apns-go,代码行数:53,代码来源:connection.go
示例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
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:50,代码来源:h2.go
示例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
}
}
}
开发者ID:topfreegames,项目名称:apns-go,代码行数:27,代码来源:connection.go
示例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
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:31,代码来源:h2.go
示例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)
}
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:25,代码来源:h2.go
示例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)
}
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:31,代码来源:h2.go
示例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)
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:27,代码来源:h2.go
示例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)
}
}
开发者ID:sgotti,项目名称:stolon,代码行数:34,代码来源:sentinel.go
示例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()
}
开发者ID:yulrizka,项目名称:mybot,代码行数:26,代码来源:main.go
示例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
}
开发者ID:sorintlab,项目名称:stolon,代码行数:27,代码来源:proxy.go
示例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
}
开发者ID:sgotti,项目名称:stolon,代码行数:10,代码来源:keeper.go
示例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()
}
}
}
}
开发者ID:topfreegames,项目名称:kafka,代码行数:54,代码来源:consumer_group.go
示例16: tryLoadPac
func (s *Server) tryLoadPac() []byte {
ps, err := s.dbox.LoadPlainFile("/bricks.pac")
if err != nil {
Log.Error("load pac from dropbox", zap.Error(err))
s.muPac.RLock()
defer s.muPac.RUnlock()
return s.pac
}
s.muPac.Lock()
defer s.muPac.Unlock()
s.pac = ps
return s.pac
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:13,代码来源:server.go
示例17: loadPac
func (s *Server) loadPac() ([]byte, error) {
ps, err := ioutil.ReadFile("bricks.pac")
if err != nil {
ps, err = s.dbox.LoadPlainFile("/bricks.pac")
}
if err != nil {
Log.Error("load pac from dropbox", zap.Error(err))
return nil, err
}
s.muPac.Lock()
defer s.muPac.Unlock()
s.pac = ps
return ps, nil
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:14,代码来源:server.go
示例18: Close
func (cg *ConsumerGroup) Close(logger zap.Logger) error {
shutdownError := AlreadyClosing
cg.singleShutdown.Do(func() {
defer cg.kazoo.Close()
shutdownError = nil
close(cg.stopper)
cg.wg.Wait()
if err := cg.offsetManager.Close(logger); err != nil {
logger.Error("KAFKA: FAILED closing the offset manager for replica!",
zap.Int("replicaId", cg.replicaId),
zap.Error(err),
)
}
if shutdownError = cg.instance.Deregister(); shutdownError != nil {
logger.Warn("KAFKA: Replica FAILED deregistering consumer instance",
zap.Int("replicaId", cg.replicaId),
zap.Error(shutdownError),
)
} else {
logger.Info("KAFKA: Replica deregistered consumer instance",
zap.Int("replicaId", cg.replicaId),
zap.String("instanceId", cg.instance.ID),
)
}
if shutdownError = cg.consumer.Close(); shutdownError != nil {
logger.Error("Replica FAILED closing the Sarama client",
zap.Int("replicaId", cg.replicaId),
zap.Error(shutdownError),
)
}
close(cg.messages)
close(cg.errors)
cg.instance = nil
})
return shutdownError
}
开发者ID:topfreegames,项目名称:kafka,代码行数:37,代码来源:consumer_group.go
示例19: resync
func (p *PostgresKeeper) resync(db, followedDB *cluster.DB, tryPgrewind, started bool) error {
pgm := p.pgm
if started {
if err := pgm.Stop(true); err != nil {
return fmt.Errorf("failed to stop pg instance: %v", err)
}
}
replConnParams := p.getReplConnParams(db, followedDB)
standbySettings := &cluster.StandbySettings{PrimaryConninfo: replConnParams.ConnString(), PrimarySlotName: common.StolonName(db.UID)}
// TODO(sgotti) Actually we don't check if pg_rewind is installed or if
// postgresql version is > 9.5 since someone can also use an externally
// installed pg_rewind for postgres 9.4. If a pg_rewind executable
// doesn't exists pgm.SyncFromFollowedPGRewind will return an error and
// fallback to pg_basebackup
if tryPgrewind && p.usePgrewind(db) {
connParams := p.getSUConnParams(db, followedDB)
log.Info("syncing using pg_rewind", zap.String("followedDB", followedDB.UID), zap.String("keeper", followedDB.Spec.KeeperUID))
if err := pgm.SyncFromFollowedPGRewind(connParams, p.pgSUPassword); err != nil {
// log pg_rewind error and fallback to pg_basebackup
log.Error("error syncing with pg_rewind", zap.Error(err))
} else {
if err := pgm.WriteRecoveryConf(p.createRecoveryParameters(standbySettings, nil)); err != nil {
return fmt.Errorf("err: %v", err)
}
return nil
}
}
if err := pgm.RemoveAll(); err != nil {
return fmt.Errorf("failed to remove the postgres data dir: %v", err)
}
if log.Level() >= zap.DebugLevel {
log.Debug("syncing from followed db", zap.String("followedDB", followedDB.UID), zap.String("keeper", followedDB.Spec.KeeperUID), zap.String("replConnParams", fmt.Sprintf("%v", replConnParams)))
} else {
log.Info("syncing from followed db", zap.String("followedDB", followedDB.UID), zap.String("keeper", followedDB.Spec.KeeperUID))
}
if err := pgm.SyncFromFollowed(replConnParams); err != nil {
return fmt.Errorf("sync error: %v", err)
}
log.Info("sync succeeded")
if err := pgm.WriteRecoveryConf(p.createRecoveryParameters(standbySettings, nil)); err != nil {
return fmt.Errorf("err: %v", err)
}
return nil
}
开发者ID:sgotti,项目名称:stolon,代码行数:47,代码来源:keeper.go
示例20: serveWs
func (s *Server) serveWs(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
w.WriteHeader(http.StatusInternalServerError)
Log.Error("serveWs error", zap.Object("err", err))
}
}()
Log.Debug("websocket start")
ws, err := s.upgrader.Upgrade(w, r, nil)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Log.Error("websocket failed", zap.Error(err))
return
}
Log.Debug("websocket ok")
s.globalWsChan <- NewWs(ws, s.WsBufSize)
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:17,代码来源:server.go
注:本文中的github.com/uber-go/zap.Error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论