MCPcopy
hub / github.com/dnote/dnote / Init

Function Init

pkg/cli/infra/init.go:108–140  ·  view source on GitHub ↗

Init initializes the Dnote environment and returns a new dnote context apiEndpoint is used when creating a new config file (e.g., from ldflags during tests)

(versionTag, apiEndpoint, dbPath string)

Source from the content-addressed store, hash-verified

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)
108func Init(versionTag, apiEndpoint, dbPath string) (*context.DnoteCtx, error) {
109 ctx, err := newBaseCtx(versionTag, dbPath)
110 if err != nil {
111 return nil, errors.Wrap(err, "initializing a context")
112 }
113
114 if err := initFiles(ctx, apiEndpoint); err != nil {
115 return nil, errors.Wrap(err, "initializing files")
116 }
117
118 if err := InitDB(ctx); err != nil {
119 return nil, errors.Wrap(err, "initializing database")
120 }
121 if err := InitSystem(ctx); err != nil {
122 return nil, errors.Wrap(err, "initializing system data")
123 }
124
125 if err := migrate.Legacy(ctx); err != nil {
126 return nil, errors.Wrap(err, "running legacy migration")
127 }
128 if err := migrate.Run(ctx, migrate.LocalSequence, migrate.LocalMode); err != nil {
129 return nil, errors.Wrap(err, "running migration")
130 }
131
132 ctx, err = setupCtx(ctx)
133 if err != nil {
134 return nil, errors.Wrap(err, "setting up the context")
135 }
136
137 log.Debug("context: %+v\n", context.Redact(ctx))
138
139 return &ctx, nil
140}
141
142// setupCtx enriches the base context with values from config file and database.
143// This is called after files and database have been initialized.

Callers 2

mainFunction · 0.92
TestInit_APIEndpointFunction · 0.85

Calls 9

LegacyFunction · 0.92
RunFunction · 0.92
DebugFunction · 0.92
RedactFunction · 0.92
newBaseCtxFunction · 0.85
initFilesFunction · 0.85
InitSystemFunction · 0.85
setupCtxFunction · 0.85
InitDBFunction · 0.70

Tested by 1

TestInit_APIEndpointFunction · 0.68