make clean works. configfile builds and runs

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-21 17:53:36 -05:00
parent be5548cd4e
commit bda590a39b
5 changed files with 70 additions and 41 deletions

View File

@ -13,6 +13,17 @@ all:
# Then: # Then:
protoc --version protoc --version
make droplet.pb.go 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: redomod:
rm -f go.* rm -f go.*
@ -21,6 +32,8 @@ redomod:
clean: clean:
rm -f *.pb.go rm -f *.pb.go
-rm go.*
cd configfile && make clean
droplet.pb.go: droplet.proto droplet.pb.go: droplet.proto
protoc --go_out=. droplet.proto protoc --go_out=. droplet.proto

View File

@ -1,8 +1,11 @@
build: build:
go build GO111MODULE=off go build
prep: prep:
go get -v -t -u go get -v -t -u
run: run:
go run *.go go run *.go
clean:
-rm -f configfile

View File

@ -7,7 +7,8 @@ import "bufio"
import "io/ioutil" import "io/ioutil"
import "github.com/golang/protobuf/proto" 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 // saves entries in a config file
@ -20,7 +21,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalln("Error reading file:", err) log.Fatalln("Error reading file:", err)
} }
allEvents := &pb.Event{} allEvents := &pb.Droplet{}
if err := proto.Unmarshal(in, allEvents); err != nil { if err := proto.Unmarshal(in, allEvents); err != nil {
log.Fatalln("Failed to parse events:", err) log.Fatalln("Failed to parse events:", err)
} }
@ -30,7 +31,7 @@ func main() {
log.Println(in) log.Println(in)
} }
func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) { func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Droplet) {
buf, err := proto.Marshal(e) buf, err := proto.Marshal(e)
if err != nil { if err != nil {
log.Fatal("marshaling error: ", err) log.Fatal("marshaling error: ", err)
@ -48,7 +49,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) {
func TestWriteEvent() { func TestWriteEvent() {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
e := pb.CreateSampleEvent() e := pb.CreateSampleDroplet()
got := buf.String() got := buf.String()
log.Println(got) log.Println(got)
@ -61,13 +62,13 @@ func TestWriteEvent() {
} }
func marshalUnmarshal() { func marshalUnmarshal() {
test := pb.CreateSampleEvent() test := pb.CreateSampleDroplet()
data, err := proto.Marshal(test) data, err := proto.Marshal(test)
if err != nil { if err != nil {
log.Fatal("marshaling error: ", err) log.Fatal("marshaling error: ", err)
} }
newTest := &pb.Event{} newTest := &pb.Droplet{}
err = proto.Unmarshal(data, newTest) err = proto.Unmarshal(data, newTest)
if err != nil { if err != nil {
log.Fatal("unmarshaling error: ", err) log.Fatal("unmarshaling error: ", err)

View File

@ -4,47 +4,24 @@ package virtbuf;
message Droplet { message Droplet {
string uuid = 1; string uuid = 1;
string name = 2; 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 = 8;
repeated Network networks = 4; repeated Disk disks = 9;
repeated VM vms = 5;
enum EventType { string comment = 10;
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;
}
message Network { message Network {
string mac = 1; string mac = 1;
string name = 2; string name = 2;
} }
message VM { message Disk {
int64 id = 1; string filename = 1;
string name = 2; int64 size = 2;
string hostname = 3;
int64 cpus = 4;
int64 memory = 5;
int64 disk = 6;
string IPv6 = 7;
string role = 8;
string baseImage = 9;
} }
} }

35
sampleData.go Normal file
View File

@ -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
}