Skip to content

Commit

Permalink
set own default config properties, such as 'platform', 'version', 'pr…
Browse files Browse the repository at this point in the history
…oduct'
  • Loading branch information
vetcher committed Oct 22, 2018
1 parent 8733285 commit 748aa44
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions conn/dialers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,33 @@ func DialTLS(url string, amqps *tls.Config, opts ...ConnectionOption) (*Connecti
// DialConfig wraps amqp.DialConfig function and adds reconnection ability.
// Never returns error.
func DialConfig(url string, config amqp.Config, opts ...ConnectionOption) (*Connection, error) {
config.Properties = setupDefaultConfigProperties(config.Properties)
return DialWithDialer(func() (*amqp.Connection, error) { return amqp.DialConfig(url, config) }, opts...)
}

const (
defaultProduct = "https://github.com/devimteam/amqp"
defaultVersion = "v1.1.3"
defaultPlatform = "golang"
defaultInformation = "github.com/devimteam/amqp is a wrapper of https://github.com/streadway/amqp"
)

func setupDefaultConfigProperties(prop amqp.Table) amqp.Table {
if _, ok := prop["product"]; !ok {
prop["product"] = defaultProduct
}
if _, ok := prop["version"]; !ok {
prop["version"] = defaultVersion
}
if _, ok := prop["platform"]; !ok {
prop["platform"] = defaultPlatform
}
if _, ok := prop["information"]; !ok {
prop["information"] = defaultInformation
}
return prop
}

// Open wraps amqp.Open function and adds reconnection ability.
// Never returns error.
func Open(conn io.ReadWriteCloser, config amqp.Config, opts ...ConnectionOption) (*Connection, error) {
Expand Down

0 comments on commit 748aa44

Please sign in to comment.