Skip to content

Commit a742d27

Browse files
committed
expand env vars
Signed-off-by: Khash Sajadi <[email protected]>
1 parent 1c81009 commit a742d27

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Add any required modules to CoreDNS code as prompted.
2626

2727
In the Corefile, `mysql` can be configured with the following parameters:
2828

29-
`dsn` DSN for MySQL as per https://github.com/go-sql-driver/mysql examples.
29+
`dsn` DSN for MySQL as per https://github.com/go-sql-driver/mysql examples. You can use `$ENV_NAME` format in the DSN, and it will be replaced with the environment variable value.
3030
`table_prefix` Prefix for the MySQL tables. Defaults to `coredns_`.
3131
`max_lifetime` Duration (in Golang format) for a SQL connection. Default is 1 minute.
3232
`max_open_connections` Maximum number of open connections to the database server. Default is 10.

setup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coredns_mysql
22

33
import (
44
"database/sql"
5+
"os"
56
"strconv"
67
"time"
78

@@ -129,7 +130,7 @@ func mysqlParse(c *caddy.Controller) (*CoreDNSMySql, error) {
129130
}
130131

131132
func (handler *CoreDNSMySql) db() (*sql.DB, error) {
132-
db, err := sql.Open("mysql", handler.Dsn)
133+
db, err := sql.Open("mysql", os.ExpandEnv(handler.Dsn))
133134
if err != nil {
134135
return nil, err
135136
}

0 commit comments

Comments
 (0)