summaryrefslogtreecommitdiff
path: root/change.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-24 21:39:07 -0500
committerJeff Carr <[email protected]>2024-10-24 21:39:07 -0500
commit1effa9c745ac224c3160f3817d4d0ec7af96950d (patch)
treed3c7a0ce714dff56b61ead8c61e89682f9b28ee4 /change.go
parentfea819956f4c8cfd43623ad7d0c1992b0305291d (diff)
working on making events
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'change.go')
-rw-r--r--change.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/change.go b/change.go
new file mode 100644
index 0000000..f4e7d79
--- /dev/null
+++ b/change.go
@@ -0,0 +1,64 @@
+package main
+
+import (
+ // "reflect"
+
+ "errors"
+
+ "google.golang.org/protobuf/types/known/anypb"
+ "google.golang.org/protobuf/types/known/wrapperspb"
+
+ pb "go.wit.com/lib/protobuf/virtbuf"
+ "go.wit.com/log"
+)
+
+func convert(x any) *anypb.Any {
+ switch v := x.(type) {
+ case int64:
+ var a *anypb.Any
+ a, _ = anypb.New(wrapperspb.Int64(x.(int64)))
+ return a
+ case string:
+ var a *anypb.Any
+ a, _ = anypb.New(wrapperspb.String(x.(string)))
+ return a
+ case int:
+ var a *anypb.Any
+ a, _ = anypb.New(wrapperspb.Int64(x.(int64)))
+ return a
+ case bool:
+ var a *anypb.Any
+ a, _ = anypb.New(wrapperspb.Bool(x.(bool)))
+ return a
+ default:
+ log.Error(errors.New("Set() unknown type"), "v =", v, "x =", x)
+ return nil
+ }
+ return nil
+}
+
+// Wrapping the int into a protobuf message
+func NewEvent(origval any, newval any) *pb.Event {
+ var e *pb.Event
+ e = new(pb.Event)
+
+ e.OrigVal = convert(origval)
+ e.NewVal = convert(newval)
+ return e
+}
+
+// update the droplet memory
+func (d *DropletT) SetMemory(b int64) *pb.Event {
+ log.Info("Set the amount of memory for the droplet", b)
+ if d.pb.Memory == b {
+ return nil
+ }
+ var e *pb.Event
+ e = NewEvent(d.pb.Memory, b)
+ return e
+}
+
+// update the droplet memory
+func (d *DropletT) SetCpus(b int64) {
+ log.Info("Set the number of cpus for the droplet", b)
+}