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