// protoc executes the "protoc" command on files named in fnames,
// passing go_out and include flags specified in goOut and includes respectively.
// protoc returns combined output from stdout and stderr.
772357
func protoc(goOut string, includes, fnames []string) ([]byte, error) {
	args := []string{"--go_out=plugins=grpc:" + goOut}
	for _, inc := range includes {
		args = append(args, "-I", inc)
	}
	args = append(args, fnames...)
	return exec.Command("protoc", args...).CombinedOutput()
}
1293712
func Proto(rw http.ResponseWriter, status int, pb proto.Message) error {
	rw.Header().Set("Content-Type", "application/json")
	rw.WriteHeader(status)
	return jpb.Marshal(rw, pb)
}
591897
func proc(env, path string) string {
	// try to read full file path
	if p := os.Getenv(env); p != "" {
		return p
	}
	// return default path
	return path
}
809587
func (c *hookCmd) runGofmt() (files []string, err error) {
	repo, err := repoRoot()
	if err != nil {
		return nil, err
	}
	if !strings.HasSuffix(repo, string(filepath.Separator)) {
		repo += string(filepath.Separator)
	}

	out, err := cmdOutputDirErr(".", "git", "diff-index", "--name-only", "--diff-filter=ACM", "--cached", "HEAD", "--", ":(glob)**/*.go", ":!/vendor/")
	if err != nil {
		return nil, err
	}
	indexFiles := addRoot(repo, nonBlankLines(out))
	if len(indexFiles) == 0 {
		return
	}

	args := []string{"-l"}
	// TODO(mpl): it would be nice to TrimPrefix the pwd from each file to get a shorter output.
	// However, since git sets the pwd to GIT_DIR before running the pre-commit hook, we lost
	// the actual pwd from when we ran `git commit`, so no dice so far.
	for _, file := range indexFiles {
		args = append(args, file)
	}

	if c.verbose {
		fmt.Fprintln(cmdmain.Stderr, commandString("gofmt", args))
	}
	cmd := exec.Command("gofmt", args...)
	var stdout, stderr bytes.Buffer
	cmd.Stdout = &stdout
	cmd.Stderr = &stderr
	err = cmd.Run()

	if err != nil {
		// Error but no stderr: usually can't find gofmt.
		if stderr.Len() == 0 {
			return nil, fmt.Errorf("invoking gofmt: %v", err)
		}
		return nil, fmt.Errorf("%s: %v", stderr.String(), err)
	}

	// Build file list.
	files = lines(stdout.String())
	sort.Strings(files)
	return files, nil
}
816258
func (c *CrateDriver) Exec(stmt string, args []driver.Value) (result driver.Result, err error) {
	res, err := c.query(stmt, args)

	if err != nil {
		return nil, err
	}

	result = &Result{res.Rowcount}

	return result, nil
}
408553
func main() {

	rpc := grpc.NewServer()
	pb.RegisterGreeterServer(rpc, &server{})

	app := gear.New()
	app.UseHandler(logging.Default())

	app.Use(func(ctx *gear.Context) error {
		// "application/grpc", "application/grpc+proto"
		if strings.HasPrefix(ctx.GetHeader(gear.HeaderContentType), "application/grpc") {
			rpc.ServeHTTP(ctx.Res, ctx.Req)
			ctx.End(204) // Must end with 204 to handle rpc error
		}
		return nil
	})
	app.Use(func(ctx *gear.Context) error {
		return ctx.HTML(200, "<h1>gRPC</h1>")
	})

	log.Fatalln(app.ListenTLS(":3000", "./testdata/out/test.crt", "./testdata/out/test.key"))
}
1065093
func (p *ProcessingResult) Proto() (*api.Processor, error) {
	out := &api.Processor{Id: p.ProcID}

	if p.CreatedTs.IsZero() {
		out.State = api.Processor_PENDING // no result yet
		return out, nil
	}
	out.FinishedTs = google.NewTimestamp(p.CreatedTs)

	if p.Success {
		out.State = api.Processor_SUCCEEDED
		res := &structpb.Struct{}
		if err := p.ReadResultIntoStruct(res); err != nil {
			return nil, err
		}
		if len(res.Fields) != 0 {
			out.Result = res
		}
	} else {
		out.State = api.Processor_FAILED
		out.Error = p.Error
	}

	return out, nil
}
1270073
func (p *Pipeline) Exec() {
	go func() {
		err := p.exec(p.head.Container)
		if err != nil {
			p.err = err
		}
		p.step()
	}()
}
186955
func (c *ExecCommand) Stdout() (io.WriteCloser, error) {
	if c.stdout == nil {
		if c.StdoutPath != "" {
			f, err := fifo.OpenWriter(c.StdoutPath)
			if err != nil {
				return nil, fmt.Errorf("failed to create stdout: %v", err)
			}
			c.stdout = f
		} else {
			c.stdout = nopCloser{ioutil.Discard}
		}
	}
	return c.stdout, nil
}
483648
func (g *Generator) Fail(msgs ...string) {
	s := strings.Join(msgs, " ")
	log.Print("protoc-gen-go: error:", s)
	os.Exit(1)
}
3413
func (p ProtobufImpl) Marshal(msg proto.Message) ([]byte, error) {
	res, err := proto.Marshal(msg)
	return res, errors.WithStack(err)
}
430494
func main() {
	// Add command names to cfssl usage
	flag.Usage = nil // this is set to nil for testabilty
	// Register commands.
	cmds := map[string]*cli.Command{
		"bundle":         bundle.Command,
		"certinfo":       certinfo.Command,
		"crl":            crl.Command,
		"sign":           sign.Command,
		"serve":          serve.Command,
		"version":        version.Command,
		"genkey":         genkey.Command,
		"gencert":        gencert.Command,
		"gencsr":         gencsr.Command,
		"gencrl":         gencrl.Command,
		"ocspdump":       ocspdump.Command,
		"ocsprefresh":    ocsprefresh.Command,
		"ocspsign":       ocspsign.Command,
		"ocspserve":      ocspserve.Command,
		"selfsign":       selfsign.Command,
		"scan":           scan.Command,
		"info":           info.Command,
		"print-defaults": printdefaults.Command,
		"revoke":         revoke.Command,
	}

	// If the CLI returns an error, exit with an appropriate status
	// code.
	err := cli.Start(cmds)
	if err != nil {
		os.Exit(1)
	}
}
1366606
func protoMessageDoc(msg proto.Message) (name, doc string) {
	withDesc, ok := msg.(descriptor.Message)
	if !ok {
		return "", ""
	}

	fd, md := descriptor.ForMessage(withDesc)
	if fd == nil || md == nil {
		return "", ""
	}

	for _, info := range publicProtos {
		// Find the exact same *.proto file within publicProtos struct.
		if info.goPath == fd.GetName() {
			if info.docURL == "" {
				return "", "" // no docs for it
			}
			return md.GetName(), info.docURL
		}
	}

	return "", "" // not a public proto
}
529510
func (cmd *CLI) StdOut() io.Writer {
	if cmd.stdOutput == nil {
		cmd.stdOutput = os.Stdout
	}
	return cmd.stdOutput
}
1136198
func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
	if t.dir {
		if filepath.Ext(path) != "" {
			path = filepath.Dir(path)
		}
		// check if there is at least one go file
		matched := false
		files, _ := ioutil.ReadDir(path)
		for _, f := range files {
			matched, _ = filepath.Match("*.go", f.Name())
			if matched {
				break
			}
		}
		if !matched {
			return
		}
	} else if !strings.HasSuffix(path, ".go") {
		return
	}
	args := t.Args
	if strings.HasSuffix(path, ".go") {
		args = append(args, path)
		path = filepath.Dir(path)
	}
	if s := ext(path); s == "" || s == "go" {
		if t.parent.parent.Settings.Recovery.Tools {
			log.Println("Tool:", t.name, path, args)
		}
		var out, stderr bytes.Buffer
		done := make(chan error)
		args = append(t.cmd, args...)
		cmd := exec.Command(args[0], args[1:]...)
		if t.Dir != "" {
			cmd.Dir, _ = filepath.Abs(t.Dir)
		} else {
			cmd.Dir = path
		}
		cmd.Stdout = &out
		cmd.Stderr = &stderr
		// Start command
		err := cmd.Start()
		if err != nil {
			response.Name = t.name
			response.Err = err
			return
		}
		go func() { done <- cmd.Wait() }()
		// Wait a result
		select {
		case <-stop:
			// Stop running command
			cmd.Process.Kill()
		case err := <-done:
			// Command completed
			response.Name = t.name
			if err != nil {
				response.Err = errors.New(stderr.String() + out.String() + err.Error())
			} else {
				if t.Output {
					response.Out = out.String()
				}
			}
		}
	}
	return
}
938792
func Exec(name string, args []string, timeout time.Duration, log Log) (Result, error) {
	return execWithFunc(name, args, nil, exec.Command, timeout, log)
}
304943
func Output(cmd string, args ...string) (string, error) {
	buf := &bytes.Buffer{}
	_, err := Exec(nil, buf, os.Stderr, cmd, args...)
	return strings.TrimSuffix(buf.String(), "\n"), err
}