need to redo this example code

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-22 03:13:12 -05:00
parent aa70a02dd8
commit 9bc90046d9
2 changed files with 9 additions and 7 deletions

View File

@ -14,7 +14,7 @@ import pb "go.wit.com/lib/protobuf/virtbuf"
// //
func main() { func main() {
TestWriteDroplet() TestWriteCluster()
in, err := ioutil.ReadFile("/tmp/testing4.protobuf") in, err := ioutil.ReadFile("/tmp/testing4.protobuf")
if err != nil { if err != nil {
@ -47,7 +47,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, c *pb.Cluster) {
log.Println("bufio.Write() tmp2, err = ", tmp2, err) log.Println("bufio.Write() tmp2, err = ", tmp2, err)
} }
func TestWriteDroplet() { func TestWriteCluster() {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
c := pb.CreateSampleCluster(3) c := pb.CreateSampleCluster(3)
@ -59,7 +59,7 @@ func TestWriteDroplet() {
myWriter := bufio.NewWriter(newfile) myWriter := bufio.NewWriter(newfile)
marshalWriteToFile(myWriter, c) marshalWriteToFile(myWriter, c)
marshalUnmarshal() // marshalUnmarshal()
} }
func marshalUnmarshal() { func marshalUnmarshal() {

View File

@ -3,18 +3,22 @@ package virtbuf
import ( import (
"fmt" "fmt"
"log" "log"
"github.com/google/uuid"
) )
// //
// This generates some sample data. It *should* match the .proto file // This generates some sample data.
// //
func CreateSampleDroplet(hostname string) *Droplet { func CreateSampleDroplet(hostname string) *Droplet {
// TODO: flush this out to do all the fields // TODO: flush this out to do all the fields
log.Println("CreateSampleDroplet() is generating a new droplet", hostname) log.Println("CreateSampleDroplet() is generating a new droplet", hostname)
// Generate a new UUID
id := uuid.New()
d := &Droplet{ d := &Droplet{
Uuid: "6a1c571b-1d02-462b-9288-63d205306d76", Uuid: id.String(),
Hostname: hostname, Hostname: hostname,
Comment: "this is a droplet for testing", Comment: "this is a droplet for testing",
} }
@ -28,8 +32,6 @@ func CreateSampleCluster(total int) *Cluster {
for i := 0; i < total; i++ { for i := 0; i < total; i++ {
hostname := fmt.Sprintf("bmath%d.wit.com", i) hostname := fmt.Sprintf("bmath%d.wit.com", i)
d := CreateSampleDroplet(hostname) d := CreateSampleDroplet(hostname)
// e.Id += 1000 + int32(i)
d.Comment = fmt.Sprintf("Sample Droplet %d", i) d.Comment = fmt.Sprintf("Sample Droplet %d", i)
c.Droplets = append(c.Droplets, d) c.Droplets = append(c.Droplets, d)