feat: system api with profiles

This commit is contained in:
email
2022-03-29 20:53:43 +08:00
parent 4f88221bce
commit b3a431570c
9 changed files with 111 additions and 43 deletions

View File

@ -4,40 +4,28 @@ import (
"fmt"
"os"
"memos/common"
"memos/server"
"memos/store"
)
type Main struct {
profile *Profile
profile *common.Profile
server *server.Server
db *store.DB
}
func Execute() {
m := Main{}
profile := GetProfile()
m.profile = &profile
err := m.Run()
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
}
func (m *Main) Run() error {
db := store.NewDB(m.profile.dsn, m.profile.mode)
db := store.NewDB(m.profile)
if err := db.Open(); err != nil {
return fmt.Errorf("cannot open db: %w", err)
}
m.db = db
s := server.NewServer(m.profile.port, m.profile.mode)
s := server.NewServer(m.profile)
s.ShortcutService = store.NewShortcutService(db)
s.MemoService = store.NewMemoService(db)
@ -53,3 +41,16 @@ func (m *Main) Run() error {
return nil
}
func Execute() {
profile := common.GetProfile()
m := Main{
profile: &profile,
}
err := m.Run()
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
}