Browse Source
Rename FileSystem in settings to StorageProvider
feature/add-settings
Fabian Vowie
3 years ago
No known key found for this signature in database
GPG Key ID: C27317C33B27C410
3 changed files with
12 additions and
12 deletions
-
main.go
-
settings/settings.go
-
settings/settings_test.go
|
|
@ -47,8 +47,8 @@ func main() { |
|
|
|
|
|
|
|
var storageProvider storage.IStorageProvider |
|
|
|
|
|
|
|
if settings.FileSystem.Type == 0 { |
|
|
|
storageProvider = storage.GetFileSystemStorageProvider(settings.FileSystem.BasePath) |
|
|
|
if settings.StorageProvider.Type == 0 { |
|
|
|
storageProvider = storage.GetFileSystemStorageProvider(settings.StorageProvider.BasePath) |
|
|
|
} else { |
|
|
|
panic("Invalid file system provided!") |
|
|
|
} |
|
|
|
|
|
@ -13,17 +13,17 @@ const ( |
|
|
|
type FileSystemType int |
|
|
|
|
|
|
|
type Settings struct { |
|
|
|
Endpoint string |
|
|
|
Token string |
|
|
|
FileSystem FileSystemSettings |
|
|
|
Endpoint string |
|
|
|
Token string |
|
|
|
StorageProvider StorageSettings |
|
|
|
} |
|
|
|
|
|
|
|
type FileSystemSettings struct { |
|
|
|
type StorageSettings struct { |
|
|
|
Type FileSystemType |
|
|
|
BasePath string |
|
|
|
} |
|
|
|
|
|
|
|
func ParseSettings(data []byte) Settings { |
|
|
|
func parseSettings(data []byte) Settings { |
|
|
|
settings := Settings{} |
|
|
|
|
|
|
|
json.Unmarshal(data, &settings) |
|
|
@ -39,14 +39,14 @@ func LoadSettings() Settings { |
|
|
|
data, err := os.ReadFile(path) |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
return ParseSettings(data) |
|
|
|
return parseSettings(data) |
|
|
|
} |
|
|
|
|
|
|
|
// If file does not exist, create default settings
|
|
|
|
defaultSettings := Settings{ |
|
|
|
Endpoint: "127.0.0.1:8000", |
|
|
|
Token: "changeme", |
|
|
|
FileSystem: FileSystemSettings{ |
|
|
|
StorageProvider: StorageSettings{ |
|
|
|
Type: Local, |
|
|
|
BasePath: "assets", |
|
|
|
}, |
|
|
|
|
|
@ -10,17 +10,17 @@ func TestSettingsLoading(t *testing.T) { |
|
|
|
const file string = `{ |
|
|
|
"endpoint": "0.0.0.0:8000", |
|
|
|
"token": "foobar", |
|
|
|
"fileSystem": { |
|
|
|
"storageProvider": { |
|
|
|
"type": 0, |
|
|
|
"basePath": "assets" |
|
|
|
} |
|
|
|
}` |
|
|
|
|
|
|
|
t.Run("Settings parsing is successful", func(t *testing.T) { |
|
|
|
settings := ParseSettings([]byte(file)) |
|
|
|
settings := parseSettings([]byte(file)) |
|
|
|
|
|
|
|
assert.Equal(t, "0.0.0.0:8000", settings.Endpoint) |
|
|
|
assert.Equal(t, "foobar", settings.Token) |
|
|
|
assert.Equal(t, "assets", settings.FileSystem.BasePath) |
|
|
|
assert.Equal(t, "assets", settings.StorageProvider.BasePath) |
|
|
|
}) |
|
|
|
} |