Exemple #1
0
func newTable(mydb *db.DB, name string) *KvTable {
	if err := mydb.Create(name); err != nil {
		log.Println(err)
	}
	//	mydb.Scrub(name)
	myTable := mydb.Use(name)
	return &KvTable{name: name, col: myTable, tdb: mydb}
}
Exemple #2
0
func initDatabase(database *db.DB) {
	col := database.Use("Settings")
	if col == nil {
		err := database.Create("Settings")
		if err != nil {
			panic(err)
		}
	}

	col = database.Use("Scripts")
	if col == nil {
		err := database.Create("Scripts")
		if err != nil {
			panic(err)
		}
	}
}
Exemple #3
0
func NewGenericRepository(database *db.DB, coll string) GenericRepository {
	col := database.Use(coll)
	if col == nil {
		err := database.Create(coll)
		if err != nil {
			panic(err)
		}

		col = database.Use(coll)
	}

	return GenericRepository{database, coll}
}
Exemple #4
0
func main() {
	var port string
	if port = os.Getenv("VCAP_APP_PORT"); len(port) == 0 {
		port = DEFAULT_PORT
	}

	var host string
	if host = os.Getenv("VCAP_APP_HOST"); len(host) == 0 {
		host = DEFAULT_HOST
	}

	// prepare folder for DB with sample data
	dir := "./.fakedata-db"
	os.RemoveAll(dir)
	defer os.RemoveAll(dir)

	var tiedot *db.DB
	var err error

	// init sample data
	if tiedot, err = db.OpenDB(dir); err != nil {
		log.Panic(err)
	}
	defer tiedot.Close()

	// init sample data
	if err = fakedata.AddData(tiedot); err != nil {
		log.Panic(err)
	}

	// init persistence stores
	rest.SetProductStore(data.GetProductStore(tiedot))

	// Echo instance
	e := echo.New()

	// Static test web pages
	e.Static("/", "website")
	e.Index("website/index.html")

	// Customization
	e.SetDebug(true)

	// Middleware
	e.Use(mw.Logger())
	e.Use(mw.Recover())

	// Routes
	routes(e)

	s := e.Server(host + ":" + port)

	// HTTP2 is currently enabled by default in echo.New(). To override TLS handshake errors
	// you will need to override the TLSConfig for the server so it does not attempt to validate
	// the connection using TLS as required by HTTP2
	s.TLSConfig = nil

	// Start server
	log.Printf("Starting app on %+v:%+v\n", host, port)
	graceful.ListenAndServe(s, 5*time.Second)
}