Config: Refactor options and flags source files #2195

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2022-04-08 14:22:07 +02:00
parent 67fdecfbef
commit 30da260a11
7 changed files with 24 additions and 26 deletions

2
go.mod
View file

@ -55,7 +55,7 @@ require (
github.com/urfave/cli v1.22.5
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
gonum.org/v1/gonum v0.11.0
google.golang.org/protobuf v1.28.0 // indirect

4
go.sum
View file

@ -398,8 +398,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b h1:vI32FkLJNAWtGD4BwkThwEy6XS7ZLLMHkSkYfF8M0W0=
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 h1:EN5+DfgmRMvRUrMGERW2gQl3Vc+Z7ZMnI/xdEpPSf0c=
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

View file

@ -7,35 +7,16 @@ import (
"reflect"
"time"
"github.com/photoprism/photoprism/pkg/txt"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
"github.com/photoprism/photoprism/pkg/fs"
"github.com/photoprism/photoprism/pkg/txt"
)
// SQL Databases.
const (
MySQL = "mysql"
MariaDB = "mariadb"
Postgres = "postgres" // TODO: Requires GORM 2.0 for generic column data types
SQLite3 = "sqlite3"
SQLiteTestDB = ".test.db"
SQLiteMemoryDSN = ":memory:"
)
// Options provides a struct in which application configuration is stored.
// Application code must use functions to get config options, for two reasons:
//
// 1. We do not want to leak implementation details so refactoring overhead is kept low
// 2. Some config values are dynamically generated
// 3. Paths may become dynamic too at a later time
//
// See https://github.com/photoprism/photoprism/issues/50#issuecomment-433856358
// Options hold the global configuration values without further validation or processing.
// Application code should retrieve option values via getter functions since they provide
// validation and return defaults if a value is empty.
type Options struct {
Name string `json:"-"`
Version string `json:"-"`

View file

@ -14,10 +14,27 @@ import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/mutex"
)
// SQL Databases.
// TODO: PostgresSQL support requires upgrading GORM, so generic column data types can be used.
const (
MySQL = "mysql"
MariaDB = "mariadb"
Postgres = "postgres"
SQLite3 = "sqlite3"
)
// SQLite default DSNs.
const (
SQLiteTestDB = ".test.db"
SQLiteMemoryDSN = ":memory:"
)
// dsnPattern is a regular expression matching a database DSN string.
var dsnPattern = regexp.MustCompile(
`^(?:(?P<user>.*?)(?::(?P<password>.*))?@)?` +
`(?:(?P<net>[^\(]*)(?:\((?P<server>[^\)]*)\))?)?` +