51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
|
|
package config
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
)
|
||
|
|
|
||
|
|
type MeilisearchConfig struct {
|
||
|
|
Host string
|
||
|
|
APIKey string
|
||
|
|
Index string
|
||
|
|
}
|
||
|
|
|
||
|
|
func loadMeilisearch(env string) MeilisearchConfig {
|
||
|
|
if os.Getenv("MEILISEARCH_HOST") != "" {
|
||
|
|
return MeilisearchConfig{
|
||
|
|
Host: os.Getenv("MEILISEARCH_HOST"),
|
||
|
|
APIKey: os.Getenv("MEILISEARCH_API_KEY"),
|
||
|
|
Index: getEnv("MEILISEARCH_INDEX", "models"),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
switch env {
|
||
|
|
case "production":
|
||
|
|
return MeilisearchConfig{
|
||
|
|
Host: "http://ip-172-31-22-170.eu-central-1.compute.internal:7700",
|
||
|
|
APIKey: getEnv("MEILISEARCH_API_KEY", "young9#!UJsD219921031"),
|
||
|
|
Index: "models",
|
||
|
|
}
|
||
|
|
default:
|
||
|
|
return MeilisearchConfig{
|
||
|
|
Host: "http://ec2-18-184-205-87.eu-central-1.compute.amazonaws.com:7700",
|
||
|
|
APIKey: getEnv("MEILISEARCH_API_KEY", "young9#!UJsD219921031"),
|
||
|
|
Index: "models",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m MeilisearchConfig) validate() error {
|
||
|
|
if m.Host == "" {
|
||
|
|
return fmt.Errorf("meilisearch host is required")
|
||
|
|
}
|
||
|
|
if m.APIKey == "" {
|
||
|
|
return fmt.Errorf("meilisearch api key is required")
|
||
|
|
}
|
||
|
|
if m.Index == "" {
|
||
|
|
return fmt.Errorf("meilisearch index is required")
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|