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

Golang graceful.Run函数代码示例

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

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



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

示例1: main

func main() {

	var wg sync.WaitGroup

	wg.Add(3)
	go func() {
		n := negroni.New()
		fmt.Println("Launching server on :3000")
		graceful.Run(":3000", 0, n)
		fmt.Println("Terminated server on :3000")
		wg.Done()
	}()
	go func() {
		n := negroni.New()
		fmt.Println("Launching server on :3001")
		graceful.Run(":3001", 0, n)
		fmt.Println("Terminated server on :3001")
		wg.Done()
	}()
	go func() {
		n := negroni.New()
		fmt.Println("Launching server on :3002")
		graceful.Run(":3002", 0, n)
		fmt.Println("Terminated server on :3002")
		wg.Done()
	}()
	fmt.Println("Press ctrl+c. All servers should terminate.")
	wg.Wait()

}
开发者ID:gotstago,项目名称:go-tarabish,代码行数:30,代码来源:main.go


示例2: main

func main() {
	middle := interpose.New()

	// Tell the browser which server this came from.
	// This modifies headers, so we want this to be called before
	// any middleware which might modify the body (in HTTP, the headers cannot be
	// modified after the body is modified)
	middle.Use(func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
			rw.Header().Set("X-Server-Name", "Interpose Test Server")
			next.ServeHTTP(rw, req)
		})
	})

	// Apply the router. By adding it last, all of our other middleware will be
	// executed before the router, allowing us to modify headers before any
	// output has been generated.
	router := mux.NewRouter()
	middle.UseHandler(router)

	router.HandleFunc("/{user}", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page, %s!", mux.Vars(req)["user"])
	})

	// Launch and permit graceful shutdown, allowing up to 10 seconds for existing
	// connections to end
	graceful.Run(":3001", 10*time.Second, middle)
}
开发者ID:RichardEby,项目名称:liveplant-server,代码行数:28,代码来源:main.go


示例3: 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


示例4: main

func main() {
	mw := interpose.New()

	// Use unrolled's secure framework
	// If you inspect the headers, you will see X-Frame-Options set to DENY
	// Must be called before the router because it modifies HTTP headers
	secureMiddleware := secure.New(secure.Options{
		FrameDeny: true,
	})
	mw.Use(secureMiddleware.Handler)

	// Apply the router. By adding it first, all of our other middleware will be
	// executed before the router, allowing us to modify headers before any
	// output has been generated.
	router := mux.NewRouter()
	mw.UseHandler(router)

	router.HandleFunc("/{user}", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page, %s!", mux.Vars(req)["user"])
	})

	// Launch and permit graceful shutdown, allowing up to 10 seconds for existing
	// connections to end
	graceful.Run(":3001", 10*time.Second, mw)
}
开发者ID:mvpmvh,项目名称:interpose,代码行数:25,代码来源:main.go


示例5: main

func main() {
	var (
		addr  = flag.String("addr", ":8080", "endpoint address")
		mongo = flag.String("mongo", "localhost", "mongodb address")
	)
	log.Println("Dialing mongo", *mongo)
	db, err := mgo.Dial(*mongo)
	if err != nil {
		log.Fatalln("failed to connect to mongo:", err)
	}
	defer db.Close()
	mux := http.NewServeMux()
	mux.HandleFunc("/polls/", withCORS(withVars(withData(db, withAPIKey(handlePolls)))))
	log.Println("Starting web server on", *addr)
	graceful.Run(*addr, 1*time.Second, mux)
	log.Println("Stopping...")
}
开发者ID:0-T-0,项目名称:goblueprints,代码行数:17,代码来源:main.go


示例6: main

func main() {
	var (
		addr  = flag.String("addr", ":8080", "エンドポイントのアドレス")
		mongo = flag.String("mongo", "localhost", "MongoDBのアドレス")
	)
	flag.Parse()
	log.Println("MongoDB に接続します", *mongo)
	db, err := mgo.Dial(*mongo)
	if err != nil {
		log.Fatalln("MongoDB への接続に失敗しました:", err)
	}
	defer db.Close()
	mux := http.NewServeMux()
	mux.HandleFunc("/polls/", withCORS(withVars(withData(db, withAPIKey(handlePolls)))))
	log.Println("Webサーバを開始します:", *addr)
	graceful.Run(*addr, 1*time.Second, mux)
	log.Println("停止します...")
}
开发者ID:koshigoe,项目名称:exercise-go-programming-blueprints,代码行数:18,代码来源:main.go


