init
This commit is contained in:
52
config/config.go
Normal file
52
config/config.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// Config represents the application configuration
|
||||
type Config struct {
|
||||
Server struct {
|
||||
Port int `mapstructure:"port"`
|
||||
ReadTimeoutSeconds int `mapstructure:"read_timeout_seconds"`
|
||||
WriteTimeoutSeconds int `mapstructure:"write_timeout_seconds"`
|
||||
IdleTimeoutSeconds int `mapstructure:"idle_timeout_seconds"`
|
||||
} `mapstructure:"server"`
|
||||
|
||||
LogLevel string `mapstructure:"log_level"`
|
||||
|
||||
Google struct {
|
||||
ProjectID string `mapstructure:"project_id"`
|
||||
Location string `mapstructure:"location"`
|
||||
Dataset string `mapstructure:"dataset"`
|
||||
DicomStore string `mapstructure:"dicom_store"`
|
||||
CredentialsPath string `mapstructure:"credentials_path"`
|
||||
} `mapstructure:"google"`
|
||||
|
||||
AllowedOrigins []string `mapstructure:"allowed_origins"`
|
||||
}
|
||||
|
||||
// Load reads configuration from file and environment variables
|
||||
func Load() (*Config, error) {
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath("./config")
|
||||
viper.AddConfigPath(".")
|
||||
|
||||
viper.AutomaticEnv()
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return nil, fmt.Errorf("failed to read config file: %w", err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := viper.Unmarshal(&cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
18
config/config.yaml
Normal file
18
config/config.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
server:
|
||||
port: 8080
|
||||
read_timeout_seconds: 30
|
||||
write_timeout_seconds: 30
|
||||
idle_timeout_seconds: 60
|
||||
|
||||
log_level: "info" # debug, info, warn, error
|
||||
|
||||
google:
|
||||
project_id: "your-project-id"
|
||||
location: "asia-southeast2"
|
||||
dataset: "dicom-storage"
|
||||
dicom_store: "ohif"
|
||||
credentials_path: "./credentials/service-account.json"
|
||||
|
||||
# CORS settings - origins that are allowed to access the API
|
||||
allowed_origins:
|
||||
- "*" # Allow all origins (you may want to restrict this in production)
|
||||
Reference in New Issue
Block a user