當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。