works with mutex and without again
This commit is contained in:
parent
502826cf8c
commit
76968c90e8
4
Makefile
4
Makefile
|
@ -2,8 +2,8 @@ VERSION = $(shell git describe --tags)
|
||||||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||||
|
|
||||||
simple: build
|
simple: build
|
||||||
# make -C example clean simpleMutexGlobal goimports vet
|
make -C example clean simpleMutexGlobal goimports vet
|
||||||
make -C example clean simpleMutexProtoc goimports vet
|
# make -C example clean simpleMutexProtoc goimports vet
|
||||||
|
|
||||||
full: install clean auto goimports vet build test install
|
full: install clean auto goimports vet build test install
|
||||||
@echo everything worked and the example ran
|
@echo everything worked and the example ran
|
||||||
|
|
20
addMutex.go
20
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)
|
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")
|
lines := strings.Split(string(data), "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
|
@ -59,6 +62,12 @@ func (pb *Files) addMutex(f *File) error {
|
||||||
// fmt.Fprintln(w, "package "+"main")
|
// fmt.Fprintln(w, "package "+"main")
|
||||||
continue
|
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 f.structMatch(line) {
|
||||||
if argv.Mutex {
|
if argv.Mutex {
|
||||||
|
@ -78,9 +87,12 @@ func (pb *Files) addMutex(f *File) error {
|
||||||
fmt.Fprintln(w, line)
|
fmt.Fprintln(w, line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, msg := range f.MsgNames {
|
if argv.Mutex {
|
||||||
if !msg.MutexFound && msg.DoMutex {
|
// verify every structure was found
|
||||||
return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name)
|
for _, msg := range f.MsgNames {
|
||||||
|
if !msg.MutexFound && msg.DoMutex {
|
||||||
|
return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -11,7 +11,7 @@ syntax = "proto3";
|
||||||
// "Fruits" MUST EXIST and start exactly this way
|
// "Fruits" MUST EXIST and start exactly this way
|
||||||
// It must be "Fruit" + 's' and must match the name of this file: "fruit.proto"
|
// 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
|
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue