Skip to content

Commit

Permalink
add elasticsearch username & password to config
Browse files Browse the repository at this point in the history
  • Loading branch information
logica0419 committed Dec 7, 2023
1 parent c0eef75 commit df38293
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ type Config struct {

// ES Elasticsearch設定
ES struct {
// URL URL (default: "")
URL string `mapstructure:"url" yaml:"url"`
// Username ユーザー名 (default: "elastic")
Username string `mapstructure:"username" yaml:"username"`
// Password パスワード (default: "password")
Password string `mapstructure:"password" yaml:"password"`
} `mapstructure:"es" yaml:"es"`

// Storage ファイルストレージ設定
Expand Down Expand Up @@ -270,6 +275,8 @@ func init() {
viper.SetDefault("mariadb.connection.maxIdle", 2)
viper.SetDefault("mariadb.connection.lifetime", 0)
viper.SetDefault("es.url", "")
viper.SetDefault("es.username", "elastic")
viper.SetDefault("es.password", "password")
viper.SetDefault("storage.type", "local")
viper.SetDefault("storage.local.dir", "./storage")
viper.SetDefault("storage.swift.username", "")
Expand Down Expand Up @@ -452,7 +459,9 @@ func provideFirebaseCredentialsFilePathString(c *Config) variable.FirebaseCreden

func provideESEngineConfig(c *Config) search.ESEngineConfig {
return search.ESEngineConfig{
URL: c.ES.URL,
URL: c.ES.URL,
Username: c.ES.Username,
Password: c.ES.Password,
}
}

Expand Down
6 changes: 6 additions & 0 deletions service/search/es.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func getIndexName(index string) string {
type ESEngineConfig struct {
// URL ESのURL
URL string
// Username ESのユーザー名
Username string
// Password ESのパスワード
Password string
}

// esEngine search.Engine 実装
Expand Down Expand Up @@ -173,6 +177,8 @@ func NewESEngine(mm message.Manager, cm channel.Manager, repo repository.Reposit
// esクライアント作成
client, err := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{config.URL},
Username: config.Username,
Password: config.Password,
})
if err != nil {
return nil, fmt.Errorf("failed to init Elasticsearch: %w", err)
Expand Down

0 comments on commit df38293

Please sign in to comment.