2022-02-03 15:32:03 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-08-07 10:17:56 +08:00
|
|
|
"context"
|
2022-02-03 15:32:03 +08:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
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 {
|
2022-08-07 10:17:56 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2022-08-19 00:45:02 +08:00
|
|
|
db := DB.NewDB(profile)
|
2022-08-07 10:17:56 +08:00
|
|
|
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
|
|
|
|
2022-07-09 13:34:14 +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
|
|
|
|
2022-07-09 13:34:14 +08:00
|
|
|
return s.Run()
|
2022-02-03 15:32:03 +08:00
|
|
|
}
|
2022-03-29 20:53:43 +08:00
|
|
|
|
|
|
|
func Execute() {
|
2022-05-22 09:29:34 +08:00
|
|
|
profile := profile.GetProfile()
|
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-03-29 20:53:43 +08:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|