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