MCPcopy Index your code
hub / github.com/dnote/dnote / newBaseCtx

Function newBaseCtx

pkg/cli/infra/init.go:80–104  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

78// This base context is used for file and database initialization before
79// being enriched with config values by setupCtx.
80func 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)

Callers 1

InitFunction · 0.85

Calls 3

OpenFunction · 0.92
getLegacyDnotePathFunction · 0.85
getDBPathFunction · 0.85

Tested by

no test coverage detected