memos/bin/server/cmd/root.go

64 lines
1.7 KiB
Go
Raw Normal View History

2022-02-03 10:32:03 +03:00
package cmd
import (
"fmt"
"os"
2022-06-27 17:09:06 +03:00
"github.com/usememos/memos/server"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/store"
DB "github.com/usememos/memos/store/db"
2022-02-03 10:32:03 +03:00
)
2022-05-20 17:48:36 +03:00
const (
greetingBanner = `
`
)
2022-02-03 10:32:03 +03:00
type Main struct {
2022-05-22 04:29:34 +03:00
profile *profile.Profile
2022-02-03 10:32:03 +03:00
}
func (m *Main) Run() error {
2022-05-21 19:59:22 +03:00
db := DB.NewDB(m.profile)
2022-02-03 10:32:03 +03:00
if err := db.Open(); err != nil {
return fmt.Errorf("cannot open db: %w", err)
}
2022-03-29 15:53:43 +03:00
s := server.NewServer(m.profile)
2022-02-03 10:32:03 +03:00
2022-05-21 19:59:22 +03:00
storeInstance := store.New(db.Db, m.profile)
2022-05-16 02:37:23 +03:00
s.Store = storeInstance
2022-02-03 10:32:03 +03:00
println(greetingBanner)
fmt.Printf("Version %s has started at :%d\n", m.profile.Version, m.profile.Port)
2022-02-03 10:32:03 +03:00
return s.Run()
2022-02-03 10:32:03 +03:00
}
2022-03-29 15:53:43 +03:00
func Execute() {
2022-05-22 04:29:34 +03:00
profile := profile.GetProfile()
2022-03-29 15:53:43 +03:00
m := Main{
2022-05-17 16:21:13 +03:00
profile: profile,
2022-03-29 15:53:43 +03:00
}
2022-07-09 07:57:08 +03:00
println("---")
println("profile")
println("mode:", profile.Mode)
println("port:", profile.Port)
println("dsn:", profile.DSN)
println("version:", profile.Version)
println("---")
2022-05-20 17:48:36 +03:00
if err := m.Run(); err != nil {
fmt.Printf("error: %+v\n", err)
2022-03-29 15:53:43 +03:00
os.Exit(1)
}
}