Skip to content

Commit 102de6e

Browse files
committed
new entities
1 parent e27d6a6 commit 102de6e

4 files changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module cable_termination
2+
3+
go 1.25
4+
5+
require github.com/netboxlabs/diode-sdk-go v0.1.0
6+
7+
// Use local SDK for development and validation
8+
// When copying this example, remove the replace directive and update the require version above
9+
replace github.com/netboxlabs/diode-sdk-go => ../../..
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Package main demonstrates ingesting CableTermination entities using the Diode SDK.
2+
// This example includes three patterns: Minimal, Extended, and Explicit.
3+
package main
4+
5+
import (
6+
"context"
7+
"log"
8+
9+
"github.com/netboxlabs/diode-sdk-go/diode"
10+
)
11+
12+
const (
13+
target = "grpc://localhost:8080/diode"
14+
appName = "cable_termination-example"
15+
appVersion = "1.0.0"
16+
)
17+
18+
func main() {
19+
client, err := diode.NewClient(
20+
target,
21+
appName,
22+
appVersion,
23+
)
24+
if err != nil {
25+
log.Fatalf("Failed to create client: %v", err)
26+
}
27+
28+
// Choose one of the three patterns by uncommenting:
29+
cableTermination := CableTerminationMinimal()
30+
// cableTermination := CableTerminationExtended()
31+
// cableTermination := CableTerminationExplicit()
32+
33+
resp, err := client.Ingest(context.Background(), []diode.Entity{cableTermination})
34+
if err != nil {
35+
log.Fatalf("Ingestion failed: %v", err)
36+
}
37+
if resp.Errors != nil {
38+
log.Printf("Errors: %v", resp.Errors)
39+
} else {
40+
log.Println("CableTermination ingested successfully")
41+
}
42+
}
43+
44+
// CableTerminationMinimal Creates a CableTermination with only required fields.
45+
func CableTerminationMinimal() *diode.CableTermination {
46+
return &diode.CableTermination{
47+
Cable: &diode.Cable{
48+
Metadata: diode.Metadata{"source": "example"},
49+
},
50+
CableEnd: diode.String("A"),
51+
Metadata: diode.Metadata{"source": "example"},
52+
}
53+
}
54+
55+
// CableTerminationExtended Creates a CableTermination with common optional fields.
56+
func CableTerminationExtended() *diode.CableTermination {
57+
return &diode.CableTermination{
58+
Cable: &diode.Cable{
59+
Metadata: diode.Metadata{"source": "example"},
60+
},
61+
CableEnd: diode.String("A"),
62+
Metadata: diode.Metadata{"source": "example"},
63+
}
64+
}
65+
66+
// CableTerminationExplicit Creates a CableTermination with fully nested objects and all common fields.
67+
func CableTerminationExplicit() *diode.CableTermination {
68+
return &diode.CableTermination{
69+
Cable: &diode.Cable{
70+
Status: diode.String("active"),
71+
Color: diode.String("0000ff"),
72+
Metadata: diode.Metadata{"source": "example"},
73+
},
74+
CableEnd: diode.String("A"),
75+
Metadata: diode.Metadata{"source": "example"},
76+
}
77+
}

docs/examples/device_config/go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module device_config
2+
3+
go 1.25
4+
5+
require github.com/netboxlabs/diode-sdk-go v0.1.0
6+
7+
// Use local SDK for development and validation
8+
// When copying this example, remove the replace directive and update the require version above
9+
replace github.com/netboxlabs/diode-sdk-go => ../../..
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Package main demonstrates ingesting DeviceConfig entities using the Diode SDK.
2+
// This example includes three patterns: Minimal, Extended, and Explicit.
3+
package main
4+
5+
import (
6+
"context"
7+
"log"
8+
9+
"github.com/netboxlabs/diode-sdk-go/diode"
10+
)
11+
12+
const (
13+
target = "grpc://localhost:8080/diode"
14+
appName = "device_config-example"
15+
appVersion = "1.0.0"
16+
)
17+
18+
func main() {
19+
client, err := diode.NewClient(
20+
target,
21+
appName,
22+
appVersion,
23+
)
24+
if err != nil {
25+
log.Fatalf("Failed to create client: %v", err)
26+
}
27+
28+
// Choose one of the three patterns by uncommenting:
29+
deviceConfig := DeviceConfigMinimal()
30+
// deviceConfig := DeviceConfigExtended()
31+
// deviceConfig := DeviceConfigExplicit()
32+
33+
resp, err := client.Ingest(context.Background(), []diode.Entity{deviceConfig})
34+
if err != nil {
35+
log.Fatalf("Ingestion failed: %v", err)
36+
}
37+
if resp.Errors != nil {
38+
log.Printf("Errors: %v", resp.Errors)
39+
} else {
40+
log.Println("DeviceConfig ingested successfully")
41+
}
42+
}
43+
44+
// DeviceConfigMinimal Creates a DeviceConfig with only required fields.
45+
func DeviceConfigMinimal() *diode.DeviceConfig {
46+
return &diode.DeviceConfig{
47+
Startup: []byte("example data"),
48+
Running: []byte("example data"),
49+
Candidate: []byte("example data"),
50+
Metadata: diode.Metadata{"source": "example"},
51+
}
52+
}
53+
54+
// DeviceConfigExtended Creates a DeviceConfig with common optional fields.
55+
func DeviceConfigExtended() *diode.DeviceConfig {
56+
return &diode.DeviceConfig{
57+
Startup: []byte("example data"),
58+
Running: []byte("example data"),
59+
Candidate: []byte("example data"),
60+
Metadata: diode.Metadata{"source": "example"},
61+
}
62+
}
63+
64+
// DeviceConfigExplicit Creates a DeviceConfig with fully nested objects and all common fields.
65+
func DeviceConfigExplicit() *diode.DeviceConfig {
66+
return &diode.DeviceConfig{
67+
Startup: []byte("example data"),
68+
Running: []byte("example data"),
69+
Candidate: []byte("example data"),
70+
Metadata: diode.Metadata{"source": "example"},
71+
}
72+
}

0 commit comments

Comments
 (0)