Reorder items in generated source files.
Ideally they would always have been sorted as such, but this seems more critical in migrating from one service definition to another where the ordering might change.
This commit is contained in:
@ -29,16 +29,16 @@ import (
|
||||
var _ time.Time
|
||||
|
||||
// Device URNs:
|
||||
const ({{range .DeviceTypes}}
|
||||
const ({{range .OrderedDeviceTypes}}
|
||||
{{.Const}} = "{{.URN}}"{{end}}
|
||||
)
|
||||
|
||||
// Service URNs:
|
||||
const ({{range .ServiceTypes}}
|
||||
const ({{range .OrderedServiceTypes}}
|
||||
{{.Const}} = "{{.URN}}"{{end}}
|
||||
)
|
||||
|
||||
{{range .Services}}
|
||||
{{range .OrderedServices}}
|
||||
{{$srv := .}}
|
||||
{{$srvIdent := printf "%s%s" .Name .Version}}
|
||||
|
||||
@ -102,7 +102,7 @@ func new{{$srvIdent}}ClientsFromGenericClients(genericClients []goupnp.ServiceCl
|
||||
return clients
|
||||
}
|
||||
|
||||
{{range .SCPD.Actions}}{{/* loops over *SCPDWithURN values */}}
|
||||
{{range .SCPD.OrderedActions}}{{/* loops over *SCPDWithURN values */}}
|
||||
|
||||
{{$winargs := $srv.WrapArguments .InputArguments}}
|
||||
{{$woutargs := $srv.WrapArguments .OutputArguments}}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/huin/goupnp"
|
||||
@ -85,6 +86,7 @@ func (dcp *DCP) writeCode(outFile string, useGofmt bool) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err = packageTmpl.Execute(output, dcp); err != nil {
|
||||
output.Close()
|
||||
return err
|
||||
@ -92,6 +94,33 @@ func (dcp *DCP) writeCode(outFile string, useGofmt bool) error {
|
||||
return output.Close()
|
||||
}
|
||||
|
||||
func (dcp *DCP) OrderedServices() []SCPDWithURN {
|
||||
services := append([]SCPDWithURN{}, dcp.Services...)
|
||||
sort.SliceStable(services, func(i, j int) bool {
|
||||
return services[i].URNParts.URN < services[j].URNParts.URN
|
||||
})
|
||||
return services
|
||||
}
|
||||
|
||||
func orderedURNParts(urnMap map[string]*URNParts) []*URNParts {
|
||||
urns := make([]*URNParts, 0, len(urnMap))
|
||||
for _, urn := range urnMap {
|
||||
urns = append(urns, urn)
|
||||
}
|
||||
sort.SliceStable(urns, func(i, j int) bool {
|
||||
return urns[i].URN < urns[j].URN
|
||||
})
|
||||
return urns
|
||||
}
|
||||
|
||||
func (dcp *DCP) OrderedDeviceTypes() []*URNParts {
|
||||
return orderedURNParts(dcp.DeviceTypes)
|
||||
}
|
||||
|
||||
func (dcp *DCP) OrderedServiceTypes() []*URNParts {
|
||||
return orderedURNParts(dcp.ServiceTypes)
|
||||
}
|
||||
|
||||
func (dcp *DCP) processSCPDFile(file *zip.File) error {
|
||||
scpd := new(scpd.SCPD)
|
||||
if err := unmarshalXmlFile(file, scpd); err != nil {
|
||||
|
Reference in New Issue
Block a user