2017-08-03 08:13:53 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-10-23 08:05:20 -04:00
|
|
|
"github.com/Luzifer/ots/pkg/storage"
|
|
|
|
"github.com/Luzifer/ots/pkg/storage/memory"
|
|
|
|
"github.com/Luzifer/ots/pkg/storage/redis"
|
|
|
|
)
|
2017-08-03 08:13:53 -04:00
|
|
|
|
2023-10-23 08:05:20 -04:00
|
|
|
func getStorageByType(t string) (storage.Storage, error) {
|
2017-08-03 08:13:53 -04:00
|
|
|
switch t {
|
|
|
|
case "mem":
|
2023-10-23 08:05:20 -04:00
|
|
|
return memory.New(), nil
|
|
|
|
|
2017-08-03 08:13:53 -04:00
|
|
|
case "redis":
|
2023-10-23 08:05:20 -04:00
|
|
|
s, err := redis.New()
|
|
|
|
if err != nil {
|
|
|
|
return s, fmt.Errorf("creating redis storage: %w", err)
|
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
|
2017-08-03 08:13:53 -04:00
|
|
|
default:
|
2023-10-04 16:53:29 -04:00
|
|
|
return nil, fmt.Errorf("storage type %q not found", t)
|
2017-08-03 08:13:53 -04:00
|
|
|
}
|
|
|
|
}
|