32 lines
606 B
Go
32 lines
606 B
Go
package storage
|
|
|
|
import (
|
|
"os"
|
|
|
|
"git.obamna.ru/erius/ozon-task/graph/model"
|
|
"git.obamna.ru/erius/ozon-task/internal/storage/db"
|
|
)
|
|
|
|
const (
|
|
inMemory = "inmemory"
|
|
postgres = "postgres"
|
|
)
|
|
|
|
var storage = os.Getenv("APP_STORAGE")
|
|
|
|
type Storage interface {
|
|
AddPost(input *model.PostInput) (*model.AddResult, error)
|
|
AddComment(input *model.CommentInput) (*model.AddResult, error)
|
|
GetPosts() ([]*model.Post, error)
|
|
}
|
|
|
|
func InitStorage() (Storage, error) {
|
|
switch storage {
|
|
case inMemory:
|
|
return InitInMemory(), nil
|
|
case postgres:
|
|
return db.InitPostgres()
|
|
default:
|
|
return InitInMemory(), nil
|
|
}
|
|
}
|