Browse Source

Rename FileSystem in settings to StorageProvider

feature/update-route-registration
Fabian Vowie 3 years ago
parent
commit
d87ae291e4
No known key found for this signature in database GPG Key ID: C27317C33B27C410
  1. 4
      main.go
  2. 10
      settings/settings.go
  3. 6
      settings/settings_test.go

4
main.go

@ -47,8 +47,8 @@ func main() {
var storageProvider storage.IStorageProvider 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 { } else {
panic("Invalid file system provided!") panic("Invalid file system provided!")
} }

10
settings/settings.go

@ -15,15 +15,15 @@ type FileSystemType int
type Settings struct { type Settings struct {
Endpoint string Endpoint string
Token string Token string
FileSystem FileSystemSettings
StorageProvider StorageSettings
} }
type FileSystemSettings struct {
type StorageSettings struct {
Type FileSystemType Type FileSystemType
BasePath string BasePath string
} }
func ParseSettings(data []byte) Settings {
func parseSettings(data []byte) Settings {
settings := Settings{} settings := Settings{}
json.Unmarshal(data, &settings) json.Unmarshal(data, &settings)
@ -39,14 +39,14 @@ func LoadSettings() Settings {
data, err := os.ReadFile(path) data, err := os.ReadFile(path)
if err == nil { if err == nil {
return ParseSettings(data)
return parseSettings(data)
} }
// If file does not exist, create default settings // If file does not exist, create default settings
defaultSettings := Settings{ defaultSettings := Settings{
Endpoint: "127.0.0.1:8000", Endpoint: "127.0.0.1:8000",
Token: "changeme", Token: "changeme",
FileSystem: FileSystemSettings{
StorageProvider: StorageSettings{
Type: Local, Type: Local,
BasePath: "assets", BasePath: "assets",
}, },

6
settings/settings_test.go

@ -10,17 +10,17 @@ func TestSettingsLoading(t *testing.T) {
const file string = `{ const file string = `{
"endpoint": "0.0.0.0:8000", "endpoint": "0.0.0.0:8000",
"token": "foobar", "token": "foobar",
"fileSystem": {
"storageProvider": {
"type": 0, "type": 0,
"basePath": "assets" "basePath": "assets"
} }
}` }`
t.Run("Settings parsing is successful", func(t *testing.T) { 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, "0.0.0.0:8000", settings.Endpoint)
assert.Equal(t, "foobar", settings.Token) assert.Equal(t, "foobar", settings.Token)
assert.Equal(t, "assets", settings.FileSystem.BasePath)
assert.Equal(t, "assets", settings.StorageProvider.BasePath)
}) })
} }
Loading…
Cancel
Save