Skip to content

Commit

Permalink
chore: add instance url to profile
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Aug 13, 2024
1 parent 9a27fdf commit c3f381c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 42 deletions.
34 changes: 16 additions & 18 deletions bin/memos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
DSN: viper.GetString("dsn"),
Public: viper.GetBool("public"),
PasswordAuth: viper.GetBool("password-auth"),
InstanceURL: viper.GetString("instance-url"),
Version: version.GetCurrentVersion(viper.GetString("mode")),
}
if err := instanceProfile.Validate(); err != nil {
Expand Down Expand Up @@ -107,9 +108,7 @@ var (
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"`)
Expand All @@ -120,37 +119,33 @@ func init() {
rootCmd.PersistentFlags().String("dsn", "", "database source name(aka. DSN)")
rootCmd.PersistentFlags().Bool("public", false, "")
rootCmd.PersistentFlags().Bool("password-auth", true, "")
rootCmd.PersistentFlags().String("instance-url", "", "the url of your memos instance")

err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode"))
if err != nil {
if err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode")); err != nil {
panic(err)
}
err = viper.BindPFlag("addr", rootCmd.PersistentFlags().Lookup("addr"))
if err != nil {
if err := viper.BindPFlag("addr", rootCmd.PersistentFlags().Lookup("addr")); err != nil {
panic(err)
}
err = viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port"))
if err != nil {
if err := viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port")); err != nil {
panic(err)
}
err = viper.BindPFlag("data", rootCmd.PersistentFlags().Lookup("data"))
if err != nil {
if err := viper.BindPFlag("data", rootCmd.PersistentFlags().Lookup("data")); err != nil {
panic(err)
}
err = viper.BindPFlag("driver", rootCmd.PersistentFlags().Lookup("driver"))
if err != nil {
if err := viper.BindPFlag("driver", rootCmd.PersistentFlags().Lookup("driver")); err != nil {
panic(err)
}
err = viper.BindPFlag("dsn", rootCmd.PersistentFlags().Lookup("dsn"))
if err != nil {
if err := viper.BindPFlag("dsn", rootCmd.PersistentFlags().Lookup("dsn")); err != nil {
panic(err)
}
err = viper.BindPFlag("public", rootCmd.PersistentFlags().Lookup("public"))
if err != nil {
if err := viper.BindPFlag("public", rootCmd.PersistentFlags().Lookup("public")); err != nil {
panic(err)
}
err = viper.BindPFlag("password-auth", rootCmd.PersistentFlags().Lookup("password-auth"))
if err != nil {
if err := viper.BindPFlag("password-auth", rootCmd.PersistentFlags().Lookup("password-auth")); err != nil {
panic(err)
}
if err := viper.BindPFlag("instance-url", rootCmd.PersistentFlags().Lookup("instance-url")); err != nil {
panic(err)
}

Expand All @@ -159,6 +154,9 @@ func init() {
if err := viper.BindEnv("password-auth", "MEMOS_PASSWORD_AUTH"); err != nil {
panic(err)
}
if err := viper.BindEnv("instance-url", "MEMOS_INSTANCE_URL"); err != nil {
panic(err)
}
}

func printGreetings(profile *profile.Profile) {
Expand Down
3 changes: 3 additions & 0 deletions docs/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3154,3 +3154,6 @@ definitions:
passwordAuth:
type: boolean
description: password_auth is a flag whether the instance allows password authentication.
instanceUrl:
type: string
description: instance_url is the URL of the instance.
2 changes: 2 additions & 0 deletions proto/api/v1/workspace_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ message WorkspaceProfile {
bool public = 4;
// password_auth is a flag whether the instance allows password authentication.
bool password_auth = 5;
// instance_url is the URL of the instance.
string instance_url = 6;
}

message GetWorkspaceProfileRequest {}
59 changes: 35 additions & 24 deletions proto/gen/api/v1/workspace_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Profile struct {
Public bool
// PasswordAuth is the flag whether the instance uses password authentication.
PasswordAuth bool
// InstanceURL is the url of your memos instance.
InstanceURL string
}

func (p *Profile) IsDev() bool {
Expand Down
1 change: 1 addition & 0 deletions server/router/api/v1/workspace_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (s *APIV1Service) GetWorkspaceProfile(ctx context.Context, _ *v1pb.GetWorks
Mode: s.Profile.Mode,
Public: s.Profile.Public,
PasswordAuth: s.Profile.PasswordAuth,
InstanceUrl: s.Profile.InstanceURL,
}
owner, err := s.GetInstanceOwner(ctx)
if err != nil {
Expand Down

0 comments on commit c3f381c

Please sign in to comment.