almost done removing old map var
This commit is contained in:
parent
b111cdd1f9
commit
5bb3846a3b
2
argv.go
2
argv.go
|
@ -18,7 +18,7 @@ type args struct {
|
|||
Marshal []string `arg:"--marshal" help:"what to marshal on"`
|
||||
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"`
|
||||
Mutex bool `arg:"--mutex" help:"try mutex hack (breaks proto.Marshal() ???)"`
|
||||
Mutex bool `arg:"--mutex" default:"true" help:"add mutex in protoc autogen file"`
|
||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||
GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
|
||||
GoPath string `arg:"--gopath" help:"the gopath of this repo"`
|
||||
|
|
|
@ -22,5 +22,6 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
pf.iterSortBy(f)
|
||||
pf.iterAll(f)
|
||||
pf.iterDelete(f)
|
||||
pf.iterFind(f)
|
||||
return nil
|
||||
}
|
||||
|
|
90
sort.go
90
sort.go
|
@ -127,9 +127,6 @@ func (pf *File) iterSelect(w io.Writer) {
|
|||
fmt.Fprintln(w, "}")
|
||||
}
|
||||
|
||||
func iterAppend(w io.Writer, names map[string]string) {
|
||||
}
|
||||
|
||||
func (pf *File) appendUnique(w io.Writer) {
|
||||
var MSG string = pf.Bases.Name
|
||||
var BASE string = pf.Base.Name
|
||||
|
@ -196,38 +193,35 @@ func (pf *File) appendUnique(w io.Writer) {
|
|||
fmt.Fprintln(w, "")
|
||||
}
|
||||
|
||||
func iterReplace(w io.Writer, names map[string]string) {
|
||||
if names["append"] == "" {
|
||||
// can't continue without a key field
|
||||
}
|
||||
fmt.Fprintln(w, "// enforces "+names["append"]+" is unique")
|
||||
fmt.Fprintln(w, "func (all *"+names["Bases"]+") Replace"+names["append"]+"(newP *"+names["Base"]+") bool { // todo: make unique name here")
|
||||
func (pf *File) iterReplace(w io.Writer) {
|
||||
var MSG string = pf.Bases.Name
|
||||
var BASE string = pf.Base.Name
|
||||
var LOCK string = pf.Bases.Lockname
|
||||
|
||||
if sortmap["lock"] == "all" {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
||||
} else {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
||||
}
|
||||
for _, KEY := range pf.Base.Unique {
|
||||
fmt.Fprintln(w, "// enforces "+KEY+" is unique")
|
||||
fmt.Fprintln(w, "func (all *"+MSG+") Replace"+KEY+"(newP *"+BASE+") bool { // todo: make unique name here")
|
||||
fmt.Fprintln(w, " "+LOCK+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " for _, p := range all."+names["Bases"]+" {")
|
||||
fmt.Fprintln(w, " if p."+names["append"]+" == newP."+names["append"]+" {")
|
||||
fmt.Fprintln(w, " for _, p := range all."+MSG+" {")
|
||||
fmt.Fprintln(w, " if p."+KEY+" == newP."+KEY+" {")
|
||||
fmt.Fprintln(w, " return false")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " all."+names["Bases"]+" = append(all."+names["Bases"]+", newP)")
|
||||
fmt.Fprintln(w, " all."+MSG+" = append(all."+MSG+", newP)")
|
||||
fmt.Fprintln(w, " return true")
|
||||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
}
|
||||
}
|
||||
|
||||
func (pf *File) iterDelete(w io.Writer) {
|
||||
var MSG string = pf.Bases.Name
|
||||
var LOCK string = pf.Bases.Lockname
|
||||
|
||||
for _, KEY := range pf.Base.Sort {
|
||||
for _, KEY := range pf.Base.Unique {
|
||||
fmt.Fprintln(w, "func (all *"+MSG+") DeleteBy"+KEY+"(s string) bool {")
|
||||
fmt.Fprintln(w, " "+LOCK+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
|
||||
|
@ -246,23 +240,23 @@ func (pf *File) iterDelete(w io.Writer) {
|
|||
}
|
||||
|
||||
// this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct
|
||||
func iterDeleteWithCopy(w io.Writer, names map[string]string) {
|
||||
fmt.Fprintln(w, "func (all *"+names["Bases"]+") DeleteBy"+names["append"]+"(s string) *"+names["Base"]+" {")
|
||||
if sortmap["lock"] == "all" {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
||||
} else {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
||||
}
|
||||
func (pf *File) iterDeleteWithCopy(w io.Writer) {
|
||||
var MSG string = pf.Bases.Name
|
||||
var BASE string = pf.Base.Name
|
||||
var LOCK string = pf.Bases.Lockname
|
||||
|
||||
for _, KEY := range pf.Base.Unique {
|
||||
fmt.Fprintln(w, "func (all *"+MSG+") DeleteBy"+KEY+"(s string) *"+BASE+" {")
|
||||
fmt.Fprintln(w, " "+LOCK+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " var newr "+names["Base"])
|
||||
fmt.Fprintln(w, " var newr "+BASE)
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " for i, _ := range all."+names["Bases"]+" {")
|
||||
fmt.Fprintln(w, " if all."+names["Bases"]+"[i]."+names["append"]+" == s {")
|
||||
fmt.Fprintln(w, " newr = *all."+names["Bases"]+"[i]")
|
||||
fmt.Fprintln(w, " all."+names["Bases"]+"[i] = all."+names["Bases"]+"[len(all."+names["Bases"]+")-1]")
|
||||
fmt.Fprintln(w, " all."+names["Bases"]+" = all."+names["Bases"]+"[:len(all."+names["Bases"]+")-1]")
|
||||
fmt.Fprintln(w, " for i, _ := range all."+MSG+" {")
|
||||
fmt.Fprintln(w, " if all."+MSG+"[i]."+KEY+" == s {")
|
||||
fmt.Fprintln(w, " newr = *all."+MSG+"[i]")
|
||||
fmt.Fprintln(w, " all."+MSG+"[i] = all."+MSG+"[len(all."+MSG+")-1]")
|
||||
fmt.Fprintln(w, " all."+MSG+" = all."+MSG+"[:len(all."+MSG+")-1]")
|
||||
fmt.Fprintln(w, " return &newr")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " }")
|
||||
|
@ -270,28 +264,30 @@ func iterDeleteWithCopy(w io.Writer, names map[string]string) {
|
|||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
}
|
||||
}
|
||||
|
||||
func iterFind(w io.Writer, names map[string]string) {
|
||||
func (pf *File) iterFind(w io.Writer) {
|
||||
var MSG string = pf.Bases.Name
|
||||
var BASE string = pf.Base.Name
|
||||
var LOCK string = pf.Bases.Lockname
|
||||
|
||||
for _, KEY := range pf.Base.Unique {
|
||||
fmt.Fprintln(w, "// find a dependancy by the go path")
|
||||
fmt.Fprintln(w, "func (all *"+names["Bases"]+") FindBy"+names["append"]+"(s string) *"+names["Base"]+" {")
|
||||
fmt.Fprintln(w, "func (all *"+MSG+") FindBy"+KEY+"(s string) *"+BASE+" {")
|
||||
fmt.Fprintln(w, " if all == nil {")
|
||||
fmt.Fprintln(w, " return nil")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, "")
|
||||
if sortmap["lock"] == "all" {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
||||
} else {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
||||
}
|
||||
fmt.Fprintln(w, " "+LOCK+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " for i, _ := range all."+names["Bases"]+" {")
|
||||
fmt.Fprintln(w, " if all."+names["Bases"]+"[i]."+names["append"]+" == s {")
|
||||
fmt.Fprintln(w, " return all."+names["Bases"]+"[i]")
|
||||
fmt.Fprintln(w, " for i, _ := range all."+MSG+" {")
|
||||
fmt.Fprintln(w, " if all."+MSG+"[i]."+KEY+" == s {")
|
||||
fmt.Fprintln(w, " return all."+MSG+"[i]")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " return nil")
|
||||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue