memos/bin/server/main.go

78 lines
2.1 KiB
Go
Raw Normal View History

2022-02-03 15:32:03 +08:00
package main
2022-08-24 21:53:12 +08:00
import (
"os"
_ "github.com/mattn/go-sqlite3"
2022-09-05 21:14:17 +08:00
"context"
"fmt"
"github.com/usememos/memos/server"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/store"
DB "github.com/usememos/memos/store/db"
2022-08-24 21:53:12 +08:00
)
2022-02-03 15:32:03 +08:00
2022-09-05 21:14:17 +08:00
const (
greetingBanner = `
`
)
func run(profile *profile.Profile) error {
ctx := context.Background()
db := DB.NewDB(profile)
if err := db.Open(ctx); err != nil {
return fmt.Errorf("cannot open db: %w", err)
}
2022-10-29 11:15:39 +08:00
serverInstance := server.NewServer(profile)
2022-09-05 21:14:17 +08:00
storeInstance := store.New(db.Db, profile)
2022-10-29 11:15:39 +08:00
serverInstance.Store = storeInstance
metricCollector := server.NewMetricCollector(profile, storeInstance)
// Disable metrics collector.
metricCollector.Enabled = false
2022-10-29 11:15:39 +08:00
serverInstance.Collector = &metricCollector
2022-09-05 21:14:17 +08:00
println(greetingBanner)
fmt.Printf("Version %s has started at :%d\n", profile.Version, profile.Port)
2023-01-02 23:18:12 +08:00
return serverInstance.Run(ctx)
2022-09-05 21:14:17 +08:00
}
func execute() error {
profile, err := profile.GetProfile()
if err != nil {
return err
}
println("---")
println("profile")
println("mode:", profile.Mode)
println("port:", profile.Port)
println("dsn:", profile.DSN)
println("version:", profile.Version)
println("---")
if err := run(profile); err != nil {
fmt.Printf("error: %+v\n", err)
return err
}
return nil
}
2022-02-03 15:32:03 +08:00
func main() {
2022-09-05 21:14:17 +08:00
if err := execute(); err != nil {
2022-08-24 21:53:12 +08:00
os.Exit(1)
}
2022-02-03 15:32:03 +08:00
}