You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/05/02 16:51:50 UTC
[plc4x] 02/03: feat(plc4go/spi): implement GetConnectionUrl for options
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit ab8bfd8a17acf890e77f779b3dec6ec230f63ac3
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue May 2 18:35:25 2023 +0200
feat(plc4go/spi): implement GetConnectionUrl for options
---
plc4go/spi/model/DefaultPlcDiscoveryItem.go | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/plc4go/spi/model/DefaultPlcDiscoveryItem.go b/plc4go/spi/model/DefaultPlcDiscoveryItem.go
index d8393d9609..6f8e08bfb7 100644
--- a/plc4go/spi/model/DefaultPlcDiscoveryItem.go
+++ b/plc4go/spi/model/DefaultPlcDiscoveryItem.go
@@ -20,9 +20,11 @@
package model
import (
+ "net/url"
+ "strings"
+
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
- "net/url"
)
//go:generate go run ../../tools/plc4xgenerator/gen.go -type=DefaultPlcDiscoveryItem
@@ -78,8 +80,15 @@ func (d *DefaultPlcDiscoveryItem) GetAttributes() map[string]apiValues.PlcValue
}
func (d *DefaultPlcDiscoveryItem) GetConnectionUrl() string {
+ options := ""
if d.Options != nil {
- panic("Not implemented")
+ flatOptions := []string{}
+ for k, vl := range d.Options {
+ for _, v := range vl {
+ flatOptions = append(flatOptions, url.QueryEscape(k)+"="+url.QueryEscape(v))
+ }
+ }
+ options += "?" + strings.Join(flatOptions, "&")
}
- return d.ProtocolCode + ":" + d.TransportCode + "//" + d.TransportUrl.Host
+ return d.ProtocolCode + ":" + d.TransportCode + "//" + d.TransportUrl.Host + options
}