• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang handlers.CombinedLoggingHandler函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/gorilla/handlers.CombinedLoggingHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang CombinedLoggingHandler函数的具体用法?Golang CombinedLoggingHandler怎么用?Golang CombinedLoggingHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了CombinedLoggingHandler函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: ServeHTTP

// ServeHTTP registers the `HTTPCachingHandler` and sets up the route
// handlers and logging.
func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	srv.Use(middleware.HTTPCachingHandler)
	srv.RegisterRoutes()

	logger := gh.CombinedLoggingHandler(os.Stdout, srv.Router)
	logger.ServeHTTP(w, r)
}
开发者ID:vsco,项目名称:dcdr,代码行数:9,代码来源:server.go


示例17: newTestEnvWithConfig

func newTestEnvWithConfig(t *testing.T, config *configuration.Configuration) *testEnv {
	ctx := context.Background()

	app := NewApp(ctx, *config)
	server := httptest.NewServer(handlers.CombinedLoggingHandler(os.Stderr, app))
	builder, err := v2.NewURLBuilderFromString(server.URL + config.HTTP.Prefix)

	if err != nil {
		t.Fatalf("error creating url builder: %v", err)
	}

	pk, err := libtrust.GenerateECP256PrivateKey()
	if err != nil {
		t.Fatalf("unexpected error generating private key: %v", err)
	}

	return &testEnv{
		pk:      pk,
		ctx:     ctx,
		config:  *config,
		app:     app,
		server:  server,
		builder: builder,
	}
}
开发者ID:lusis,项目名称:distribution,代码行数:25,代码来源:api_test.go


示例18: main

func main() {
	flag.Parse()

	var err error
	if config, err = cfg.ReadConf(); err != nil {
		log.Printf("ReadConf: %v", err)
		os.Exit(1)
	}

	index = template.Must(template.New("index").Parse(indexTemplate))
	servers = &serversInfo{Info: map[string]ServerInfo{}}

	go staleCheck()

	http.Handle("/", handlers.CombinedLoggingHandler(os.Stdout, http.HandlerFunc(indexHandler)))
	log.Println("Serving mothership index at /")

	dir := wwwDir()
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(dir))))
	log.Printf("Serving static files from %v at /static", dir)

	if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
		log.Println("Error starting www server:", err)
		// os.IsPermission(err) doesn't work.
		if *port == 80 {
			log.Printf("Try: sudo setcap 'cap_net_bind_service=+ep' %v", os.Args[0])
		}
	}
}
开发者ID:nictuku,项目名称:mothership,代码行数:29,代码来源:main.go


示例19: main

func main() {

	//Creating stock records
	var st = (new(StockRecords))

	//TradeID Initialization
	tradeId = 0

	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(":1333", server))

}
开发者ID:Noman-Khan-SJSU,项目名称:cmpe273-assignment1,代码行数:26,代码来源:Go-Server.go


示例20: launchServer

// launchServer sets up the http fileserver. Exciting!
func launchServer() {
	r := mux.NewRouter().
		StrictSlash(true)

	// Grab all our config junk and prepare to launch
	ip := viper.GetString("ListenAddr")
	port := viper.GetInt("ListenPort")
	fmt.Println(viper.GetInt("ListenPort"))

	// I... I guess, if you want TLS, you can totally have it
	cert, key := viper.GetString("CertFile"), viper.GetString("KeyFile")
	useTLS := len(cert) > 0 && len(key) > 0
	scheme := "https"
	if !useTLS {
		if port == 0 {
			port = 80
		}
		scheme = "http"
	} else if port == 0 {
		port = 443
	}

	p := fmt.Sprintf("%s:%d", ip, port)

	root, files := viper.GetString("ServerRoot"), viper.GetString("StaticFiles")

	reload, err := lr.New(lr.DefaultName, lr.DefaultPort)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	go reload.ListenAndServe()

	r.PathPrefix(root).
		Handler(
			handlers.CombinedLoggingHandler(
				os.Stdout, injectReload(root, files, scheme),
			),
		)

	go func() {
		fmt.Printf("Launching ogload on %s\n", p)
		if !useTLS {
			if err := http.ListenAndServe(p, r); err != nil {
				fmt.Printf("Server failed! scheme=%s, addr=%s, err=%v\n", scheme, p, err)
				os.Exit(1)
			}
			return
		}

		if err := http.ListenAndServeTLS(p, cert, key, r); err != nil {
			fmt.Printf("TLS Server failed! scheme=%s, addr=%s, err=%v\n", scheme, p, err)
			os.Exit(1)
		}
	}()

	wait := watchDir(files, reload)
	<-wait
}
开发者ID:pombredanne,项目名称:tools-8,代码行数:60,代码来源:main.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang handlers.CompressHandler函数代码示例发布时间:2022-05-23
下一篇:
Golang csrf.TemplateField函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap