mirror of
https://github.com/usememos/memos.git
synced 2025-03-06 10:34:01 +08:00
chore: fix env init
This commit is contained in:
parent
8fd5365ac1
commit
7564c40c8d
3 changed files with 32 additions and 44 deletions
|
@ -31,12 +31,25 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
instanceProfile *profile.Profile
|
||||
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "memos",
|
||||
Short: `An open source, lightweight note-taking service. Easily capture and share your great thoughts.`,
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
instanceProfile := &profile.Profile{
|
||||
Mode: viper.GetString("mode"),
|
||||
Addr: viper.GetString("addr"),
|
||||
Port: viper.GetInt("port"),
|
||||
Data: viper.GetString("data"),
|
||||
Driver: viper.GetString("driver"),
|
||||
DSN: viper.GetString("dsn"),
|
||||
Public: viper.GetBool("public"),
|
||||
PasswordAuth: viper.GetBool("password-auth"),
|
||||
Version: version.GetCurrentVersion(viper.GetString("mode")),
|
||||
}
|
||||
if err := instanceProfile.Validate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
dbDriver, err := db.NewDBDriver(instanceProfile)
|
||||
if err != nil {
|
||||
|
@ -77,7 +90,7 @@ var (
|
|||
}
|
||||
}
|
||||
|
||||
printGreetings()
|
||||
printGreetings(instanceProfile)
|
||||
|
||||
go func() {
|
||||
<-c
|
||||
|
@ -91,11 +104,14 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func init() {
|
||||
viper.SetDefault("mode", "demo")
|
||||
viper.SetDefault("driver", "sqlite")
|
||||
viper.SetDefault("addr", "")
|
||||
viper.SetDefault("port", 8081)
|
||||
viper.SetDefault("public", false)
|
||||
viper.SetDefault("password-auth", true)
|
||||
|
||||
rootCmd.PersistentFlags().String("mode", "demo", `mode of server, can be "prod" or "dev" or "demo"`)
|
||||
rootCmd.PersistentFlags().String("addr", "", "address of server")
|
||||
rootCmd.PersistentFlags().Int("port", 8081, "port of server")
|
||||
|
@ -143,29 +159,9 @@ func init() {
|
|||
if err := viper.BindEnv("password-auth", "MEMOS_PASSWORD_AUTH"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
viper.SetDefault("mode", "demo")
|
||||
viper.SetDefault("driver", "sqlite")
|
||||
viper.SetDefault("addr", "")
|
||||
viper.SetDefault("port", 8081)
|
||||
viper.SetDefault("public", false)
|
||||
viper.SetDefault("password-auth", true)
|
||||
|
||||
instanceProfile = &profile.Profile{
|
||||
Mode: viper.GetString("mode"),
|
||||
Addr: viper.GetString("addr"),
|
||||
Port: viper.GetInt("port"),
|
||||
Data: viper.GetString("data"),
|
||||
Driver: viper.GetString("driver"),
|
||||
DSN: viper.GetString("dsn"),
|
||||
Public: viper.GetBool("public"),
|
||||
PasswordAuth: viper.GetBool("password-auth"),
|
||||
Version: version.GetCurrentVersion(viper.GetString("mode")),
|
||||
}
|
||||
if err := instanceProfile.Validate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
func printGreetings(profile *profile.Profile) {
|
||||
fmt.Printf(`---
|
||||
Server profile
|
||||
version: %s
|
||||
|
@ -178,15 +174,13 @@ public: %t
|
|||
password-auth: %t
|
||||
driver: %s
|
||||
---
|
||||
`, instanceProfile.Version, instanceProfile.Data, instanceProfile.DSN, instanceProfile.Addr, instanceProfile.Port, instanceProfile.Mode, instanceProfile.Public, instanceProfile.PasswordAuth, instanceProfile.Driver)
|
||||
}
|
||||
`, profile.Version, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Public, profile.PasswordAuth, profile.Driver)
|
||||
|
||||
func printGreetings() {
|
||||
print(greetingBanner)
|
||||
if len(instanceProfile.Addr) == 0 {
|
||||
fmt.Printf("Version %s has been started on port %d\n", instanceProfile.Version, instanceProfile.Port)
|
||||
if len(profile.Addr) == 0 {
|
||||
fmt.Printf("Version %s has been started on port %d\n", profile.Version, profile.Port)
|
||||
} else {
|
||||
fmt.Printf("Version %s has been started on address '%s' and port %d\n", instanceProfile.Version, instanceProfile.Addr, instanceProfile.Port)
|
||||
fmt.Printf("Version %s has been started on address '%s' and port %d\n", profile.Version, profile.Addr, profile.Port)
|
||||
}
|
||||
fmt.Printf(`---
|
||||
See more in:
|
||||
|
@ -197,8 +191,7 @@ See more in:
|
|||
}
|
||||
|
||||
func main() {
|
||||
err := Execute()
|
||||
if err != nil {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ root = "."
|
|||
tmp_dir = ".air"
|
||||
|
||||
[build]
|
||||
bin = "./.air/memos --mode dev"
|
||||
bin = "./.air/memos --mode dev --public true"
|
||||
cmd = "go build -o ./.air/memos ./bin/memos/main.go"
|
||||
delay = 1000
|
||||
exclude_dir = [".air", "web", "build"]
|
||||
|
|
|
@ -772,11 +772,6 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
|
|||
displayTs = memo.UpdatedTs
|
||||
}
|
||||
|
||||
creator, err := s.Store.GetUser(ctx, &store.FindUser{ID: &memo.CreatorID})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get creator")
|
||||
}
|
||||
|
||||
name := fmt.Sprintf("%s%d", MemoNamePrefix, memo.ID)
|
||||
listMemoRelationsResponse, err := s.ListMemoRelations(ctx, &v1pb.ListMemoRelationsRequest{Name: name})
|
||||
if err != nil {
|
||||
|
@ -807,7 +802,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
|
|||
Name: name,
|
||||
Uid: memo.UID,
|
||||
RowStatus: convertRowStatusFromStore(memo.RowStatus),
|
||||
Creator: fmt.Sprintf("%s%d", UserNamePrefix, creator.ID),
|
||||
Creator: fmt.Sprintf("%s%d", UserNamePrefix, memo.CreatorID),
|
||||
CreateTime: timestamppb.New(time.Unix(memo.CreatedTs, 0)),
|
||||
UpdateTime: timestamppb.New(time.Unix(memo.UpdatedTs, 0)),
|
||||
DisplayTime: timestamppb.New(time.Unix(displayTs, 0)),
|
||||
|
|
Loading…
Reference in a new issue