make clean works. configfile builds and runs
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
be5548cd4e
commit
bda590a39b
13
Makefile
13
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue