// copied from pkg/net_linux.go
160154
func linkFlags(rawFlags uint32) net.Flags {
	var f net.Flags
	if rawFlags&unix.IFF_UP != 0 {
		f |= net.FlagUp
	}
	if rawFlags&unix.IFF_BROADCAST != 0 {
		f |= net.FlagBroadcast
	}
	if rawFlags&unix.IFF_LOOPBACK != 0 {
		f |= net.FlagLoopback
	}
	if rawFlags&unix.IFF_POINTOPOINT != 0 {
		f |= net.FlagPointToPoint
	}
	if rawFlags&unix.IFF_MULTICAST != 0 {
		f |= net.FlagMulticast
	}
	return f
}
583016
func main() {
	var (
		lintArgs       string
		lintBin        string
		packageList    string
		output         string
		packages       []string
		results        []*result
		hasFailingTest bool

		gopath = os.Getenv("GOPATH")
	)

	flag.StringVar(&lintArgs, "lintArgs", "", "args to pass to gometalinter")
	flag.StringVar(&lintBin, "lintBin", filepath.Join(gopath, "bin", "gometalinter"), "path to go metalinter")
	flag.StringVar(&packageList, "packages", "", "list of space separated packages")
	flag.StringVar(&output, "output", "", "output file for to write results.")
	flag.Parse()

	packages = strings.Split(strings.Replace(packageList, "-", "/", -1), " ")
	dirname, _ := os.Getwd()
	cwd := filepath.Base(dirname)
	gopath, _ = filepath.Abs(gopath)
	lintArgs += fmt.Sprintf(" --concurrency=%d", runtime.NumCPU()/2)

	for _, pkg := range packages {
		args := []string{lintBin, lintArgs}
		if cwd == pkg {
			args = append(args, ".")
		} else {
			args = append(args, "./"+pkg)
		}

		startAt := time.Now()
		cmd := strings.Join(args, " ")
		out, err := exec.Command("sh", "-c", cmd).CombinedOutput()

		r := &result{
			cmd:      strings.Join(args, " "),
			name:     "lint-" + strings.Replace(pkg, "/", "-", -1),
			passed:   err == nil,
			duration: time.Since(startAt),
			output:   strings.Split(string(out), "\n"),
		}
		r.fixup(dirname)

		if !r.passed {
			hasFailingTest = true
		}

		results = append(results, r)
		fmt.Println(r)
	}

	if output != "" {
		f, err := os.Create(output)
		if err != nil {
			os.Exit(1)
		}
		defer func() {
			if err != f.Close() {
				panic(err)
			}
		}()

		for _, r := range results {
			f.WriteString(r.String() + "\n")
		}
	}

	if hasFailingTest {
		os.Exit(1)
	}
}
196543
func main() {
	app := cli.NewApp()
	app.Name = path.Base(os.Args[0])
	app.Author = "Manfred Touron"
	app.Email = "https://github.com/moul"
	app.Version = "1.0.0-dev"
	app.Usage = "Anonymize UUIDs outputs"

	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "hexspeak",
			Usage: "Generate hexspeak style fake UUIDs",
		},
		cli.BoolFlag{
			Name:  "random, r",
			Usage: "Generate random fake UUIDs",
		},
		cli.BoolFlag{
			Name:  "keep-beginning",
			Usage: "Keep first part of the UUID unchanged",
		},
		cli.BoolFlag{
			Name:  "keep-end",
			Usage: "Keep last part of the UUID unchanged",
		},
		cli.StringFlag{
			Name:  "prefix, p",
			Usage: "Prefix generated UUIDs",
		},
		cli.StringFlag{
			Name:  "suffix",
			Usage: "Suffix generated UUIDs",
		},
	}

	app.Action = action
	app.Run(os.Args)
}
41557
func (pkg *Package) Binfile() string {
	target := filepath.Join(pkg.bindir(), pkg.binname())

	// if this is a cross compile or GOOS/GOARCH are both defined or there are build tags, add ctxString.
	if pkg.isCrossCompile() || (os.Getenv("GOOS") != "" && os.Getenv("GOARCH") != "") {
		target += "-" + pkg.ctxString()
	} else if len(pkg.buildtags) > 0 {
		target += "-" + strings.Join(pkg.buildtags, "-")
	}

	if pkg.gotargetos == "windows" {
		target += ".exe"
	}
	return target
}
144512
func goFmtPackage(pkg *build.Package) {
	output, err := exec.Command("go", "fmt", pkg.ImportPath).Output()

	if err != nil {
		fmt.Printf("Warning: Error running 'go fmt %s'.\nstdout: %s\n%s\n", pkg.ImportPath, output, err.Error())
	}
}
393223
func main() {
	r.Sync = make(chan string)
	app := &cli.App{
		Name:        strings.Title(realize.RPrefix),
		Version:     realize.RVersion,
		Description: "Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.",
		Commands: []*cli.Command{
			{
				Name:        "start",
				Aliases:     []string{"s"},
				Description: "Start " + strings.Title(realize.RPrefix) + " on a given path. If not exist a config file it creates a new one.",
				Flags: []cli.Flag{
					&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: ".", Usage: "Project base path"},
					&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: "", Usage: "Run a project by its name"},
					&cli.BoolFlag{Name: "fmt", Aliases: []string{"f"}, Value: false, Usage: "Enable go fmt"},
					&cli.BoolFlag{Name: "vet", Aliases: []string{"v"}, Value: false, Usage: "Enable go vet"},
					&cli.BoolFlag{Name: "test", Aliases: []string{"t"}, Value: false, Usage: "Enable go test"},
					&cli.BoolFlag{Name: "generate", Aliases: []string{"g"}, Value: false, Usage: "Enable go generate"},
					&cli.BoolFlag{Name: "server", Aliases: []string{"srv"}, Value: false, Usage: "Start server"},
					&cli.BoolFlag{Name: "open", Aliases: []string{"op"}, Value: false, Usage: "Open into the default browser"},
					&cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install"},
					&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build"},
					&cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"},
					&cli.BoolFlag{Name: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Legacy watch by polling instead fsnotify"},
					&cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing config and doesn't create a new one"},
				},
				Action: start,
			},
			{
				Name:        "add",
				Category:    "Configuration",
				Aliases:     []string{"a"},
				Description: "Add a project to an existing config or to a new one.",
				Flags: []cli.Flag{
					&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: realize.Wdir(), Usage: "Project base path"},
					&cli.BoolFlag{Name: "fmt", Aliases: []string{"f"}, Value: false, Usage: "Enable go fmt"},
					&cli.BoolFlag{Name: "vet", Aliases: []string{"v"}, Value: false, Usage: "Enable go vet"},
					&cli.BoolFlag{Name: "test", Aliases: []string{"t"}, Value: false, Usage: "Enable go test"},
					&cli.BoolFlag{Name: "generate", Aliases: []string{"g"}, Value: false, Usage: "Enable go generate"},
					&cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install"},
					&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build"},
					&cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"},
				},
				Action: add,
			},
			{
				Name:        "init",
				Category:    "Configuration",
				Aliases:     []string{"i"},
				Description: "Make a new config file step by step.",
				Action:      setup,
			},
			{
				Name:        "remove",
				Category:    "Configuration",
				Aliases:     []string{"r"},
				Description: "Remove a project from an existing config.",
				Flags: []cli.Flag{
					&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: ""},
				},
				Action: remove,
			},
			{
				Name:        "clean",
				Category:    "Configuration",
				Aliases:     []string{"c"},
				Description: "Remove " + strings.Title(realize.RPrefix) + " folder.",
				Action: func(c *cli.Context) error {
					return clean()
				},
			},
			{
				Name:        "version",
				Aliases:     []string{"v"},
				Description: "Print " + strings.Title(realize.RPrefix) + " version.",
				Action: func(p *cli.Context) error {
					version()
					return nil
				},
			},
		},
	}
	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}
