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


Golang gin.SetMode函数代码示例

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


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

示例1: main

func main() {
	gin.SetMode(gin.ReleaseMode)

	s := loadServerCtx()
	if s.Debug {
		log.SetLevel(log.DebugLevel)
		gin.SetMode(gin.DebugMode)
	}

	c, err := statsdClient(s.StatsdUrl)
	if err != nil {
		log.WithField("statsdUrl", s.StatsdUrl).Fatal("Could not connect to statsd")
	}

	r := gin.Default()
	r.GET("/status", func(c *gin.Context) {
		c.String(200, "OK")
	})

	if len(s.AppPasswd) > 0 {
		auth := r.Group("/", gin.BasicAuth(s.AppPasswd))
		auth.POST("/", s.processLogs)
	}

	s.in = make(chan *logData, bufferLen)
	defer close(s.in)
	s.out = make(chan *logMetrics, bufferLen)
	defer close(s.out)
	go logProcess(s.in, s.out)
	go c.sendToStatsd(s.out)
	log.Infoln("Server ready ...")
	r.Run(":" + s.Port)

}
开发者ID:urbandictionary,项目名称:heroku-datadog-drain-golang,代码行数:34,代码来源:server.go

示例2: NewWebServer

// NewWebServer : create and configure a new web server
func NewWebServer(c *Config, l *Store, level int) *WebHandler {
	wh := &WebHandler{}
	// create the router
	if level == 0 {
		gin.SetMode(gin.ReleaseMode)
		wh.router = gin.New()
	}
	if level == 1 {
		gin.SetMode(gin.ReleaseMode)
		wh.router = gin.Default()
	}
	if level > 1 {
		wh.router = gin.Default()
	}
	// bind the lease db
	wh.store = l
	// bind the config
	wh.config = c
	// bind the config to the file store
	wh.fs = c.fs

	// templates
	// base os selector
	t, err := template.New("list").Parse(OsSelector)
	if err != nil {
		logger.Critical("template error : %v", err)
		return nil
	}
	// class selector
	_, err = t.New("class").Parse(ClassSelector)
	if err != nil {
		logger.Critical("template error : %v", err)
		return nil
	}

	wh.templates = t
	// rocket handlers
	wh.RocketHandler()
	// chose and operating system
	wh.router.GET("/choose", wh.Lister)
	wh.router.GET("/choose/:dist/:mac", wh.Chooser)
	wh.router.GET("/class/:dist/:mac", wh.ClassChooser)
	wh.router.GET("/setclass/:dist/:class/:mac", wh.ClassSet)
	// get the boot line for your operating system
	wh.router.GET("/boot/:dist/:mac", wh.Starter)
	// load the kernel and file system
	wh.router.GET("/image/:dist/*path", wh.Images)
	// serve the bin folder
	wh.router.GET("/bin/*path", wh.Binaries)
	// actions for each distro
	wh.router.GET("/action/:dist/:action", wh.Action)
	// configs for each distro
	wh.router.GET("/config/:dist/:action", wh.Config)
	if wh.config.Spawn {
		wh.SpawnHandler()
	}
	return wh
}
开发者ID:dardevelin,项目名称:astralboot,代码行数:59,代码来源:web.go

示例3: init

func init() {
	readConfig()
	if config.Environment.Env == "release" {
		gin.SetMode(gin.ReleaseMode)
	}
	if config.Environment.Env == "debug" {
		gin.SetMode(gin.DebugMode)
	}
	client = elasticsearch.NewClientFromUrl(config.Es_cluster.Addr)
}
开发者ID:cch123,项目名称:esweb,代码行数:10,代码来源:main.go

示例4: SetMode

func SetMode(mode string) {
	switch mode {
	case "release":
		gin.SetMode(gin.ReleaseMode)
	case "debug":
		gin.SetMode(gin.DebugMode)
	case "test":
		gin.SetMode(gin.TestMode)
	default:
		panic("mode unavailable. (debug, release, test)")
	}
}
开发者ID:Nesurion,项目名称:milight-daemon,代码行数:12,代码来源:main.go

示例5: SetMode

func SetMode(value string) {
	switch value {
	case DevMode:
		gin.SetMode(gin.DebugMode)
	case ProdMode:
		gin.SetMode(gin.ReleaseMode)
	case TestMode:
		gin.SetMode(gin.TestMode)
	default:
		panic("mode unknown: " + value)
	}
	modeName = value
}
开发者ID:gophergala2016,项目名称:source,代码行数:13,代码来源:mode.go

示例6: NewDaemon

