From bda590a39b0a873b239b41d62cabe36c75f6a87f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 21 Oct 2024 17:53:36 -0500 Subject: [PATCH] make clean works. configfile builds and runs Signed-off-by: Jeff Carr --- Makefile | 13 +++++++++++++ configfile/Makefile | 5 ++++- configfile/main.go | 13 +++++++------ droplet.proto | 45 +++++++++++---------------------------------- sampleData.go | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 41 deletions(-) create mode 100644 sampleData.go diff --git a/Makefile b/Makefile index 292a050..43c32d0 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,17 @@ all: # Then: protoc --version make droplet.pb.go + cd configfile && make + +vet: + GO111MODULE=off go vet + +lint: + buf lint droplet.proto + +# autofixes your import headers in your golang files +goimports: + goimports -w *.go redomod: rm -f go.* @@ -21,6 +32,8 @@ redomod: clean: rm -f *.pb.go + -rm go.* + cd configfile && make clean droplet.pb.go: droplet.proto protoc --go_out=. droplet.proto diff --git a/configfile/Makefile b/configfile/Makefile index 15d8b54..b1a31f3 100644 --- a/configfile/Makefile +++ b/configfile/Makefile @@ -1,8 +1,11 @@ build: - go build + GO111MODULE=off go build prep: go get -v -t -u run: go run *.go + +clean: + -rm -f configfile diff --git a/configfile/main.go b/configfile/main.go index c012ba3..3cc713c 100644 --- a/configfile/main.go +++ b/configfile/main.go @@ -7,7 +7,8 @@ import "bufio" import "io/ioutil" import "github.com/golang/protobuf/proto" -import pb "git.wit.com/wit/virtbuf" +// import "google.golang.org/protobuf/proto" +import pb "go.wit.com/lib/protobuf/virtbuf" // // saves entries in a config file @@ -20,7 +21,7 @@ func main() { if err != nil { log.Fatalln("Error reading file:", err) } - allEvents := &pb.Event{} + allEvents := &pb.Droplet{} if err := proto.Unmarshal(in, allEvents); err != nil { log.Fatalln("Failed to parse events:", err) } @@ -30,7 +31,7 @@ func main() { log.Println(in) } -func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) { +func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Droplet) { buf, err := proto.Marshal(e) if err != nil { log.Fatal("marshaling error: ", err) @@ -48,7 +49,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) { func TestWriteEvent() { buf := new(bytes.Buffer) - e := pb.CreateSampleEvent() + e := pb.CreateSampleDroplet() got := buf.String() log.Println(got) @@ -61,13 +62,13 @@ func TestWriteEvent() { } func marshalUnmarshal() { - test := pb.CreateSampleEvent() + test := pb.CreateSampleDroplet() data, err := proto.Marshal(test) if err != nil { log.Fatal("marshaling error: ", err) } - newTest := &pb.Event{} + newTest := &pb.Droplet{} err = proto.Unmarshal(data, newTest) if err != nil { log.Fatal("unmarshaling error: ", err) diff --git a/droplet.proto b/droplet.proto index 8c12664..7cf14de 100644 --- a/droplet.proto +++ b/droplet.proto @@ -4,47 +4,24 @@ package virtbuf; message Droplet { string uuid = 1; string name = 2; + string hostname = 3; + int64 cpus = 4; + int64 memory = 5; + int64 disk = 6; + string base_image = 7; - repeated Response results = 3; - repeated Network networks = 4; - repeated VM vms = 5; + repeated Network networks = 8; + repeated Disk disks = 9; - enum EventType { - ADD = 0; - DELETE = 1; - POWERON = 2; - POWEROFF = 3; - HIBERNATE = 4; - MIGRATE = 5; - DEMO = 6; - GET = 7; // request something - LOGIN = 8; // attempt to login - OK = 9; // everything is ok - FAIL = 10; // everything failed - } - - message Response { - EventType type = 1; - int32 id = 2; - string name = 3; - string error = 4; - repeated string snippets = 5; - } + string comment = 10; message Network { string mac = 1; string name = 2; } - message VM { - int64 id = 1; - string name = 2; - string hostname = 3; - int64 cpus = 4; - int64 memory = 5; - int64 disk = 6; - string IPv6 = 7; - string role = 8; - string baseImage = 9; + message Disk { + string filename = 1; + int64 size = 2; } } diff --git a/sampleData.go b/sampleData.go new file mode 100644 index 0000000..6c48985 --- /dev/null +++ b/sampleData.go @@ -0,0 +1,35 @@ +package virtbuf + +import "log" + +// +// This generates some sample data. It *should* match the .proto file +// + +func CreateSampleDroplet() *Droplet { + // TODO: flush this out to do all the fields + log.Println("CreateSampleDroplet() is generating a new droplet") + + e := &Droplet{ + Uuid: "6a1c571b-1d02-462b-9288-63d205306d76", + Hostname: "bmath.wit.com", + Comment: "this is a droplet for testing", + } + return e +} + +func CreateSampleDroplets(total int) []Droplet { + + var all []Droplet + + for i := 0; i < total; i++ { + d := CreateSampleDroplet() + + // e.Id += 1000 + int32(i) + d.Comment = "Sample Event " + string(i) + + all = append(all, *d) + } + + return all +}