diff --git a/datastore.go b/datastore.go index e3ba917..ba1e0c8 100644 --- a/datastore.go +++ b/datastore.go @@ -2,7 +2,7 @@ package gismanager import "fmt" -type datastore struct { +type DatastoreConfig struct { Host string `yaml:"host"` Port uint `yaml:"port"` DBName string `yaml:"database"` @@ -12,11 +12,11 @@ type datastore struct { } //BuildConnectionString return gdal postgres connection as string -func (ds *datastore) BuildConnectionString() string { +func (ds *DatastoreConfig) BuildConnectionString() string { return fmt.Sprintf("PG: host=%s port=%d dbname=%s user=%s password=%s", ds.Host, ds.Port, ds.DBName, ds.DBUser, ds.DBPass) } //PostgresConnectionString return postgres connection as string -func (ds *datastore) PostgresConnectionString() string { +func (ds *DatastoreConfig) PostgresConnectionString() string { return fmt.Sprintf("postgresql://%s:%s@%s:%d/%s?sslmode=disable", ds.DBUser, ds.DBPass, ds.Host, ds.Port, ds.DBName) } diff --git a/datastore_test.go b/datastore_test.go index 5fec03a..3b6e290 100644 --- a/datastore_test.go +++ b/datastore_test.go @@ -7,7 +7,7 @@ import ( ) func TestBuildConnectionString(t *testing.T) { - ds := datastore{ + ds := DatastoreConfig{ Host: "localhost", Port: 5432, DBName: "gis", diff --git a/manager.go b/manager.go index b24ad75..c256084 100644 --- a/manager.go +++ b/manager.go @@ -10,22 +10,24 @@ import ( "github.com/sirupsen/logrus" ) -type geoserver struct { +//GeoserverConfig geoserver configuration +type GeoserverConfig struct { WorkspaceName string `yaml:"workspace"` ServerURL string `yaml:"url"` Username string `yaml:"username"` Password string `yaml:"password"` } -type source struct { +//SourceConfig Data Source/Dir configuration +type SourceConfig struct { Path string `yaml:"path"` } //ManagerConfig is the configuration Object type ManagerConfig struct { - Geoserver geoserver `yaml:"geoserver"` - Datastore datastore `yaml:"datastore"` - Source source `yaml:"source"` + Geoserver GeoserverConfig `yaml:"geoserver"` + Datastore DatastoreConfig `yaml:"datastore"` + Source SourceConfig `yaml:"source"` logger *logrus.Logger } diff --git a/manager_test.go b/manager_test.go index c7fb064..c72f360 100644 --- a/manager_test.go +++ b/manager_test.go @@ -12,9 +12,9 @@ func TestFromConfig(t *testing.T) { assert.Nil(t, confErr) assert.NotNil(t, manager) expected := ManagerConfig{ - Geoserver: geoserver{WorkspaceName: "golang", Username: "admin", Password: "geoserver", ServerURL: "http://localhost:8080/geoserver"}, - Datastore: datastore{Host: "localhost", Port: 5432, DBName: "gis", DBUser: "golang", DBPass: "golang", Name: "gismanager_data"}, - Source: source{Path: "./testdata"}, + Geoserver: GeoserverConfig{WorkspaceName: "golang", Username: "admin", Password: "geoserver", ServerURL: "http://localhost:8080/geoserver"}, + Datastore: DatastoreConfig{Host: "localhost", Port: 5432, DBName: "gis", DBUser: "golang", DBPass: "golang", Name: "gismanager_data"}, + Source: SourceConfig{Path: "./testdata"}, logger: manager.logger, } assert.Equal(t, expected.Geoserver, manager.Geoserver)