func NewDaemon(port int, debug bool, dockerClient *dockerclient.DockerClient, dockerHost string, redisClient *redis.Client) *Daemon {
	if debug {
		logs.Debug.Println("Initializing daemon in debug mode")
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
	}
	engine := gin.Default()
	cron := cron.New()
	intools.Engine = &intools.IntoolsEngineImpl{dockerClient, dockerHost, redisClient, cron}
	daemon := &Daemon{port, engine, debug}
	return daemon
}
开发者ID:iMax-pp,项目名称:intools-engine,代码行数:13,代码来源:server.go

示例7: main

func main() {
	// Neo4J Database setup
	var db *neoism.Database
	if os.Getenv("NEO4J_HOST") != "" && os.Getenv("NEO4J_PORT") != "" {
		if connected, err := database.Connect(
			os.Getenv("NEO4J_USER"),
			os.Getenv("NEO4J_PASS"),
			os.Getenv("NEO4J_HOST"),
			os.Getenv("NEO4J_PORT"),
		); err != nil {
			log.Fatal(err)
		} else {
			db = connected
		}
	}

	// Postgres Database setup
	var pgdb *gorm.DB
	if connected, err := gorm.Open("postgres", "user=postgres dbname=newsapi sslmode=disable host=db"); err != nil {
		// if connected, err := gorm.Open("postgres", "user=newsapi dbname=newsapi sslmode=disable"); err != nil {
		log.Fatal(err)
	} else {
		pgdb = &connected
		pgdb.AutoMigrate(&models.User{})
	}

	// Setup analytics client
	var analytics *ga.Client
	if token := os.Getenv("ANALYTICS_TOKEN"); token == "" {
		fmt.Printf("Analytics token not provided.\n")
	} else if client, err := ga.NewClient(token); err != nil {
		log.Fatal(err)
	} else {
		fmt.Printf("Analytics activated.\n")
		analytics = client
	}

	// Setup environment
	if environment := os.Getenv("ENVIRONMENT"); environment == "PRODUCTION" {
		gin.SetMode(gin.ReleaseMode)
	} else {
		gin.SetMode(gin.DebugMode)
		if db != nil {
			db.Session.Log = true
		}
	}

	// Start
	Server(db, pgdb, analytics).Run(port)
}
开发者ID:IIC2173-2015-2-Grupo2,项目名称:news-api,代码行数:50,代码来源:main.go

示例8: StartGin

func StartGin() {
	gin.SetMode(gin.ReleaseMode)

	router := gin.New()
	gin.Logger()
	router.Use(rateLimit, gin.Recovery())
	router.Use(gin.Logger())
	router.LoadHTMLGlob("resources/*.templ.html")
	router.Static("/static", "resources/static")
	router.GET("/", MyBenchLogger(), index)
	router.GET("/auth", authentication.RequireTokenAuthentication(), index)
	router.POST("/test", controllers.Login)
	router.GET("/room/:name", roomGET)
	router.POST("/room-post/:roomid", roomPOST)
	router.GET("/stream/:roomid", streamRoom)

	//mongodb user create
	uc := user_controllers.NewUserController(getSession())
	router.GET("/user", uc.GetUser)
	router.GET("/message", uc.GetMessage)
	router.POST("/message", uc.CreateMessage)
	router.POST("/user", uc.CreateUser)
	router.DELETE("/user/:id", uc.RemoveUser)

	router.Run(":5001")

}
开发者ID:atyenoria,项目名称:gin-websocket-mongo-mysql-client-jwt-redis,代码行数:27,代码来源:main.go

示例9: main

func main() {
	flag.Parse()

	common.Info("initializing metric http endpoint")
	connector, err := common.BuildRabbitMQConnector(*rabbitHost, *rabbitPort, *rabbitUser, *rabbitPassword, *rabbitExchange)
	if err != nil {
		log.Fatalln("error", err)
	}

	bindTo := fmt.Sprintf(":%d", *serverPort)

	common.Info("binding to:", bindTo)

	service := metricsService{connector: connector}

	gin.SetMode(gin.ReleaseMode)
	r := gin.New()
	r.Use(gin.Recovery())
	r.POST("/metrics", service.createMetric)
	r.GET("/debug/vars", expvar.Handler())

	if err := r.Run(bindTo); err != nil {
		log.Fatalln(err)
	}
}
开发者ID:ezeql,项目名称:koding-challenge,代码行数:25,代码来源:main.go

示例10: serve

