jam a mutex in the proto-gen-go pb.go file for now
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
a6035cb90f
commit
a40f961924
1
argv.go
1
argv.go
|
@ -16,6 +16,7 @@ type args struct {
|
||||||
Sort []string `arg:"--sort" help:"how and what to sort on"`
|
Sort []string `arg:"--sort" help:"how and what to sort on"`
|
||||||
Marshal []string `arg:"--marshal" help:"what to marshal on"`
|
Marshal []string `arg:"--marshal" help:"what to marshal on"`
|
||||||
NoMarshal bool `arg:"--no-marshal" help:"do not make a marshal.pb.go file"`
|
NoMarshal bool `arg:"--no-marshal" help:"do not make a marshal.pb.go file"`
|
||||||
|
NoSort bool `arg:"--no-sort" help:"do not make a sort.pb.go file"`
|
||||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
47
main.go
47
main.go
|
@ -15,6 +15,8 @@ import (
|
||||||
var VERSION string
|
var VERSION string
|
||||||
var BUILDTIME string
|
var BUILDTIME string
|
||||||
|
|
||||||
|
var sortmap map[string]string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
pp := arg.MustParse(&argv)
|
pp := arg.MustParse(&argv)
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ func main() {
|
||||||
|
|
||||||
protobase := strings.TrimSuffix(argv.Proto, ".proto")
|
protobase := strings.TrimSuffix(argv.Proto, ".proto")
|
||||||
|
|
||||||
sortmap := make(map[string]string)
|
sortmap = make(map[string]string)
|
||||||
sortmap["package"] = packageName
|
sortmap["package"] = packageName
|
||||||
sortmap["protobase"] = protobase
|
sortmap["protobase"] = protobase
|
||||||
if argv.LoBase == "" {
|
if argv.LoBase == "" {
|
||||||
|
@ -80,50 +82,17 @@ func main() {
|
||||||
// add mutex
|
// add mutex
|
||||||
if err := addMutex(sortmap); err == nil {
|
if err := addMutex(sortmap); err == nil {
|
||||||
log.Info("adding mutex to existing protoc-gen-go file worked")
|
log.Info("adding mutex to existing protoc-gen-go file worked")
|
||||||
|
sortmap["mutex"] = "true"
|
||||||
} else {
|
} else {
|
||||||
log.Info("adding mutex to existing protoc-gen-go file did not work")
|
log.Info("adding mutex to existing protoc-gen-go file did not work")
|
||||||
|
sortmap["mutex"] = "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
f, _ := os.OpenFile(protobase+".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600)
|
if argv.NoSort {
|
||||||
|
log.Info("not making sort.pb.go file (--no-sort == true)")
|
||||||
header(f, sortmap)
|
|
||||||
syncLock(f, sortmap)
|
|
||||||
iterTop(f, sortmap)
|
|
||||||
iterNext(f, sortmap)
|
|
||||||
|
|
||||||
// setup Sort() functions
|
|
||||||
if len(argv.Sort) == 0 {
|
|
||||||
// don't do any sorting
|
|
||||||
// setup Append() functions
|
|
||||||
if argv.Append == "" {
|
|
||||||
iterAppend(f, sortmap) // Append() enforce no unique keys
|
|
||||||
} else {
|
|
||||||
iterAppend(f, sortmap) // Append() enforce no unique keys
|
|
||||||
sortmap["append"] = argv.Append
|
|
||||||
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
sortparts := strings.Split(argv.Sort[0], ",")
|
makeSortfile()
|
||||||
sortmap["sortBy"] = sortparts[0]
|
|
||||||
sortmap["sortKey"] = sortparts[1]
|
|
||||||
|
|
||||||
iterSort(f, sortmap)
|
|
||||||
|
|
||||||
if argv.Append == "" {
|
|
||||||
iterAppend(f, sortmap) // Append() enforce no unique keys
|
|
||||||
} else {
|
|
||||||
iterAppend(f, sortmap) // Append() enforce no unique keys
|
|
||||||
sortmap["append"] = argv.Append
|
|
||||||
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
|
||||||
}
|
|
||||||
sortmap["append"] = sortmap["sortKey"]
|
|
||||||
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
|
||||||
|
|
||||||
// add ReplaceKey()
|
|
||||||
iterDelete(f, sortmap)
|
|
||||||
iterReplace(f, sortmap)
|
|
||||||
}
|
}
|
||||||
iterEnd(f, sortmap)
|
|
||||||
|
|
||||||
if argv.NoMarshal {
|
if argv.NoMarshal {
|
||||||
log.Info("not making marshal.pb.go file (--no-marshal == true)")
|
log.Info("not making marshal.pb.go file (--no-marshal == true)")
|
||||||
|
|
44
sort.go
44
sort.go
|
@ -3,8 +3,52 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func makeSortfile() {
|
||||||
|
f, _ := os.OpenFile(sortmap["protobase"] + ".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
|
|
||||||
|
header(f, sortmap)
|
||||||
|
syncLock(f, sortmap)
|
||||||
|
iterTop(f, sortmap)
|
||||||
|
iterNext(f, sortmap)
|
||||||
|
// setup Sort() functions
|
||||||
|
if len(argv.Sort) == 0 {
|
||||||
|
// don't do any sorting
|
||||||
|
// setup Append() functions
|
||||||
|
if argv.Append == "" {
|
||||||
|
iterAppend(f, sortmap) // Append() enforce no unique keys
|
||||||
|
} else {
|
||||||
|
iterAppend(f, sortmap) // Append() enforce no unique keys
|
||||||
|
sortmap["append"] = argv.Append
|
||||||
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sortparts := strings.Split(argv.Sort[0], ",")
|
||||||
|
sortmap["sortBy"] = sortparts[0]
|
||||||
|
sortmap["sortKey"] = sortparts[1]
|
||||||
|
|
||||||
|
iterSort(f, sortmap)
|
||||||
|
|
||||||
|
if argv.Append == "" {
|
||||||
|
iterAppend(f, sortmap) // Append() enforce no unique keys
|
||||||
|
} else {
|
||||||
|
iterAppend(f, sortmap) // Append() enforce no unique keys
|
||||||
|
sortmap["append"] = argv.Append
|
||||||
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
||||||
|
}
|
||||||
|
sortmap["append"] = sortmap["sortKey"]
|
||||||
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
||||||
|
|
||||||
|
// add ReplaceKey()
|
||||||
|
iterDelete(f, sortmap)
|
||||||
|
iterReplace(f, sortmap)
|
||||||
|
}
|
||||||
|
iterEnd(f, sortmap)
|
||||||
|
}
|
||||||
|
|
||||||
func headerComment(w io.Writer) {
|
func headerComment(w io.Writer) {
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
fmt.Fprintln(w, "// this file was autogenerated with autogenpb")
|
fmt.Fprintln(w, "// this file was autogenerated with autogenpb")
|
||||||
|
|
Loading…
Reference in New Issue