zoukankan      html  css  js  c++  java
  • req_params.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()))
    }

  • 相关阅读:
    codeforces
    hdu
    hdu
    poj 2823
    hdu
    hdu
    hdu
    微信公众号 SDK
    PHP 正则表达式
    注册和登录时的验证码
  • 原文地址:https://www.cnblogs.com/zhangboyu/p/7457515.html
Copyright © 2011-2022 走看看