autogenpb/main.go

35 lines
809 B
Go

package main
import (
"fmt"
"io"
"os"
)
func main() {
f, _ := os.OpenFile("test.sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600)
header(f, "autogenpb")
syncLock(f, "godeplock")
}
func header(w io.Writer, name string) {
fmt.Fprintln(w, "package " + name)
fmt.Fprintln(w, "")
fmt.Fprintln(w, "// this is becoming a standard format")
fmt.Fprintln(w, "// todo: autogenerate this from the .proto file?")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "import (")
fmt.Fprintln(w, " \"fmt\"")
fmt.Fprintln(w, " \"os\"")
fmt.Fprintln(w, " \"sort\"")
fmt.Fprintln(w, " \"sync\"")
fmt.Fprintln(w, ")")
fmt.Fprintln(w, "")
}
func syncLock(w io.Writer, name string) {
fmt.Fprintln(w, "// bad global lock until I figure out some other plan")
fmt.Fprintln(w, "var " + name + " sync.RWMutex")
fmt.Fprintln(w, "")
}