Skip to content

Commit

Permalink
feat(plc4go/spi): implement GetConnectionUrl for options
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed May 2, 2023
1 parent b691072 commit ab8bfd8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plc4go/spi/model/DefaultPlcDiscoveryItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit ab8bfd8

Please sign in to comment.