547737
func init() {
	gob.Register([]interface{}{})
	gob.Register(map[string]interface{}{})
	gob.Register([]map[string]string{})
	gob.Register([]map[string]int{})
	gob.Register(syscall.Signal(0x1))
}
550708
func main() {
	g := generator.New()

	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		failWithError(err, "reading input")
	}

	if err := proto.Unmarshal(data, g.Request); err != nil {
		failWithError(err, "parsing input proto")
	}

	if len(g.Request.FileToGenerate) == 0 {
		fail("no files to generate")
	}

	g.CommandLineParameters(g.Request.GetParameter())

	if val, ok := g.Param["logtostderr"]; ok && val == "true" {
		logtostderr = true
	}

	tree := buildTree(g.Request.GetProtoFile())

	packageLocations := make(map[string]string)
	for _, file := range g.Request.GetProtoFile() {
		loc := file.GetName()[:strings.LastIndex(file.GetName(), "/")]
		packageLocations[file.GetPackage()] = loc
	}

	selectedServices := make(map[string]string)
	for k, v := range g.Param {
		switch {
		case k == "logtostderr":
			if v == "true" {
				logtostderr = true
			}
		case strings.HasPrefix(k, "."):
			selectedServices[k] = v
		}
	}

	for serviceKey := range selectedServices {
		service, ok := tree.services[serviceKey]
		if !ok {
			fail("Service", serviceKey, "unknown")
		}

		usedMessages := make(map[string]*message)
		usedEnums := make(map[string]*enum)

		content := new(bytes.Buffer)

		fmt.Fprintf(content, "# %s API Reference\n\n", service.GetName())
		if service.comment != "" {
			fmt.Fprintf(content, "%s\n\n", service.comment)
		}

		if len(service.methods) > 0 {
			fmt.Fprint(content, "## Methods\n\n")

			for _, method := range service.methods {
				fmt.Fprintf(content, "### `%s`\n\n", method.GetName())
				if method.comment != "" {
					fmt.Fprintf(content, "%s\n\n", method.comment)
				}
				if method.inputStream {
					fmt.Fprintf(content, "- Client stream of [`%s`](#%s)\n", method.input.GetName(), heading(method.input.key))
				} else {
					fmt.Fprintf(content, "- Request: [`%s`](#%s)\n", method.input.GetName(), heading(method.input.key))
				}
				useMessage(tree, method.input, usedMessages, usedEnums)
				if method.outputStream {
					fmt.Fprintf(content, "- Server stream of [`%s`](#%s)\n", method.output.GetName(), heading(method.input.key))
				} else {
					fmt.Fprintf(content, "- Response: [`%s`](#%s)\n", method.output.GetName(), heading(method.input.key))
				}
				useMessage(tree, method.output, usedMessages, usedEnums)

				fmt.Fprintln(content)

				if len(method.endpoints) != 0 {
					if len(method.endpoints) == 1 {
						fmt.Fprint(content, "#### HTTP Endpoint\n\n")
					} else {
						fmt.Fprint(content, "#### HTTP Endpoints\n\n")
					}
					for _, endpoint := range method.endpoints {
						fmt.Fprintf(content, "- `%s` `%s`", endpoint.method, endpoint.url)
						var params []string
						for _, match := range regexp.MustCompile(`\{([a-z_]+)\}`).FindAllStringSubmatch(endpoint.url, -1) {
							if match != nil && len(match) == 2 && match[1] != "" {
								params = append(params, fmt.Sprintf("`%s`", match[1]))
							}
						}
						if len(params) > 0 {
							fmt.Fprintf(content, "(%s can be left out of the request body)", strings.Join(params, ", "))
						}
						fmt.Fprintln(content)
					}
					fmt.Fprintln(content)

					fmt.Fprint(content, "#### JSON Request Format\n\n")
					fmt.Fprintf(content, "```json\n%s\n```\n\n", method.input.JSONExample(tree))

					fmt.Fprint(content, "#### JSON Response Format\n\n")
					fmt.Fprintf(content, "```json\n%s\n```\n\n", method.output.JSONExample(tree))
				}
			}
		}

		if len(usedMessages) > 0 {
			fmt.Fprint(content, "## Messages\n\n")

			var messageKeys []string
			for key := range usedMessages {
				messageKeys = append(messageKeys, key)
			}
			sort.Strings(messageKeys)

			for _, messageKey := range messageKeys {
				message := usedMessages[messageKey]
				fmt.Fprintf(content, "### `%s`\n\n", message.key)
				if strings.HasPrefix(messageKey, ".google") {
					fmt.Fprintf(content, "%s\n\n", strings.SplitAfter(message.comment, ".")[0])
				} else if message.comment != "" {
					fmt.Fprintf(content, "%s\n\n", message.comment)
				}
				if len(message.fields) > 0 {
					fmt.Fprintln(content, "| Field Name | Type | Description |")
					fmt.Fprintln(content, "| ---------- | ---- | ----------- |")
					for idx, field := range message.fields {
						if field.isOneOf {
							if idx == 0 || !message.fields[idx-1].isOneOf || message.fields[idx-1].GetOneofIndex() != field.GetOneofIndex() {
								oneof := message.GetOneof(field.GetOneofIndex())
								if len(oneof.fields) > 1 {
									fmt.Fprintf(content, "| **%s** | **oneof %d** | one of the following %d |\n", oneof.GetName(), len(oneof.fields), len(oneof.fields))
								}
							}
						} else {
							if idx > 0 && message.fields[idx-1].isOneOf {
								oneof := message.GetOneof(message.fields[idx-1].GetOneofIndex())
								if len(oneof.fields) > 1 {
									fmt.Fprintf(content, "| **%s** | **end oneof %d** |  |\n", oneof.GetName(), len(oneof.fields))
								}
							}
						}

						var fieldType string
						if field.repeated {
							fieldType += "_repeated_ "
						}
						typ := strings.ToLower(strings.TrimPrefix(field.GetType().String(), "TYPE_"))
						switch typ {
						case "message":
							friendlyType := field.GetTypeName()[strings.LastIndex(field.GetTypeName(), ".")+1:]
							fieldType += fmt.Sprintf("[`%s`](#%s)", friendlyType, heading(field.GetTypeName()))
						case "enum":
							// TODO(htdvisser): test this
							if enum, ok := tree.enums[field.GetTypeName()]; ok {
								usedEnums[field.GetTypeName()] = enum
							}
							friendlyType := field.GetTypeName()[strings.LastIndex(field.GetTypeName(), ".")+1:]
							fieldType += fmt.Sprintf("[`%s`](#%s)", friendlyType, heading(field.GetTypeName()))
						default:
							fieldType += fmt.Sprintf("`%s`", typ)
						}
						fmt.Fprintf(content, "| `%s` | %s | %s |\n", field.GetName(), fieldType, strings.Replace(field.comment, "\n", " ", -1))
					}
					fmt.Fprintln(content)
				}
			}
		}

		if len(usedEnums) > 0 {
			fmt.Fprint(content, "## Used Enums\n\n")

			var enumKeys []string
			for key := range usedEnums {
				enumKeys = append(enumKeys, key)
			}
			sort.Strings(enumKeys)

			for _, enumKey := range enumKeys {
				enum := usedEnums[enumKey]

				fmt.Fprintf(content, "### `%s`\n\n", enum.key)
				if enum.comment != "" {
					fmt.Fprintf(content, "%s\n\n", enum.comment)
				}

				if len(enum.values) > 0 {
					fmt.Fprintln(content, "| Value | Description |")
					fmt.Fprintln(content, "| ----- | ----------- |")
					for _, value := range enum.values {
						fmt.Fprintf(content, "| `%s` | %s |\n", value.GetName(), strings.Replace(value.comment, "\n", " ", -1))
					}
					fmt.Fprintln(content)
				}
			}
		}

		packageService := strings.TrimPrefix(service.key, ".")
		packageName := packageService[:strings.Index(packageService, ".")]
		location, ok := packageLocations[packageName]
		if !ok {
			fail("Could not find location of package", packageName)
		}
		fileName := path.Join(location, service.GetName()+".md")
		contentString := content.String()
		g.Response.File = append(g.Response.File, &plugin.CodeGeneratorResponse_File{
			Name:    &fileName,
			Content: &contentString,
		})
	}

	// Send back the results.
	data, err = proto.Marshal(g.Response)
	if err != nil {
		failWithError(err, "failed to marshal output proto")
	}
	_, err = os.Stdout.Write(data)
	if err != nil {
		failWithError(err, "failed to write output proto")
	}
}
273067
func (lh *GoLangHelper) PreBuild() error {
	wd, err := os.Getwd()
	if err != nil {
		return err
	}
	// todo: this won't work if the function is more complex since the import paths won't match up, need to fix
	pbcmd := fmt.Sprintf("docker run --rm -v %s:/go/src/github.com/x/y -w /go/src/github.com/x/y iron/go:dev go build -o func", wd)
	fmt.Println("Running prebuild command:", pbcmd)
	parts := strings.Fields(pbcmd)
	head := parts[0]
	parts = parts[1:len(parts)]
	cmd := exec.Command(head, parts...)
	// cmd.Dir = dir
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	if err := cmd.Run(); err != nil {
		return fmt.Errorf("error running docker build: %v", err)
	}
	return nil
}
1158181
func (c *Client) LinodeConfigCreate(linodeID int, kernelID int, label string,
	diskList string, conf LinodeConfigCreateOpts) (configID int, err error) {

	args, err := c.argMarshal(conf)
	if err != nil {
		return 0, err
	}
	args["LinodeID"] = linodeID
	args["KernelID"] = kernelID
	args["Label"] = label
	args["DiskList"] = diskList

	data, err := c.apiCall("linode.config.create", args)
	if err != nil {
		return 0, err
	}

	err = unmarshalSingle(data, "ConfigID", &configID)
	if err != nil {
		return 0, err
	}

	return configID, nil
}
1030925
func main() {
	flag.Parse()
	if len(flag.Args()) == 0 {
		panic(fmt.Errorf("arch is required"))
	}

	for _, arch := range flag.Args() {
		wd, err := os.Getwd()
		if err != nil {
			panic(err)
		}
		f, err := os.Open(filepath.Join(wd, arch))
		if err != nil {
			panic(err)
		}
		defer f.Close()
		buf := &bytes.Buffer{}

		gz, err := gzip.NewWriterLevel(newHexStringWriter(buf), gzip.BestCompression)
		if err != nil {
			panic(err)
		}
		if _, err = io.Copy(gz, f); err != nil {
			panic(err)
		}
		if err := gz.Close(); err != nil {
			panic(err)
		}

		fn := filepath.Join(wd, arch+"_binary.go")
		dest, err := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
		if err != nil {
			panic(err)
		}
		if err := tmpl.Execute(dest, struct{ Arch, Package, Data string }{Arch: arch, Package: "binfmt_misc", Data: buf.String()}); err != nil {
			panic(err)
		}
		dest.Close()
	}

}
150949
func main() {
	q, err := netfilter.New(0, 100, netfilter.NF_DEFAULT_PACKET_SIZE)
	onErrorExit(err)

	pp := 0

	onInterruptSignal(func() {
		q.Close()
		log.Printf("\n%d packets processed", pp)
		os.Exit(0)
	})

	go q.Run()

	pChan := q.Packets()

	for p := range pChan {
		q.SetVerdict(p, netfilter.NF_ACCEPT)
		pp++
	}
}
246822
func main() {
    // Get Udp data, you can use GOnetstat.Tcp() to get TCP data
     d := GOnetstat.Udp()

     // format header
     fmt.Printf("Proto %16s %20s %14s %24s\n", "Local Adress", "Foregin Adress",
                "State", "Pid/Program")

     for _, p := range(d) {
        // format data like netstat output
        ip_port := fmt.Sprintf("%v:%v", p.Ip, p.Port)
        fip_port := fmt.Sprintf("%v:%v", p.ForeignIp, p.ForeignPort)
        pid_program := fmt.Sprintf("%v/%v", p.Pid, p.Name)

        fmt.Printf("udp %16v %20v %16v %20v\n", ip_port, fip_port,
                            p.State, pid_program)
     }
}
766254
func main() {
	flag.Parse()

	// set the log level to Trace
	log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(false))))

	// register a single ping-pong service
	services := map[string]adapters.ServiceFunc{
		"ping-pong": func(ctx *adapters.ServiceContext) (node.Service, error) {
			return newPingPongService(ctx.Config.ID), nil
		},
	}
	adapters.RegisterServices(services)

	// create the NodeAdapter
	var adapter adapters.NodeAdapter

	switch *adapterType {

	case "sim":
		log.Info("using sim adapter")
		adapter = adapters.NewSimAdapter(services)

	case "exec":
		tmpdir, err := ioutil.TempDir("", "p2p-example")
		if err != nil {
			log.Crit("error creating temp dir", "err", err)
		}
		defer os.RemoveAll(tmpdir)
		log.Info("using exec adapter", "tmpdir", tmpdir)
		adapter = adapters.NewExecAdapter(tmpdir)

	default:
		log.Crit(fmt.Sprintf("unknown node adapter %q", *adapterType))
	}

	// start the HTTP API
	log.Info("starting simulation server on 0.0.0.0:8888...")
	network := simulations.NewNetwork(adapter, &simulations.NetworkConfig{
		DefaultService: "ping-pong",
	})
	if err := http.ListenAndServe(":8888", simulations.NewServer(network)); err != nil {
		log.Crit("error starting simulation server", "err", err)
	}
}
17673
func libgcc(ctx *Context) (string, error) {
	args := []string{
		"-print-libgcc-file-name",
	}
	var buf bytes.Buffer
	cmd := gccCmd(&Package{Context: ctx}, "") // TODO(dfc) hack
	err := runOut(&buf, ".", nil, cmd[0], args...)
	return strings.TrimSpace(buf.String()), err
}
741756
func Bin(product string) (string, error) {
	godelw, err := newGodelwRunner()
	if err != nil {
		return "", err
	}

	// return error if version is too new
	majorVersion, err := majorVersion(godelw)
	if err != nil {
		return "", err
	}
	if majorVersion >= 2 {
		return "", fmt.Errorf("this package does not support godel with major version >=2, but was %d: use v2 of the library instead", majorVersion)
	}

	currOSArchFlag := fmt.Sprintf("--os-arch=%s-%s", runtime.GOOS, runtime.GOARCH)
	requiresBuildOutput, err := godelw.run("artifacts", "build", "--absolute", currOSArchFlag, "--requires-build", product)
	if err != nil {
		return "", err
	}
	if requiresBuildOutput != "" {
		if _, err := godelw.run("build", currOSArchFlag, product); err != nil {
			return "", err
		}
	}
	binPath, err := godelw.run("artifacts", "build", "--absolute", currOSArchFlag, product)
	if err != nil {
		return "", err
	}
	if binPath == "" {
		return "", fmt.Errorf("no build artifact for product %s with GOOS %s and GOARCH %s", product, runtime.GOOS, runtime.GOARCH)
	}
	return binPath, nil
}
58156
func main() {
	rules := filepath.Join(strings.Split(os.Getenv("GOPATH"), ":")[0], "src/github.com/vube/i18n/data/rules")
	err := filepath.Walk(rules, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			panic(err)
		}
		if info.IsDir() {
			return nil
		}
		in, err := ioutil.ReadFile(path)
		if err != nil {
			panic(err)
		}
		var out yaml.MapSlice
		if err = yaml.Unmarshal(in, &out); err != nil {
			panic(err)
		}
		var plural string
		for _, item := range out {
			if item.Key == "plural" {
				plural = item.Value.(string)
			}
		}
		if plural == "" {
			fmt.Println("can't find plurals in", path)
			return nil
		}
		locale := strings.Replace(info.Name(), filepath.Ext(info.Name()), "", 1)
		locale = strings.Replace(locale, "-", "_", -1)
		dir := "resources/locales/" + locale
		if _, err := os.Stat(dir); err != nil {
			fmt.Println(dir, "doesn't exist")
			return nil
		}
		file, err := os.Create(dir + "/plural.go")
		if err != nil {
			panic(err)
		}
		rawcodes := fmt.Sprintf(`package %s

		var pluralRule = %q
		`, locale, plural)
		var codes []byte
		if codes, err = format.Source([]byte(rawcodes)); err != nil {
			panic(err)
		}
		if _, err := file.Write(codes); err != nil {
			panic(err)
		}
		return nil
	})
	if err != nil {
		panic(err)
	}
}