本文整理匯總了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)
}
示例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
}
示例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)
}
示例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)")
}
}
示例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
}
示例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
}
示例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)
}
示例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")
}
示例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)
}
}
示例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))
}
示例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")
}
示例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))
}
示例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)
}
示例14: StartGin
func StartGin() {
gin.SetMode(gin.ReleaseMode)
r := gin.New()
r.GET("/testApiPing", apiPing)
r.GET("/testApiDB", apiDB)
r.Run(":8082")
}
示例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)
}