Пример #1
0
func setup() {
	database.Open("testing.db")

	timeStamp, _ := time.Parse(time.RFC3339Nano, "2015-11-19T12:19:33.865042825+01:00")

	items := []*model.Item{
		&model.Item{
			Code:      "url",
			Type:      model.URLItemType,
			Content:   "https://ariejan.net",
			CreatedAt: timeStamp,
		},
		&model.Item{
			Code:      "txt",
			Type:      model.TextItemType,
			Content:   "Lorem ipsum",
			CreatedAt: timeStamp,
		},
	}

	for _, item := range items {
		database.SaveItem(item)
	}

	router = gin.Default()
	web.Setup(router.Group("/"), database)
}
Пример #2
0
func main() {
	// Configure logging
	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile)

	// Setup bolt database
	db := &db.DB{}
	db.Open(dbName)
	defer db.Close()

	// Create seed data
	// TODO: Replace this with an optional CLI command to seed data.
	seedData(db)

	// Configure routers
	apiRouter := gin.Default()
	apiRouter.Use(cors.Middleware(corsConfig))
	api.Setup(apiRouter.Group("/api/v1"), db)

	adminRouter := gin.Default()
	adminRouter.Use(cors.Middleware(corsConfig))
	ember.Setup(adminRouter.Group("/"))

	contentRouter := gin.Default()
	web.Setup(contentRouter.Group("/"), db)

	// Setup subdomain routing
	hs := make(HostSwitch)
	hs[apiHost] = apiRouter
	hs[adminHost] = adminRouter
	hs[contentHost] = contentRouter

	// Start HTTP server
	log.Print(">> Server up and running")
	log.Printf(">> Content server - http://%s", contentHost)
	log.Printf(">> API server     - http://%s", apiHost)
	log.Printf(">> Admin server   - http://%s", adminHost)
	http.ListenAndServe(portString, hs)
}