Adds MongoDB-backed submission for survey statistics/metrics and introduces MongoDB ObjectID-based participant/task identifiers to support upserts and linking metrics to a participant. It introduces breaking changes to the exsisting json stat and metric files. Delete the old ones Changes: Add internal/storage/MongoStorage and wire pm survey submit / pm start to submit local .pm/*.json files to MongoDB. Extend stats/metrics models to include MongoDB _id / participant_id fields and add participant ID propagation into task metrics. Update app initialization to generate ObjectIDs for new participants and expose GetParticipantID() via StatsService.
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package models
|
|
|
|
import "os"
|
|
|
|
type Config struct {
|
|
DbUri string
|
|
AutoInit bool
|
|
RootCmd string
|
|
AppDir string
|
|
WebAddress string
|
|
IssuePrefix string
|
|
ActionLogger func(string)
|
|
StatisticsStoragePath string
|
|
}
|
|
|
|
var BaseConfig = Config{
|
|
DbUri: "",
|
|
AutoInit: false,
|
|
RootCmd: "pm",
|
|
IssuePrefix: "pm",
|
|
WebAddress: ":8080",
|
|
AppDir: "./.pm/",
|
|
StatisticsStoragePath: "./.pm/stats.json",
|
|
}
|
|
|
|
func (c Config) LoadFromEnv() Config {
|
|
if dbURI, ok := os.LookupEnv("DB_URI"); ok {
|
|
c.DbUri = dbURI
|
|
}
|
|
return c
|
|
}
|
|
|
|
func (c Config) WithDbUri(uri string) Config {
|
|
c.DbUri = uri
|
|
return c
|
|
}
|
|
|
|
func (c Config) WithAutoInit(autoInit bool) Config {
|
|
c.AutoInit = autoInit
|
|
return c
|
|
}
|
|
|
|
func (c Config) WithRootCmd(rootCmd string) Config {
|
|
c.RootCmd = rootCmd
|
|
return c
|
|
}
|
|
|
|
func (c Config) WithWebAddress(webAddress string) Config {
|
|
c.WebAddress = webAddress
|
|
return c
|
|
}
|
|
|
|
func (c Config) WithIssuePrefix(issuePrefix string) Config {
|
|
c.IssuePrefix = issuePrefix
|
|
return c
|
|
}
|
|
|
|
func (c Config) WithStatisticsStoragePath(path string) Config {
|
|
c.StatisticsStoragePath = path
|
|
return c
|
|
}
|
|
|
|
func (c Config) WithActionLogger(logger func(string)) Config {
|
|
c.ActionLogger = logger
|
|
return c
|
|
}
|