示例7: main

func main() {
	l := log.New(os.Stdout, "[cuddled] ", 0)
	e := log.New(os.Stderr, "[cuddled] ", 0)

	// define flags
	debug := flag.Bool("debug", false, "print debug messages")
	help := flag.Bool("help", false, "print help")
	portname := flag.String("port", "/dev/ttyUSB0", "the serial port name")
	listenaddr := flag.String("listen", ":http", "the address on which to listen")

	// parse flags
	flag.Parse()

	// print help
	if *help {
		flag.Usage()
		os.Exit(0)
	}

	// do not accept arguments
	if flag.NArg() > 0 {
		flag.Usage()
		os.Exit(1)
	}

	// connect serial port
	port, err := cuddle.OpenPort(*portname)
	if err != nil {
		e.Fatalln(err)
	}
	defer port.Close()
	l.Println("Connected to", *portname)

	// update setpoints in background
	go cuddle.SendQueuedMessagesTo(port)

	// set debug
	cuddle.Debug = *debug
	// create server instance
	mux := cuddle.New()

	// run with graceful shutdown
	graceful.Run(*listenaddr, time.Second, mux)
}
开发者ID:Reinaesaya,项目名称:go-cuddlebot,代码行数:44,代码来源:main.go


示例8: QuasarServeHTTP

func QuasarServeHTTP(q *btrdb.Quasar, addr string) {
	go func() {
		log.Info("Active HTTP requests: ", outstandingHttpReqs)
	}()
	mux := pat.New()
	mux.Get("/data/uuid/:uuid", http.HandlerFunc(curry(q, request_get_VRANGE)))
	mux.Get("/csv/uuid/:uuid", http.HandlerFunc(curry(q, request_get_CSV)))
	mux.Post("/directcsv", http.HandlerFunc(curry(q, request_post_MULTICSV)))
	mux.Post("/wrappedcsv", http.HandlerFunc(curry(q, request_post_WRAPPED_MULTICSV)))
	//mux.Get("/q/versions", http.HandlerFunc(curry(q, request_get_VERSIONS)))
	mux.Get("/q/nearest/:uuid", http.HandlerFunc(curry(q, request_get_NEAREST)))
	mux.Post("/q/bracket", http.HandlerFunc(curry(q, request_post_BRACKET)))
	mux.Post("/data/add/:subkey", http.HandlerFunc(curry(q, request_post_INSERT)))
	mux.Post("/data/legacyadd/:subkey", http.HandlerFunc(curry(q, request_post_LEGACYINSERT)))
	mux.Get("/status", http.HandlerFunc(curry(q, request_get_STATUS)))
	//mux.Post("/q/:uuid/v", curry(q, p
	log.Info("serving http on %v", addr)
	graceful.Run(addr, 10*time.Second, mux)
}
开发者ID:gtfierro,项目名称:btrdb,代码行数:19,代码来源:httpinterface.go


示例9: main

func main() {
	var (
		addr  = flag.String("addr", ":8005", "接听地址")
		mongo = flag.String("mongo", "localhost", "MongoDB地址")
	)

	flag.Parse()
	log.Println("MaongoDB链接中")
	db, err := mgo.Dial(*mongo)
	if err != nil {
		log.Fatalf("MaongoDB链接失败:", err)
	}
	defer db.Close()
	mux := http.NewServeMux()
	mux.HandleFunc("/polls/", withCORS(withVars(withData(db, withAPIKey(handlePolls)))))
	log.Println("web服务器启动中:", *addr)
	graceful.Run(*addr, 1*time.Second, mux)
	log.Println("停止中")
}
开发者ID:oywc410,项目名称:MYPG,代码行数:19,代码来源:main.go


示例10: main

