func (c Config) CreateDSN() string {
	if c.DSN != "" {
		return c.DSN
	}

	host := c.HostOrDefault()
	if c.PortOrDefault() != "" {
		host = host + ":" + c.PortOrDefault()
	}

	dsn := &url.URL{
		Scheme: "postgres",
		Host:   host,
		Path:   c.DatabaseOrDefault(),
	}

	if len(c.Username) > 0 {
		if len(c.Password) > 0 {
			dsn.User = url.UserPassword(c.Username, c.Password)
		} else {
			dsn.User = url.User(c.Username)
		}
	}

	queryArgs := url.Values{}
	if len(c.SSLMode) > 0 {
		queryArgs.Add("sslmode", c.SSLMode)
	}
	if c.ConnectTimeout > 0 {
		setTimeoutSeconds(queryArgs, "connect_timeout", c.ConnectTimeout)
	}
	if c.LockTimeout > 0 {
		setTimeoutMilliseconds(queryArgs, "lock_timeout", c.LockTimeout)
	}
	if c.StatementTimeout > 0 {
		setTimeoutMilliseconds(queryArgs, "statement_timeout", c.StatementTimeout)
	}
	if c.Schema != "" {
		queryArgs.Add("search_path", c.Schema)
	}
	if c.ApplicationName != "" {
		queryArgs.Add("application_name", c.ApplicationName)
	}

	dsn.RawQuery = queryArgs.Encode()
	return dsn.String()
}
// CreateDSN creates a postgres connection string from the config.
CreateDSN creates a postgres connection string from the config.
// CreateDSN creates a postgres connection string from the config .
func (c Config) CreateDSN() string {
	if c.DSN != "" {
		return c.DSN
	}
	host := c.HostOrDefault()
	if c.PortOrDefault() != "" {
		host = host + ":" + c.PortOrDefault()
	}
	dsn := &url.URL{
		Scheme: "postgres",
		Host:   host,
		Path:   c.DatabaseOrDefault(),
	}
	if len(c.Username) > 0 {
		if len(c.Password) > 0 {
			dsn.User = url.UserPassword(c.Username, c.Password)
		} else {
			dsn.User = url.User(c.Username)
		}
	}
	queryArgs := url.Values{}
	if len(c.SSLMode) > 0 {
		queryArgs.Add("sslmode", c.SSLMode)
	}
	if c.ConnectTimeout > 0 {
		setTimeoutSeconds(queryArgs, "connect_timeout", c.ConnectTimeout)
	}
	if c.LockTimeout > 0 {
		setTimeoutMilliseconds(queryArgs, "lock_timeout", c.LockTimeout)
	}
	if c.StatementTimeout > 0 {
		setTimeoutMilliseconds(queryArgs, "statement_timeout", c.StatementTimeout)
	}
	if c.Schema != "" {
		queryArgs.Add("search_path", c.Schema)
	}
	if c.ApplicationName != "" {
		queryArgs.Add("application_name", c.ApplicationName)
	}
	dsn.RawQuery = queryArgs.Encode()
	return dsn.String()
}
func ( c Config ) CreateDSN ( ) string { if c . DSN != " " { return c . DSN } host := c . HostOrDefault ( ) if c . PortOrDefault ( ) != " " { host = host + " " + c . PortOrDefault ( ) } dsn := & url . URL { Scheme : " " , Host : host , Path : c . DatabaseOrDefault ( ) , } if len ( c . Username ) > 0 { if len ( c . Password ) > 0 { dsn . User = url . UserPassword ( c . Username , c . Password ) } else { dsn . User = url . User ( c . Username ) } } queryArgs := url . Values { } if len ( c . SSLMode ) > 0 { queryArgs . Add ( " " , c . SSLMode ) } if c . ConnectTimeout > 0 { setTimeoutSeconds ( queryArgs , " " , c . ConnectTimeout ) } if c . LockTimeout > 0 { setTimeoutMilliseconds ( queryArgs , " " , c . LockTimeout ) } if c . StatementTimeout > 0 { setTimeoutMilliseconds ( queryArgs , " " , c . StatementTimeout ) } if c . Schema != " " { queryArgs . Add ( " " , c . Schema ) } if c . ApplicationName != " " { queryArgs . Add ( " " , c . ApplicationName ) } dsn . RawQuery = queryArgs . Encode ( ) return dsn . String ( ) }
CreateDSN creates a postgres connection string from the config.
CreateDSN creates a postgres connection string from the config .