memos/bin/server/cmd/root.go

46 lines
599 B
Go
Raw Normal View History

2022-02-03 15:32:03 +08:00
package cmd
import (
"fmt"
"os"
2022-03-29 20:53:43 +08:00
"memos/common"
2022-02-03 15:32:03 +08:00
"memos/server"
"memos/store"
)
type Main struct {
2022-03-29 20:53:43 +08:00
profile *common.Profile
2022-02-03 15:32:03 +08:00
}
func (m *Main) Run() error {
2022-03-29 20:53:43 +08:00
db := store.NewDB(m.profile)
2022-02-03 15:32:03 +08:00
if err := db.Open(); err != nil {
return fmt.Errorf("cannot open db: %w", err)
}
2022-03-29 20:53:43 +08:00
s := server.NewServer(m.profile)
2022-02-03 15:32:03 +08:00
2022-05-16 07:37:23 +08:00
storeInstance := store.New(db)
s.Store = storeInstance
2022-02-03 15:32:03 +08:00
if err := s.Run(); err != nil {
return err
}
return nil
}
2022-03-29 20:53:43 +08:00
func Execute() {
profile := common.GetProfile()
m := Main{
2022-05-17 21:21:13 +08:00
profile: profile,
2022-03-29 20:53:43 +08:00
}
err := m.Run()
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
}