summaryrefslogtreecommitdiff
path: root/helpers.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-30 11:06:14 -0500
committerJeff Carr <[email protected]>2024-10-30 11:06:14 -0500
commit9608bb680f4679d16985f34d227f1bcf8a0d6c87 (patch)
treef70c0cd126bab553dcf2d802edf793db2e7354e2 /helpers.go
parent6a0d4d3e3883de811cf594b0bcddd1f2c9736b43 (diff)
rename and rm old code
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'helpers.go')
-rw-r--r--helpers.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/helpers.go b/helpers.go
new file mode 100644
index 0000000..49f8cfb
--- /dev/null
+++ b/helpers.go
@@ -0,0 +1,79 @@
+package virtbuf
+
+// functions to import and export the protobuf
+// data to and from config files
+
+import (
+ "google.golang.org/protobuf/encoding/protojson"
+ "google.golang.org/protobuf/encoding/prototext"
+)
+
+// human readable JSON
+func (c *Cluster) FormatJSON() string {
+ return protojson.Format(c)
+}
+
+func (d *Droplets) FormatJSON() string {
+ return protojson.Format(d)
+}
+
+func (d *Droplet) FormatJSON() string {
+ return protojson.Format(d)
+}
+
+func (e *Events) FormatJSON() string {
+ return protojson.Format(e)
+}
+
+func (h *Hypervisors) FormatJSON() string {
+ return protojson.Format(h)
+}
+
+// apparently this isn't supposed to be used?
+// https://protobuf.dev/reference/go/faq/#unstable-text
+// this is a shame because this is much nicer output than JSON Format()
+func (c *Cluster) FormatTEXT() string {
+ return prototext.Format(c)
+}
+
+func (d *Droplets) FormatTEXT() string {
+ return prototext.Format(d)
+}
+
+func (e *Events) FormatTEXT() string {
+ return prototext.Format(e)
+}
+
+// marshal
+func (c *Cluster) MarshalJSON() ([]byte, error) {
+ return protojson.Marshal(c)
+}
+
+func (d *Droplets) MarshalJSON() ([]byte, error) {
+ return protojson.Marshal(d)
+}
+
+func (d *Droplet) MarshalJSON() ([]byte, error) {
+ return protojson.Marshal(d)
+}
+
+func (e *Events) MarshalJSON() ([]byte, error) {
+ return protojson.Marshal(e)
+}
+
+// unmarshal
+func (c *Cluster) UnmarshalJSON(data []byte) error {
+ return protojson.Unmarshal(data, c)
+}
+
+func (d *Droplets) UnmarshalJSON(data []byte) error {
+ return protojson.Unmarshal(data, d)
+}
+
+func (d *Droplet) UnmarshalJSON(data []byte) error {
+ return protojson.Unmarshal(data, d)
+}
+
+func (e *Events) UnmarshalJSON(data []byte) error {
+ return protojson.Unmarshal(data, e)
+}