Browse Source

Add settings parsing

feature/add-settings
Fabian Vowie 3 years ago
parent
commit
fdb4d59448
No known key found for this signature in database GPG Key ID: C27317C33B27C410
  1. 28
      settings/settings.go
  2. 26
      settings/settings_test.go

28
settings/settings.go

@ -0,0 +1,28 @@
package settings
import "encoding/json"
const (
Local FileSystemType = iota
)
type FileSystemType int
type Settings struct {
Endpoint string
Token string
FileSystem FileSystemSettings
}
type FileSystemSettings struct {
Type FileSystemType
BasePath string
}
func ParseSettings(data []byte) Settings {
settings := Settings{}
json.Unmarshal(data, &settings)
return settings
}

26
settings/settings_test.go

@ -0,0 +1,26 @@
package settings
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSettingsLoading(t *testing.T) {
const file string = `{
"endpoint": "0.0.0.0:8000",
"token": "foobar",
"fileSystem": {
"type": 0,
"basePath": "assets"
}
}`
t.Run("Settings parsing is successful", func(t *testing.T) {
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)
})
}
Loading…
Cancel
Save