gorm/dsn.go
2023-03-27 15:47:24 +08:00

32 lines
449 B
Go

package gorm
import (
"net/url"
"strconv"
)
type DSN struct {
Host string
Port int
User string
Pass string
Db string
Options map[string]string
}
func (d DSN) String() string {
dsn := d.User + ":" + d.Pass + "@tcp(" + d.Host + ":" + strconv.Itoa(d.Port) + ")/" + d.Db
if d.Options != nil {
value := url.Values{}
for k, v := range d.Options {
value.Add(k, v)
}
dsn += "?" + value.Encode()
}
return dsn
}