From d413f6730277fa81dadf1b07a0a402ae95ffc00f Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Fri, 13 Jul 2018 11:00:35 +0700 Subject: [PATCH] Minor cleanup to client/gen.go --- client/gen.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/client/gen.go b/client/gen.go index 35ed799..4cad52e 100644 --- a/client/gen.go +++ b/client/gen.go @@ -26,17 +26,26 @@ const ( var ( flagOut = flag.String("out", "targettype.go", "out file") - - typeAsStringRE = regexp.MustCompile(`type_as_string\s+==\s+"([^"]+)"`) ) func main() { flag.Parse() + if err := run(); err != nil { + log.Fatal(err) + } +} + +var typeAsStringRE = regexp.MustCompile(`type_as_string\s+==\s+"([^"]+)"`) + +// run executes the generator. +func run() error { + var err error + // grab source buf, err := grab(devtoolsHTTPClientCc) if err != nil { - log.Fatal(err) + return err } // find names @@ -55,15 +64,11 @@ func main() { decodeVals += fmt.Sprintf("case %s:\n*tt=%s\n", name, name) } - err = ioutil.WriteFile(*flagOut, []byte(fmt.Sprintf(targetTypeSrc, constVals, decodeVals)), 0644) - if err != nil { - log.Fatal(err) + if err = ioutil.WriteFile(*flagOut, []byte(fmt.Sprintf(targetTypeSrc, constVals, decodeVals)), 0644); err != nil { + return err } - err = exec.Command("gofmt", "-w", "-s", *flagOut).Run() - if err != nil { - log.Fatal(err) - } + return exec.Command("gofmt", "-w", "-s", *flagOut).Run() } // grab retrieves a file from the chromium source code.