summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--addMutex.go20
-rw-r--r--example/fruit.proto2
3 files changed, 19 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 068d8a1..c2830b7 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
simple: build
- # make -C example clean simpleMutexGlobal goimports vet
- make -C example clean simpleMutexProtoc goimports vet
+ make -C example clean simpleMutexGlobal goimports vet
+ # make -C example clean simpleMutexProtoc goimports vet
full: install clean auto goimports vet build test install
@echo everything worked and the example ran
diff --git a/addMutex.go b/addMutex.go
index dfb091c..f9e143e 100644
--- a/addMutex.go
+++ b/addMutex.go
@@ -48,7 +48,10 @@ func (pb *Files) addMutex(f *File) error {
w, _ := os.OpenFile(f.Pbfilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
- pbHeaderComment(w)
+ // the default is to insert a mutex directly into the struct
+ if argv.Mutex {
+ pbHeaderComment(w)
+ }
lines := strings.Split(string(data), "\n")
for _, line := range lines {
@@ -59,6 +62,12 @@ func (pb *Files) addMutex(f *File) error {
// fmt.Fprintln(w, "package "+"main")
continue
}
+ // the default is to insert a mutex directly into the struct
+ if !argv.Mutex {
+ // mutex is not to be added, only fix the package name
+ fmt.Fprintln(w, line)
+ continue
+ }
if f.structMatch(line) {
if argv.Mutex {
@@ -78,9 +87,12 @@ func (pb *Files) addMutex(f *File) error {
fmt.Fprintln(w, line)
}
}
- for _, msg := range f.MsgNames {
- if !msg.MutexFound && msg.DoMutex {
- return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name)
+ if argv.Mutex {
+ // verify every structure was found
+ for _, msg := range f.MsgNames {
+ if !msg.MutexFound && msg.DoMutex {
+ return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name)
+ }
}
}
return nil
diff --git a/example/fruit.proto b/example/fruit.proto
index a965d42..92e46ef 100644
--- a/example/fruit.proto
+++ b/example/fruit.proto
@@ -11,7 +11,7 @@ syntax = "proto3";
// "Fruits" MUST EXIST and start exactly this way
// It must be "Fruit" + 's' and must match the name of this file: "fruit.proto"
-package fruit;
+package main;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp