newBaseCtx creates a minimal context with paths and database connection. This base context is used for file and database initialization before being enriched with config values by setupCtx.
(versionTag, customDBPath string)
| 78 | // This base context is used for file and database initialization before |
| 79 | // being enriched with config values by setupCtx. |
| 80 | func newBaseCtx(versionTag, customDBPath string) (context.DnoteCtx, error) { |
| 81 | dnoteDir := getLegacyDnotePath(dirs.Home) |
| 82 | paths := context.Paths{ |
| 83 | Home: dirs.Home, |
| 84 | Config: dirs.ConfigHome, |
| 85 | Data: dirs.DataHome, |
| 86 | Cache: dirs.CacheHome, |
| 87 | LegacyDnote: dnoteDir, |
| 88 | } |
| 89 | |
| 90 | dbPath := getDBPath(paths, customDBPath) |
| 91 | |
| 92 | db, err := database.Open(dbPath) |
| 93 | if err != nil { |
| 94 | return context.DnoteCtx{}, errors.Wrap(err, "conntecting to db") |
| 95 | } |
| 96 | |
| 97 | ctx := context.DnoteCtx{ |
| 98 | Paths: paths, |
| 99 | Version: versionTag, |
| 100 | DB: db, |
| 101 | } |
| 102 | |
| 103 | return ctx, nil |
| 104 | } |
| 105 | |
| 106 | // Init initializes the Dnote environment and returns a new dnote context |
| 107 | // apiEndpoint is used when creating a new config file (e.g., from ldflags during tests) |
no test coverage detected