summaryrefslogtreecommitdiff
path: root/main.go
blob: fb2ea38d50142d9233fdabdfada15ecfa56df7b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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, "")
}