示例#1
0
func New(name, dirPath string) (HistoryStorage, error) {
	switch name {
	case "naive":
		return naive.New(dirPath), nil
	case "mongodb":
		return mongodb.New(dirPath), nil
	}
	return nil, fmt.Errorf("unknown history storage: %s", name)
}
示例#2
0
func New(dirPath string) *MongoDB {
	session, err := mgo.Dial(dialTo)
	if err != nil {
		panic(err)
	}
	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	db := session.DB(dbName)

	return &MongoDB{
		Naive:   naive.New(dirPath),
		dirPath: dirPath,
		Session: session,
		DB:      db,
	}
}
示例#3
0
func LoadStorage(dirPath string) HistoryStorage {
	confPath := dirPath + "/" + StorageTOMLConfigPath

	// TODO: we should not parse config twice. (run should have already parsed the config)
	cfg, err := config.NewFromFile(confPath)
	if err != nil {
		fmt.Printf("error: %s\n", err)
		return nil
	}
	storageType := cfg.Get("storageType")

	switch storageType {
	case "naive":
		return naive.New(dirPath)
	default:
		fmt.Printf("unknown history storage: %s\n", storageType)
		return nil
	}
	// NOTREACHED
}