good stuff. Find() seems to work
This commit is contained in:
parent
8ac4d90c22
commit
2394b2c055
10
generate.go
10
generate.go
|
@ -275,9 +275,17 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range msg.Vars {
|
for _, v := range msg.Vars {
|
||||||
|
if v.IsRepeated {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if v.HasUnique {
|
if v.HasUnique {
|
||||||
funcname = "func (x *" + PARENT + ") Find" + VARNAME + "By" + v.VarName + "(a " + v.VarType + ") *" + s.VarType + "(using" + v.VarName + ")"
|
funcname = "func (x *" + PARENT + ") Find" + VARNAME + "By" + v.VarName + "(a " + v.VarType + ") *" + s.VarType + "(using" + v.VarName + ")"
|
||||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||||
|
|
||||||
|
FUNCNAME := "Find" + VARNAME + "By" + v.VarName
|
||||||
|
funcdef := msg.generateFindBy(wSort, FUNCNAME, PARENT, VARNAME, s.VarType, v.VarName)
|
||||||
|
// func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string {
|
||||||
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "done", "", funcdef)
|
||||||
} else {
|
} else {
|
||||||
if v.VarType == "string" {
|
if v.VarType == "string" {
|
||||||
funcname = "func (x *" + PARENT + ") Find" + VARNAME + "By" + v.VarName + "(a string) []*" + s.VarType + " ???"
|
funcname = "func (x *" + PARENT + ") Find" + VARNAME + "By" + v.VarName + "(a string) []*" + s.VarType + " ???"
|
||||||
|
@ -387,6 +395,7 @@ func (pf *File) processMessage(parent *MsgName, wSort, wFind io.Writer) error {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
func (parent *MsgName) addFindByMsg(w io.Writer, FRUIT, APPLES, APPLE, LOCK string) {
|
func (parent *MsgName) addFindByMsg(w io.Writer, FRUIT, APPLES, APPLE, LOCK string) {
|
||||||
for _, v := range parent.Vars {
|
for _, v := range parent.Vars {
|
||||||
if v.HasUnique {
|
if v.HasUnique {
|
||||||
|
@ -396,6 +405,7 @@ func (parent *MsgName) addFindByMsg(w io.Writer, FRUIT, APPLES, APPLE, LOCK stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func (parent *MsgName) addDeleteByMsg(w io.Writer, FRUIT, APPLES, APPLE string) {
|
func (parent *MsgName) addDeleteByMsg(w io.Writer, FRUIT, APPLES, APPLE string) {
|
||||||
|
|
|
@ -18,9 +18,12 @@ func (msg *MsgName) getLockname(s string) string {
|
||||||
return msg.Lockname
|
return msg.Lockname
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateFindBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, LOCK string) {
|
func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string {
|
||||||
fmt.Fprintln(w, "// lookup a", FRUIT, "by the ", COLOR)
|
LOCK := msg.getLockname("x")
|
||||||
fmt.Fprintln(w, "func (x *"+FRUIT+") FindBy"+COLOR+"(s string) *"+APPLE+" {")
|
funcdef := "func (x *" + STRUCT + ") " + FUNCNAME + "(s string) *" + VARTYPE
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "// lookup a", STRUCT, "by the ", COLOR)
|
||||||
|
fmt.Fprintln(w, funcdef, "{")
|
||||||
fmt.Fprintln(w, " if x == nil {")
|
fmt.Fprintln(w, " if x == nil {")
|
||||||
fmt.Fprintln(w, " return nil")
|
fmt.Fprintln(w, " return nil")
|
||||||
fmt.Fprintln(w, " }")
|
fmt.Fprintln(w, " }")
|
||||||
|
@ -28,14 +31,16 @@ func generateFindBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, LOCK string) {
|
||||||
fmt.Fprintln(w, " "+LOCK+".RLock()")
|
fmt.Fprintln(w, " "+LOCK+".RLock()")
|
||||||
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
|
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
fmt.Fprintln(w, " for i, _ := range x."+APPLES+" {")
|
fmt.Fprintln(w, " for i, _ := range x."+VARNAME+" {")
|
||||||
fmt.Fprintln(w, " if x."+APPLES+"[i]."+COLOR+" == s {")
|
fmt.Fprintln(w, " if x."+VARNAME+"[i]."+COLOR+" == s {")
|
||||||
fmt.Fprintln(w, " return x."+APPLES+"[i]")
|
fmt.Fprintln(w, " return x."+VARNAME+"[i]")
|
||||||
fmt.Fprintln(w, " }")
|
fmt.Fprintln(w, " }")
|
||||||
fmt.Fprintln(w, " }")
|
fmt.Fprintln(w, " }")
|
||||||
fmt.Fprintln(w, " return nil")
|
fmt.Fprintln(w, " return nil")
|
||||||
fmt.Fprintln(w, "}")
|
fmt.Fprintln(w, "}")
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
|
|
||||||
|
return funcdef
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *MsgName) deleteBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, VARNAME string) string {
|
func (msg *MsgName) deleteBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, VARNAME string) string {
|
||||||
|
|
Loading…
Reference in New Issue