zoukankan      html  css  js  c++  java
  • top_channel_args.go

    package http_api

    import (
        "fmt"
        "log"
        "net"
        "net/http"
        "strings"

        "github.com/nsqio/nsq/internal/app"
    )

    type logWriter struct {
        app.Logger
    }

    func (l logWriter) Write(p []byte) (int, error) {
        l.Logger.Output(2, string(p))
        return len(p), nil
    }

    func Serve(listener net.Listener, handler http.Handler, proto string, l app.Logger) {
        l.Output(2, fmt.Sprintf("%s: listening on %s", proto, listener.Addr()))

        server := &http.Server{
            Handler:  handler,
            ErrorLog: log.New(logWriter{l}, "", 0),
        }
        err := server.Serve(listener)
        // theres no direct way to detect this error because it is not exposed
        if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
            l.Output(2, fmt.Sprintf("ERROR: http.Serve() - %s", err))
        }

        l.Output(2, fmt.Sprintf("%s: closing %s", proto, listener.Addr()))
    }

  • 相关阅读:
    JS小记
    chrome 插件开发
    js闭包理解
    文件名后缀详解
    Glut 回调函数小结
    vc++ 6.0下Glut的配置 及 Glut 框架介绍
    数字图像点运算实践 (直方图均衡和分段线性拉伸)
    event.keycode值大全
    Bookmarklet
    牛人经典语录
  • 原文地址:https://www.cnblogs.com/zhangboyu/p/7457519.html
Copyright © 2011-2022 走看看