diff options
Diffstat (limited to 'sort.go')
| -rw-r--r-- | sort.go | 31 |
1 files changed, 28 insertions, 3 deletions
@@ -58,11 +58,18 @@ func makeSortfile() { func headerComment(w io.Writer) { fmt.Fprintln(w, "") - fmt.Fprintln(w, "// this file was autogenerated with autogenpb") + fmt.Fprintln(w, "// This file was autogenerated with autogenpb.") + fmt.Fprintln(w, "// go install go.wit.com/apps/autogenpb@latest") fmt.Fprintln(w, "//") - fmt.Fprintln(w, "// you might be able to use it on simple, strictly defined protobuf files") + fmt.Fprintln(w, "// You can use it on simple protobuf files") + fmt.Fprintln(w, "// The .proto file must have a singular and plural form of a message") + fmt.Fprintln(w, "// (for those of you that know ruby on rails, it's like that)") + fmt.Fprintln(w, "//") + fmt.Fprintln(w, "// You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for") + fmt.Fprintln(w, "//") + fmt.Fprintln(w, "// For an example,") + fmt.Fprintln(w, "// go-clone go.wit.com/lib/protobuf/gitpb") fmt.Fprintln(w, "//") - fmt.Fprintln(w, "// go install go.wit.com/apps/autogenpb@latest") fmt.Fprintln(w, "") } @@ -238,6 +245,24 @@ func iterReplace(w io.Writer, names map[string]string) { } func iterDelete(w io.Writer, names map[string]string) { + fmt.Fprintln(w, "func (all *"+names["Bases"]+") DeleteBy"+names["append"]+"(s string) bool {") + fmt.Fprintln(w, " "+names["lock"]+".Lock()") + fmt.Fprintln(w, " defer "+names["lock"]+".Unlock()") + 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, " 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, " return true") + fmt.Fprintln(w, " }") + fmt.Fprintln(w, " }") + fmt.Fprintln(w, " return false") + fmt.Fprintln(w, "}") + fmt.Fprintln(w, "") +} + +// 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"]+" {") fmt.Fprintln(w, " "+names["lock"]+".Lock()") fmt.Fprintln(w, " defer "+names["lock"]+".Unlock()") |
