当前位置: 首页>>代码示例>>Golang>>正文


Golang handlers.CombinedLoggingHandler函数代码示例

本文整理汇总了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()
}
开发者ID:StrangeUSB,项目名称:gophish,代码行数:34,代码来源:gophish.go

示例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()))
}
开发者ID:tohitsugu,项目名称:gophish,代码行数:12,代码来源:gophish.go

示例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)
	}
}
开发者ID:chiku,项目名称:dashy,代码行数:27,代码来源:main.go

示例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)
	}

}
开发者ID:koensayr,项目名称:geodns-config,代码行数:27,代码来源:dnsconfig.go

示例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))
}
开发者ID:gyoho,项目名称:cmpe273-assignment1,代码行数:28,代码来源:server.go

示例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)))
}
开发者ID:dmcsorley,项目名称:avast,代码行数:26,代码来源:webserver.go

示例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)

}
开发者ID:michaelzhd,项目名称:CMPE273,代码行数:34,代码来源:stockserver_v2.go

示例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)
	}
}
开发者ID:goguardian,项目名称:traefik,代码行数:7,代码来源:logger.go

示例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)
}
开发者ID:gotstago,项目名称:go-tarabish,代码行数:31,代码来源:tarabish.go

示例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
}
开发者ID:RomainVabre,项目名称:origin,代码行数:32,代码来源:registry.go

示例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))
}
开发者ID:shawnps,项目名称:deployment-manager,代码行数:31,代码来源:main.go

示例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)
	}
}
开发者ID:kgrvamsi,项目名称:goship,代码行数:33,代码来源:main.go

示例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),
	)
}
开发者ID:JRaspass,项目名称:doc-convert,代码行数:34,代码来源:main.go

示例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)
	}
}
开发者ID:highway900,项目名称:reverseProxy,代码行数:35,代码来源:main.go

示例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))

}
开发者ID:imabdul,项目名称:cmpe273-assignment1,代码行数:27,代码来源:VirtualStockTradingServer.go


注:本文中的github.com/gorilla/handlers.CombinedLoggingHandler函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。