Skip to content

Commit 748aa44

Browse files
committed
set own default config properties, such as 'platform', 'version', 'product'
1 parent 8733285 commit 748aa44

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

conn/dialers.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,33 @@ func DialTLS(url string, amqps *tls.Config, opts ...ConnectionOption) (*Connecti
3737
// DialConfig wraps amqp.DialConfig function and adds reconnection ability.
3838
// Never returns error.
3939
func DialConfig(url string, config amqp.Config, opts ...ConnectionOption) (*Connection, error) {
40+
config.Properties = setupDefaultConfigProperties(config.Properties)
4041
return DialWithDialer(func() (*amqp.Connection, error) { return amqp.DialConfig(url, config) }, opts...)
4142
}
4243

44+
const (
45+
defaultProduct = "https://github.com/devimteam/amqp"
46+
defaultVersion = "v1.1.3"
47+
defaultPlatform = "golang"
48+
defaultInformation = "github.com/devimteam/amqp is a wrapper of https://github.com/streadway/amqp"
49+
)
50+
51+
func setupDefaultConfigProperties(prop amqp.Table) amqp.Table {
52+
if _, ok := prop["product"]; !ok {
53+
prop["product"] = defaultProduct
54+
}
55+
if _, ok := prop["version"]; !ok {
56+
prop["version"] = defaultVersion
57+
}
58+
if _, ok := prop["platform"]; !ok {
59+
prop["platform"] = defaultPlatform
60+
}
61+
if _, ok := prop["information"]; !ok {
62+
prop["information"] = defaultInformation
63+
}
64+
return prop
65+
}
66+
4367
// Open wraps amqp.Open function and adds reconnection ability.
4468
// Never returns error.
4569
func Open(conn io.ReadWriteCloser, config amqp.Config, opts ...ConnectionOption) (*Connection, error) {

0 commit comments

Comments
 (0)