本文整理匯總了Golang中github.com/gorilla/handlers.CombinedLoggingHandler函數的典型用法代碼示例。如果您正苦於以下問題:Golang CombinedLoggingHandler函數的具體用法?Golang CombinedLoggingHandler怎麽用?Golang CombinedLoggingHandler使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CombinedLoggingHandler函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
// Setup the global variables and settings
err := models.Setup()
if err != nil {
fmt.Println(err)
}
wg := &sync.WaitGroup{}
wg.Add(1)
// Start the web servers
go func() {
defer wg.Done()
if config.Conf.AdminConf.UseTLS { // use TLS for Admin web server if available
Logger.Printf("Starting admin server at https://%s\n", config.Conf.AdminConf.ListenURL)
Logger.Fatal(http.ListenAndServeTLS(config.Conf.AdminConf.ListenURL, config.Conf.AdminConf.CertPath, config.Conf.AdminConf.KeyPath,
handlers.CombinedLoggingHandler(os.Stdout, controllers.CreateAdminRouter())))
} else {
Logger.Printf("Starting admin server at http://%s\n", config.Conf.AdminConf.ListenURL)
Logger.Fatal(http.ListenAndServe(config.Conf.AdminConf.ListenURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreateAdminRouter())))
}
}()
wg.Add(1)
go func() {
defer wg.Done()
if config.Conf.PhishConf.UseTLS { // use TLS for Phish web server if available
Logger.Printf("Starting phishing server at https://%s\n", config.Conf.PhishConf.ListenURL)
Logger.Fatal(http.ListenAndServeTLS(config.Conf.PhishConf.ListenURL, config.Conf.PhishConf.CertPath, config.Conf.PhishConf.KeyPath,
handlers.CombinedLoggingHandler(os.Stdout, controllers.CreatePhishingRouter())))
} else {
Logger.Printf("Starting phishing server at http://%s\n", config.Conf.PhishConf.ListenURL)
Logger.Fatal(http.ListenAndServe(config.Conf.PhishConf.ListenURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreatePhishingRouter())))
}
}()
wg.Wait()
}
示例2: main
func main() {
// Setup the global variables and settings
err := models.Setup()
if err != nil {
fmt.Println(err)
}
// Start the web servers
Logger.Printf("Admin server started at http://%s\n", config.Conf.AdminURL)
go http.ListenAndServe(config.Conf.AdminURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreateAdminRouter()))
Logger.Printf("Phishing server started at http://%s\n", config.Conf.PhishURL)
http.ListenAndServe(config.Conf.PhishURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreatePhishingRouter()))
}
示例3: main
func main() {
file, err := os.OpenFile("dashy.log", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
log.Fatalf("Failed to open log file: %s", err)
}
defer file.Close()
logWriter := io.MultiWriter(file, os.Stdout)
log.SetOutput(logWriter)
client := gocd.NewClient()
mux := http.DefaultServeMux
mux.HandleFunc("/dashy", app.DashyHandler(client))
mux.Handle("/", http.FileServer(http.Dir("./public")))
loggingHandler := handlers.CombinedLoggingHandler(logWriter, mux)
server := &http.Server{
Addr: ":3000",
Handler: loggingHandler,
}
fmt.Println("Starting the application on http://localhost:3000")
err = server.ListenAndServe()
if err != nil {
fmt.Printf("failed to start application: %s\n", err)
}
}
示例4: setupDaemon
func setupDaemon(port int) {
router := mux.NewRouter()
router.HandleFunc("/", HomeHandler)
http.Handle("/", router)
http.Handle("/static/", http.FileServer(http.Dir(".")))
restHandler := rest.ResourceHandler{}
restHandler.SetRoutes(
rest.Route{"GET", "/api/test", RestTest},
)
restHandler.EnableGzip = true
restHandler.EnableLogAsJson = true
restHandler.EnableResponseStackTrace = true
restHandler.EnableStatusService = true
http.Handle("/api/", &restHandler)
err := http.ListenAndServe(fmt.Sprintf(":%d", port), handlers.CombinedLoggingHandler(os.Stdout, http.DefaultServeMux))
if err != nil {
log.Fatalln(err)
}
}
示例5: main
func main() {
Portfolios = make(map[float32]Portfolio)
// HTTP request multiplexer
// mux.Router matches incoming requests against a list of registered routes
// and calls a handler for the route that matches the URL
r := mux.NewRouter()
s := rpc.NewServer()
s.RegisterCodec(json.NewCodec(), "application/json")
stockDealer := new(StockDealer)
s.RegisterService(stockDealer, "")
// middle ware: organizing hared functionalities
chain := alice.New(
func(h http.Handler) http.Handler {
return handlers.CombinedLoggingHandler(os.Stdout, h)
},
handlers.CompressHandler,
func(h http.Handler) http.Handler {
return recovery.Handler(os.Stderr, h, true)
})
r.Handle("/rpc", chain.Then(s))
fmt.Println("Server listening on 8080")
log.Fatal(http.ListenAndServe(":8080", r))
}
示例6: startWebserver
func startWebserver() {
processEnv()
router = mux.NewRouter()
router.HandleFunc("/ws", wrap(wsHandler))
dockerRouter := router.PathPrefix(fmt.Sprintf("/api/%v/docker", apiVersion)).Subrouter()
dockerRouter.HandleFunc("/containers", wrap(dockerClient.ContainersHandler))
dockerRouter.HandleFunc("/containers/graph", wrap(dockerClient.ContainerGraphHandler))
dockerRouter.HandleFunc("/container/{id}", wrap(dockerClient.ContainerHandler))
dockerRouter.HandleFunc("/images", wrap(dockerClient.ImagesHandler))
dockerRouter.HandleFunc("/image/history/{id}", wrap(dockerClient.HistoryHandler))
dockerRouter.HandleFunc("/info", wrap(dockerClient.InfoHandler))
consulRouter := router.PathPrefix(fmt.Sprintf("/api/%v/consul", apiVersion)).Subrouter()
consulRouter.HandleFunc("/datacenters", wrap(consulRegistry.DatacentersHandler))
consulRouter.HandleFunc("/nodes", wrap(consulRegistry.NodesHandler))
consulRouter.HandleFunc("/nodes/{dc}", wrap(consulRegistry.NodesHandler))
consulRouter.HandleFunc("/node/{name}", wrap(consulRegistry.NodeHandler))
consulRouter.HandleFunc("/health/{name}", wrap(consulRegistry.HealthHandler))
consulRouter.HandleFunc("/health/{name}/{dc}", wrap(consulRegistry.HealthHandler))
http.Handle("/", router)
loggedRouter := handlers.CombinedLoggingHandler(os.Stdout, router)
panic(http.ListenAndServe(addr, handlers.CompressHandler(loggedRouter)))
}
示例7: main
func main() {
//initialize the stock account
var st = (new(StockAccounts))
//initialize a tradeId with random number
tradeId = rand.Intn(10000) + 1
// //register the stock account data and start server with HTTP protocol
// rpc.Register(&st)
// rpc.HandleHTTP()
// //start listening
// err := http.ListenAndServe(":1234", nil) //nil, no need for handler
router := mux.NewRouter()
server := rpc.NewServer()
server.RegisterCodec(json.NewCodec(), "application/json")
server.RegisterService(st, "")
chain := alice.New(
func(h http.Handler) http.Handler {
return handlers.CombinedLoggingHandler(os.Stdout, h)
},
handlers.CompressHandler,
func(h http.Handler) http.Handler {
return recovery.Handler(os.Stderr, h, true)
})
router.Handle("/rpc", chain.Then(server))
log.Fatal(http.ListenAndServe(":1234", server))
// checkError(err)
}
示例8: ServeHTTP
func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
if l.file == nil {
next(rw, r)
} else {
handlers.CombinedLoggingHandler(l.file, next).ServeHTTP(rw, r)
}
}
示例9: main
func main() {
flag.Parse()
listen := fmt.Sprintf(":%s", *port)
router := mux.NewRouter()
// static files
root, _ := os.Getwd()
router.PathPrefix("/static").Handler(http.StripPrefix("/static", http.FileServer(http.Dir(path.Join(root, "public")))))
// web routes
router.PathPrefix("/").Handler(tarabish.BuildRoutes())
// setup server
var handler http.Handler
// if Debug is true, enable logging
if os.Getenv("DEBUG") == "true" {
log.SetLevel(log.DebugLevel)
handler = handlers.CombinedLoggingHandler(os.Stdout, router)
} else {
handler = router
}
log.WithFields(log.Fields{
"listen": listen,
}).Info("Server running")
graceful.Run(listen, 10*time.Second, handler)
}
示例10: NewRegistry
// NewRegistry creates a new registry from a context and configuration struct.
func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Registry, error) {
var err error
ctx, err = configureLogging(ctx, config)
if err != nil {
return nil, fmt.Errorf("error configuring logger: %v", err)
}
// inject a logger into the uuid library. warns us if there is a problem
// with uuid generation under low entropy.
uuid.Loggerf = context.GetLogger(ctx).Warnf
app := handlers.NewApp(ctx, config)
// TODO(aaronl): The global scope of the health checks means NewRegistry
// can only be called once per process.
app.RegisterHealthChecks()
handler := configureReporting(app)
handler = alive("/", handler)
handler = health.Handler(handler)
handler = panicHandler(handler)
handler = gorhandlers.CombinedLoggingHandler(os.Stdout, handler)
server := &http.Server{
Handler: handler,
}
return &Registry{
app: app,
config: config,
server: server,
}, nil
}
示例11: main
func main() {
if !flag.Parsed() {
flag.Parse()
}
router := mux.NewRouter()
router.StrictSlash(true)
for _, route := range routes {
handler := http.Handler(http.HandlerFunc(route.HandlerFunc))
switch route.Type {
case "JSON":
handler = handlers.ContentTypeHandler(handler, "application/json")
case "":
break
default:
log.Fatalf("invalid route type: %v", route.Type)
}
r := router.NewRoute()
r.Name(route.Name).
Path(route.Path).
Methods(route.Methods).
Handler(handler)
}
address := fmt.Sprintf(":%d", *port)
handler := handlers.CombinedLoggingHandler(os.Stderr, router)
log.Printf("Version: %s", version.DeploymentManagerVersion)
log.Printf("Listening on port %d...", *port)
log.Fatal(http.ListenAndServe(address, handler))
}
示例12: main
func main() {
flag.Parse()
glog.Infof("Starting Goship...")
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
auth.Initialize(auth.User{Name: *defaultUser, Avatar: *defaultAvatar}, []byte(*cookieSessionHash))
h, err := buildHandler(ctx)
if err != nil {
glog.Fatal(err)
}
w := io.WriteCloser(os.Stdout)
if *requestLog != "-" {
w, err = os.OpenFile(*requestLog, os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
glog.Fatalf("Cannot open request log %s: %v", *requestLog, err)
}
defer w.Close()
}
h = ghandlers.CombinedLoggingHandler(w, h)
fmt.Printf("Running on %s\n", *bindAddress)
s := &http.Server{
Addr: *bindAddress,
Handler: h,
}
if err := s.ListenAndServe(); err != nil {
glog.Fatal(err)
}
}
示例13: main
func main() {
lo = C.lok_init(C.CString("/usr/lib/libreoffice/program"))
if lo == nil {
return
}
http.HandleFunc("/pdf", func(w http.ResponseWriter, r *http.Request) {
bytes, err := convert(r, "pdf")
if err != nil {
return
}
w.Header().Set("Content-Type", "application/pdf")
w.Write(bytes)
})
http.HandleFunc("/txt", func(w http.ResponseWriter, r *http.Request) {
bytes, err := convert(r, "txt")
if err != nil {
return
}
w.Header().Set("Content-Type", "text/plain;charset=utf8")
w.Write(bytes)
})
http.ListenAndServe(
":3000",
handlers.CombinedLoggingHandler(os.Stdout, http.DefaultServeMux),
)
}
示例14: main
func main() {
r := mux.NewRouter()
flag.Parse()
if flag.NArg() != 1 {
log.Fatal("filename not specified")
}
dirname := flag.Args()[0]
if _, err := os.Stat(dirname); os.IsNotExist(err) {
log.Println(err)
os.Exit(0)
}
fs := http.FileServer(http.Dir(dirname))
log.Println("Serving", dirname)
proxy1 := makeProxyHandler("http://localhost:6543")
r.HandleFunc("/api/{_dummy:.*}/", handler(proxy1))
// To use my router the behavior is different to `http.Handle`
// matching will only occur on a fixed path or using an expression to
// handle depth
// Below I use `PathPrefix` with a `Handler` to fix this.
r.PathPrefix("/").Handler(handlers.CombinedLoggingHandler(os.Stdout, fs))
http.Handle("/", r)
log.Println("Listening...on port :8000")
err := http.ListenAndServe(":8000", nil)
if err != nil {
panic(err)
}
}
示例15: main
func main() {
//stock account Initialization
var st = (new(StockAccounts))
//Trade Id random generator
tradeId = rand.Intn(99999) + 1
//start listening
router := mux.NewRouter()
server := rpc.NewServer()
server.RegisterCodec(json.NewCodec(), "application/json")
server.RegisterService(st, "")
chain := alice.New(
func(h http.Handler) http.Handler {
return handlers.CombinedLoggingHandler(os.Stdout, h)
},
handlers.CompressHandler,
func(h http.Handler) http.Handler {
return recovery.Handler(os.Stderr, h, true)
})
router.Handle("/rpc", chain.Then(server))
log.Fatal(http.ListenAndServe(":8070", server))
}