func serve() {
	if !Dev {
		gin.SetMode(gin.ReleaseMode)
	}
	r := gin.Default()
	r.NoRoute(handle404)

	r.Static("/assets", "./client/assets/")
	r.StaticFile("/bundle.js", "./client/bundle.js")

	// HTML5 Boilerplate
	r.StaticFile("/favicon.ico", "./client/assets/favicon.ico")
	r.StaticFile("/apple-touch-icon.png", "./client/assets/apple-touch-icon.png")
	r.StaticFile("/tile-wide.png", "./client/assets/tile-wide.png")
	r.StaticFile("/tile.png", "./client/assets/tile.png")
	r.StaticFile("/.htaccess", "./client/assets/.htaccess")
	r.StaticFile("/robots.txt", "./client/assets/robots.txt")
	r.StaticFile("/humans.txt", "./client/assets/humans.txt")
	r.StaticFile("/browserconfig.xml", "./client/assets/browserconfig.xml")
	r.StaticFile("/crossdomain.xml", "./client/assets/crossdomain.xml")

	r.LoadHTMLGlob("./client/templates/*")
	r.GET("/", func(c *gin.Context) {
		if Dev {
			r.LoadHTMLGlob("./client/templates/*")
		}
		obj := gin.H{"title": "Main Website"}
		c.HTML(http.StatusOK, "index.html", obj)
	})
	// Listen and serve on 0.0.0.0:Port
	r.Run(":" + strconv.Itoa(Port))
}
开发者ID:01AutoMonkey,项目名称:gin-webapp-init,代码行数:32,代码来源:server.go

示例11: main

func main() {
	gin.SetMode(gin.DebugMode)
	r := gin.New()

	r.GET("/:platform/*sourceurl", func(c *gin.Context) {
		platform := c.Params.ByName("platform")
		sourceurl := c.Params.ByName("sourceurl")[1:]

		v := url.Values{}
		var result string
		if platform == "sina" {
			v.Set("source", "")
			// v.Set("access_token", "")
			v.Set("url_long", sourceurl)
			log.Println(v.Encode())

			result = doPost(v.Encode(), "https://api.weibo.com/2/short_url/shorten.json")
		} else if platform == "baidu" {

		} else {
			result = platform + ": " + sourceurl
		}

		c.String(http.StatusOK, result)
	})

	r.Run(":8890")
}
开发者ID:top,项目名称:python,代码行数:28,代码来源:short_url.go

示例12: main

func main() {
	r.SetVerbose(true)

	defer utils.Recover()
	utils.ListenSignals()
	utils.Liveness()

	if os.Getenv("DEBUG_N") != "true" {
		gin.SetMode(gin.ReleaseMode)
	}

	engine := gin.New()

	engine.Use(gin.Recovery())
	engine.Use(func() gin.HandlerFunc {
		return func(c *gin.Context) {
			defer c.Next()
			log.Info(c.Request.Method, c.Request.URL.Path, c.Writer.Status())
		}
	}())

	api.Initialize(engine)

	engine.Run(config.Get(config.KEY_API_PORT))
}
开发者ID:neutrinoapp,项目名称:neutrino,代码行数:25,代码来源:main.go

示例13: init

func init() {
	rand.Seed(time.Now().UTC().UnixNano()) // need to initialize the seed
	gin.SetMode(gin.ReleaseMode)

	// Removed some commands from here
	RootCmd.AddCommand(daedalusCmd)
}
开发者ID:conejoninja,项目名称:gc6,代码行数:7,代码来源:daedalus.go

示例14: StartGin

func StartGin() {
	gin.SetMode(gin.ReleaseMode)
	r := gin.New()
	r.GET("/testApiPing", apiPing)
	r.GET("/testApiDB", apiDB)
	r.Run(":8082")
}
开发者ID:jbosnjak,项目名称:Basic-Language-Perfomance-Compare,代码行数:7,代码来源:testApi.go

示例15: Listen

// Listen Tells Gin API to start
func Listen(iface string, s *discordgo.Session, logger *logging.Logger) {
	// set the refs to point to main
	var v1 *gin.RouterGroup
	session = s
	c := config.Get()
	log = logger

	if c.LogLevel != "debug" {
		gin.SetMode(gin.ReleaseMode)
	}

	//r := gin.Default()
	r := gin.New()

	r.Use(loggerino())
	r.Use(gin.Recovery())

	if c.APIPassword != "" {
		log.Info("Basic Authentication enabled for API")
		v1 = r.Group("/v1", gin.BasicAuth(gin.Accounts{
			c.APIUsername: c.APIPassword,
		}))
	} else {
		log.Warning("DIGO_API_PASSWORD and DIGO_API_USERNAME are not set")
		log.Warning("The API is open to all requests")
		v1 = r.Group("/v1")
	}

	v1.GET("/version", versionV1)
	v1.GET("/channels", channelsV1)
	v1.POST("/message", messageV1)

	go r.Run(iface)
	log.Noticef("Digo API is listening on %s", c.APIInterface)
}
开发者ID:Skullever,项目名称:digo,代码行数:36,代码来源:api.go


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