예제 #1
0
파일: servers.go 프로젝트: syncore/a2sapi
// OpenServerDB Opens a database connection to the server database file or if
// that file does not exists, creates it and then opens a database connection to it.
func OpenServerDB() (*SDB, error) {
	if err := verifyServerDbPath(); err != nil {
		// will panic if not verified
		return nil, logger.LogAppError(err)
	}
	conn, err := sql.Open("sqlite3", constants.GetServerDBPath())
	if err != nil {
		return nil, logger.LogAppError(err)
	}
	return &SDB{db: conn}, nil
}
예제 #2
0
파일: database.go 프로젝트: syncore/a2sapi
func verifyServerDbPath() error {
	if err := util.CreateDirectory(constants.DbDirectory); err != nil {
		logger.LogAppError(err)
		panic(fmt.Sprintf("Unable to create database directory %s: %s",
			constants.DbDirectory, err))
	}
	if err := createServerDBtable(constants.GetServerDBPath()); err != nil {
		logger.LogAppErrorf("Unable to verify database path: %s", err)
		panic("Unable to verify database path")
	}

	return nil
}