-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_drive_config.go
73 lines (60 loc) · 1.89 KB
/
google_drive_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package fundrive
import (
"fmt"
"gorm.io/gorm"
)
// Common errors
var (
ErrDBEmpty = fmt.Errorf("error creating google drive service: db is empty")
ErrInvalidConfig = fmt.Errorf("invalid configuration provided")
ErrServiceAccountEmpty = fmt.Errorf("service account file path is empty")
)
// GoogleDriveServiceConfig represents the configuration for the Google Drive service
type GoogleDriveServiceConfig struct {
ServiceAccountFilePath string
EncryptionKey string
DB *gorm.DB
UseBaseFolder bool
}
// GoogleDriveServiceConfigOption defines the function signature for optional configuration
type GoogleDriveServiceConfigOption func(*GoogleDriveServiceConfig)
// DefaultGoogleDriveServiceConfig returns a Config with default values
func DefaultGoogleDriveServiceConfig() *GoogleDriveServiceConfig {
return &GoogleDriveServiceConfig{}
}
// WithServiceAccountFilePath sets the service account file path
func WithServiceAccountFilePath(path string) GoogleDriveServiceConfigOption {
return func(c *GoogleDriveServiceConfig) {
c.ServiceAccountFilePath = path
}
}
// WithDB sets the database connection
func WithDB(db *gorm.DB) GoogleDriveServiceConfigOption {
return func(c *GoogleDriveServiceConfig) {
c.DB = db
}
}
// WithEncryptionKey sets the encryption key
func WithEncryptionKey(key string) GoogleDriveServiceConfigOption {
return func(c *GoogleDriveServiceConfig) {
c.EncryptionKey = key
}
}
func WithUseBaseFolder(useBaseFolder bool) GoogleDriveServiceConfigOption {
return func(c *GoogleDriveServiceConfig) {
c.UseBaseFolder = useBaseFolder
}
}
// validate checks if the configuration is valid
func (c *GoogleDriveServiceConfig) validate() error {
if c.DB == nil {
return ErrDBEmpty
}
if c.ServiceAccountFilePath == "" {
return ErrServiceAccountEmpty
}
if c.EncryptionKey == "" {
return ErrServiceAccountEmpty
}
return nil
}