memos/bin/server/cmd/root.go

64 lines
1.8 KiB
Go
Raw Normal View History

2022-02-03 15:32:03 +08:00
package cmd
import (
"context"
2022-02-03 15:32:03 +08:00
"fmt"
2022-06-27 22:09:06 +08: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 15:32:03 +08:00
)
2022-05-20 22:48:36 +08:00
const (
greetingBanner = `
`
)
2022-08-19 00:45:02 +08:00
func Run(profile *profile.Profile) error {
ctx := context.Background()
2022-08-19 00:45:02 +08:00
db := DB.NewDB(profile)
if err := db.Open(ctx); err != nil {
2022-02-03 15:32:03 +08:00
return fmt.Errorf("cannot open db: %w", err)
}
2022-08-19 00:45:02 +08:00
s := server.NewServer(profile)
2022-02-03 15:32:03 +08:00
2022-08-19 00:45:02 +08:00
storeInstance := store.New(db.Db, profile)
2022-05-16 07:37:23 +08:00
s.Store = storeInstance
2022-02-03 15:32:03 +08:00
println(greetingBanner)
2022-08-19 00:45:02 +08:00
fmt.Printf("Version %s has started at :%d\n", profile.Version, profile.Port)
2022-02-03 15:32:03 +08:00
return s.Run()
2022-02-03 15:32:03 +08:00
}
2022-03-29 20:53:43 +08:00
2022-08-24 21:53:12 +08:00
func Execute() error {
profile, err := profile.GetProfile()
if err != nil {
return err
}
2022-03-29 20:53:43 +08:00
2022-07-09 12:57:08 +08:00
println("---")
println("profile")
println("mode:", profile.Mode)
println("port:", profile.Port)
println("dsn:", profile.DSN)
println("version:", profile.Version)
println("---")
2022-05-20 22:48:36 +08:00
2022-08-19 00:45:02 +08:00
if err := Run(profile); err != nil {
2022-05-20 22:48:36 +08:00
fmt.Printf("error: %+v\n", err)
2022-08-24 21:53:12 +08:00
return err
2022-03-29 20:53:43 +08:00
}
2022-08-24 21:53:12 +08:00
return nil
2022-03-29 20:53:43 +08:00
}