Skip to content

Commit

Permalink
refactor(discovery-example): moved find calls to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 22, 2023
1 parent 15299f4 commit dbc4140
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions examples/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,41 @@ func main() {

ctx := context.Background()

{
log.Println("Finding servers on network")
servers, err := opcua.FindServersOnNetwork(ctx, *endpoint)
if err != nil {
log.Printf("Error calling find servers on network: %v", err)
} else {
for i, server := range servers {
fmt.Printf("%d Server on network:\n", i)
fmt.Printf(" -- RecordID: %v\n", server.RecordID)
fmt.Printf(" -- ServerName: %v\n", server.ServerName)
fmt.Printf(" -- DiscoveryURL: %v\n", server.DiscoveryURL)
fmt.Printf(" -- ServerCapabilities: %v\n", server.ServerCapabilities)
}
}
findServersOnNetwork(ctx, *endpoint)

findServers(ctx, *endpoint)
}

func findServersOnNetwork(ctx context.Context, endpoint string) {
log.Println("Finding servers on network")
servers, err := opcua.FindServersOnNetwork(ctx, endpoint)
if err != nil {
log.Printf("Error calling find servers on network: %v", err)
return
}
for i, server := range servers {
fmt.Printf("%d Server on network:\n", i)
fmt.Printf(" -- RecordID: %v\n", server.RecordID)
fmt.Printf(" -- ServerName: %v\n", server.ServerName)
fmt.Printf(" -- DiscoveryURL: %v\n", server.DiscoveryURL)
fmt.Printf(" -- ServerCapabilities: %v\n", server.ServerCapabilities)
}
}

{
log.Println("Finding servers")
servers, err := opcua.FindServers(ctx, *endpoint)
if err != nil {
log.Fatal(err)
}
for i, server := range servers {
fmt.Printf("%dth Server:\n", i+1)
fmt.Printf(" -- ApplicationURI: %v\n", server.ApplicationURI)
fmt.Printf(" -- ProductURI: %v\n", server.ProductURI)
fmt.Printf(" -- ApplicationName: %v\n", server.ApplicationName)
fmt.Printf(" -- ApplicationType: %v\n", server.ApplicationType)
fmt.Printf(" -- GatewayServerURI: %v\n", server.GatewayServerURI)
fmt.Printf(" -- DiscoveryProfileURI: %v\n", server.DiscoveryProfileURI)
fmt.Printf(" -- DiscoveryURLs: %v\n", server.DiscoveryURLs)
}
func findServers(ctx context.Context, endpoint string) {
log.Println("Finding servers")
servers, err := opcua.FindServers(ctx, endpoint)
if err != nil {
log.Fatal(err)
}
for i, server := range servers {
fmt.Printf("%dth Server:\n", i+1)
fmt.Printf(" -- ApplicationURI: %v\n", server.ApplicationURI)
fmt.Printf(" -- ProductURI: %v\n", server.ProductURI)
fmt.Printf(" -- ApplicationName: %v\n", server.ApplicationName)
fmt.Printf(" -- ApplicationType: %v\n", server.ApplicationType)
fmt.Printf(" -- GatewayServerURI: %v\n", server.GatewayServerURI)
fmt.Printf(" -- DiscoveryProfileURI: %v\n", server.DiscoveryProfileURI)
fmt.Printf(" -- DiscoveryURLs: %v\n", server.DiscoveryURLs)
}
}

0 comments on commit dbc4140

Please sign in to comment.