package rest

import "fmt"

type Config struct {
	Driver   string `json:"driver"`
	Filename string `json:"filename"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Username string `json:"username"`
	Password string `json:"password"`
	Database string `json:"database"`
}


func (cfg Config) ParseDSN() string {
	if cfg.Driver == "sqlite3" {
		return cfg.Filename
	} else if cfg.Driver == "mysql" {
		return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
			cfg.Username,
			cfg.Password,
			cfg.Host,
			cfg.Port,
			cfg.Database)
	} else if cfg.Driver == "postgres" {
		return fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s",
			cfg.Host,
			cfg.Port,
			cfg.Username,
			cfg.Database,
			cfg.Password)
	}
	return ""
}