Esempio n. 1
0
func main() {
	r := gin.New()
	initProcess(r)

	// start fastcgi
	go func() {
		if config.GLOBAL_CONFIG.HttpConfig.Enable {
			var err error = nil
			if gin.IsDebugging() {
				log.Printf("[GIN-debug] Listening and serving HTTP on %s\n", config.GLOBAL_CONFIG.HttpConfig.Bind)
			}
			defer func() {
				if err != nil && gin.IsDebugging() {
					log.Printf("[GIN-debug] [ERROR] %v\n", err)
				}
			}()

			server := &http.Server{
				Addr:    config.GLOBAL_CONFIG.HttpConfig.Bind,
				Handler: r,
			}

			err = server.ListenAndServe()
		}
	}()

	startFastCgi(r)
}
Esempio n. 2
0
func (r HTML) Render(w http.ResponseWriter) error {
	w.Header()["Content-Type"] = htmlContentType
	if gin.IsDebugging() {
		BuildTemplate(r.tplPath)
	}
	return BeeTemplates[r.Name].ExecuteTemplate(w, r.Name, r.Data)
}
Esempio n. 3
0
func New(context *gin.Context) *Renderer {
	if gin.IsDebugging() {
		loadTemplates()
	}

	return &Renderer{
		ResponseWriter: context.Writer,
		req:            context.Request,
	}
}
Esempio n. 4
0
//TODO customize templates
func loadHTMLGlob(r *gin.Engine, pattern string, templFunc func(*template.Template)) {
	if gin.IsDebugging() {
		if len(pattern) <= 0 {
			panic("the HTML debug render was created without files or glob pattern")
		}
	}
	templ := template.New("")
	templFunc(templ)
	templ = template.Must(templ.ParseGlob(pattern))
	r.SetHTMLTemplate(templ)
}
Esempio n. 5
0
func main() {

	// Configure
	router := gin.Default()

	// Set html render options
	htmlRender := GinHTMLRender.New()
	htmlRender.Debug = gin.IsDebugging()
	htmlRender.Layout = "layouts/default"

	// Tell gin to use our html render
	router.HTMLRender = htmlRender.Create()

	router.RedirectTrailingSlash = true
	router.RedirectFixedPath = true

	// Middlewares
	router.Use(middlewares.Connect)
	router.Use(middlewares.ErrorHandler)

	// Statics
	router.Static("/public", "./public")

	// Routes

	router.GET("/", func(c *gin.Context) {
		c.Redirect(http.StatusMovedPermanently, "/events")
	})

	// Events
	router.GET("/new/events", events.New)
	router.GET("/events/:_id", events.Edit)
	router.GET("/events", events.List)
	router.POST("/events", events.Create)
	router.POST("/events/:_id", events.Update)
	router.POST("/delete/events/:_id", events.Delete)

	// Preferences
	router.GET("/preferences", preferences.List)
	router.POST("/preferences", preferences.Update)

	// Start listening
	port := Port
	if len(os.Getenv("PORT")) > 0 {
		port = os.Getenv("PORT")
	}
	router.Run(":" + port)
}
Esempio n. 6
0
func DebugPrint(format string, values ...interface{}) {
	if gin.IsDebugging() {
		l.Printf("[Debug] "+format, values...)
	}
}
Esempio n. 7
0
func debug(format string, values ...interface{}) {
	if gin.IsDebugging() {
		log.Printf("[APP-debug] "+format, values...)
	}
}