1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/internal/storage/driver.go

32 lines
726 B
Go
Raw Normal View History

2020-08-23 01:06:29 +03:00
package storage
import (
2023-06-07 18:46:19 +03:00
"context"
"github.com/lus/pasty/internal/config"
"strings"
2021-04-15 20:26:17 +03:00
"github.com/lus/pasty/internal/paste"
2021-04-15 22:30:37 +03:00
"github.com/lus/pasty/internal/storage/postgres"
2020-08-23 01:06:29 +03:00
)
// Driver represents a storage driver
type Driver interface {
2023-06-07 18:46:19 +03:00
Initialize(ctx context.Context, cfg *config.Config) error
Close() error
ListIDs() ([]string, error)
Get(id string) (*paste.Paste, error)
Save(paste *paste.Paste) error
Delete(id string) error
2020-09-19 02:56:50 +03:00
Cleanup() (int, error)
2020-08-23 01:06:29 +03:00
}
2023-06-07 18:46:19 +03:00
// ResolveDriver returns the driver with the given name if it exists
func ResolveDriver(name string) (Driver, bool) {
switch strings.TrimSpace(strings.ToLower(name)) {
case "postgres":
2023-06-07 18:46:19 +03:00
return new(postgres.Driver), true
2020-08-26 23:12:36 +03:00
default:
2023-06-07 18:46:19 +03:00
return nil, false
2020-08-26 23:12:36 +03:00
}
}