func main() {

	log.SetFlags(log.Llongfile)

	//Get the config from the config.yaml file
	config, err := utils.GetConfigFromFile("./config.toml")

	s, err := web.NewServer(config)

	if err != nil {
		log.Fatal(err)
	}

	l := fmt.Sprintf("%s:%d", config.Server.Address, config.Server.Port)

	log.Printf("Listening on: %s", l)

	graceful.Run(l, time.Duration(config.Server.Timeout), s)

}
开发者ID:UniversityRadioYork,项目名称:2016-site,代码行数:20,代码来源:main.go


示例11: main

func main() {
	isDevelopment := os.Getenv("ENVIRONMENT") == "development"
	dbURL := os.Getenv("MONGOLAB_URI")
	if isDevelopment {
		dbURL = os.Getenv("DB_PORT_27017_TCP_ADDR")
	}

	dbAccessor := utils.NewDatabaseAccessor(dbURL, os.Getenv("DATABASE_NAME"), 0)
	cuAccessor := utils.NewCurrentUserAccessor(1)
	s := web.NewServer(*dbAccessor, *cuAccessor, os.Getenv("GOOGLE_OAUTH2_CLIENT_ID"),
		os.Getenv("GOOGLE_OAUTH2_CLIENT_SECRET"), os.Getenv("SESSION_SECRET"),
		isDevelopment, os.Getenv("GOOGLE_ANALYTICS_KEY"))

	port := os.Getenv("PORT")
	if port == "" {
		port = "3000"
	}

	graceful.Run(":"+port, 0, s)
}
开发者ID:pocheptsov,项目名称:refermadness,代码行数:20,代码来源:main.go


示例12: main

func main() {

	initializeDB := flag.Bool("initdb", false, "initalizing database")
	flag.Parse()

	InitApp(logFile, initializeDB)

	m := martini.Classic()
	m.Use(render.Renderer())
	m.Use(martini.Recovery())

	//status
	m.Get("/status", StatusHandler)

	//Login end point
	m.Post("/auth/login", binding.Bind(LoginCredential{}), LoginHandler)

	//Create new user
	m.Post("/user/create", binding.Bind(CreateUserRequest{}), CreateUserHandler)

	//Validate unique username
	m.Post("/validate/username", binding.Bind(ValidateUsernameRequest{}), ValidateUsernameHandler)

	//Validate session token
	m.Post("/validate/token", binding.Bind(ValidateSessionTokenRequest{}), ValidateSessionTokenHandler)

	//Change password
	m.Post("/user/changePassword", binding.Bind(ChangePasswordRequest{}), ChangePasswordHandler)

	//Check permission
	m.Post("/user/checkPermission", binding.Bind(CheckPermissionRequest{}), CheckPermissionsForUserHandler)

	appGracefulShutdownTimeinSeconds, err := strconv.Atoi(viper.GetString("appGracefulShutdownTimeinSeconds"))
	if err != nil {
		ERROR.Panicln("Cannot start the server, shutdown time missing from config file")
	}

	graceful.Run(":"+viper.GetString("appPort"), time.Duration(appGracefulShutdownTimeinSeconds)*time.Second, m)

	defer cleanUpAfterShutdown()
}
开发者ID:RodrigoDev,项目名称:gondalf,代码行数:41,代码来源:server.go


示例13: main

func main() {
	router := mux.NewRouter()

	router.HandleFunc("/{user}", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page, %s!", mux.Vars(req)["user"])
	})

	mw := interpose.New()

	// Use logrus
	x := negroni.Handler(negronilogrus.NewMiddleware())
	mw.Use(adaptors.FromNegroni(x))

	// Apply the router. By adding it last, all of our other middleware will be
	// executed before the router, allowing us to modify headers before any
	// output has been generated.
	mw.UseHandler(router)

	// Launch and permit graceful shutdown, allowing up to 10 seconds for existing
	// connections to end
	graceful.Run(":3001", 10*time.Second, mw)
}
开发者ID:mvpmvh,项目名称:interpose,代码行数:22,代码来源:main.go


示例14: main

func main() {
	graceful.Run(":80", 3*time.Second, serve.Handler())
}
开发者ID:h12w,项目名称:docker-site,代码行数:3,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang objx.MSI函数代码示例发布时间:2022-05-28
下一篇:
Golang test.MakeTestContextWithPath函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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