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

Function startCmd

pkg/server/cmd/start.go:32–94  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

30)
31
32func startCmd(args []string) {
33 fs := setupFlagSet("start", "dnote-server start")
34
35 port := fs.String("port", "", "Server port (env: PORT, default: 3001)")
36 baseURL := fs.String("baseUrl", "", "Full URL to server without trailing slash (env: BaseURL, default: http://localhost:3001)")
37 dbPath := fs.String("dbPath", "", "Path to SQLite database file (env: DBPath, default: $XDG_DATA_HOME/dnote/server.db)")
38 disableRegistration := fs.Bool("disableRegistration", false, "Disable user registration (env: DisableRegistration, default: false)")
39 logLevel := fs.String("logLevel", "", "Log level: debug, info, warn, or error (env: LOG_LEVEL, default: info)")
40
41 fs.Parse(args)
42
43 cfg, err := config.New(config.Params{
44 Port: *port,
45 BaseURL: *baseURL,
46 DBPath: *dbPath,
47 DisableRegistration: *disableRegistration,
48 LogLevel: *logLevel,
49 })
50 if err != nil {
51 fmt.Printf("Error: %s\n\n", err)
52 fs.Usage()
53 os.Exit(1)
54 }
55
56 // Set log level
57 log.SetLevel(cfg.LogLevel)
58
59 app := initApp(cfg)
60 defer func() {
61 sqlDB, err := app.DB.DB()
62 if err == nil {
63 sqlDB.Close()
64 }
65 }()
66
67 // Start WAL checkpointing to prevent WAL file from growing unbounded.
68 database.StartWALCheckpointing(app.DB, 5*time.Minute)
69
70 // Start periodic VACUUM to reclaim space and defragment database.
71 database.StartPeriodicVacuum(app.DB, 24*time.Hour)
72
73 ctl := controllers.New(&app)
74 rc := controllers.RouteConfig{
75 WebRoutes: controllers.NewWebRoutes(&app, ctl),
76 APIRoutes: controllers.NewAPIRoutes(&app, ctl),
77 Controllers: ctl,
78 }
79
80 r, err := controllers.NewRouter(&app, rc)
81 if err != nil {
82 panic(errors.Wrap(err, "initializing router"))
83 }
84
85 log.WithFields(log.Fields{
86 "version": buildinfo.Version,
87 "port": cfg.Port,
88 }).Info("Dnote server starting")
89

Callers 1

ExecuteFunction · 0.85

Calls 14

NewFunction · 0.92
SetLevelFunction · 0.92
StartWALCheckpointingFunction · 0.92
StartPeriodicVacuumFunction · 0.92
NewFunction · 0.92
NewWebRoutesFunction · 0.92
NewAPIRoutesFunction · 0.92
NewRouterFunction · 0.92
WithFieldsFunction · 0.92
ErrorWrapFunction · 0.92
setupFlagSetFunction · 0.85
initAppFunction · 0.85

Tested by

no test coverage detected