// ProtoOK renders a 200 response with JSON-serialized proto
506189
func ProtoOK(rw http.ResponseWriter, pb proto.Message) error {
	return Proto(rw, http.StatusOK, pb)
}
308669
func (p *responseParser) parseOk() error {
	line, err := p.readLine()
	if err != nil {
		return err
	}

	if len(line) < 3 {
		return ErrMalformed
	}

	sign := string(line[0])
	if sign == "+" && string(line[1:3]) == "OK" && len(line) == 3 {
		return nil
	}

	if sign != "-" {
		return ErrMalformed
	}

	err, _ = p.errorFromLine(line)
	return err
}
1285915
func (d *FieldData) GetOk(k string) (interface{}, bool) {
	schema, ok := d.Schema[k]
	if !ok {
		return nil, false
	}

	result, ok, err := d.GetOkErr(k)
	if err != nil {
		panic(fmt.Sprintf("error reading %s: %s", k, err))
	}

	if ok && result == nil {
		result = schema.DefaultOrZero()
	}

	return result, ok
}
991325
func ParseResponse(resp *http.Response, ch chan<- *dto.MetricFamily) error {
	mediatype, params, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
	if err == nil && mediatype == "application/vnd.google.protobuf" &&
		params["encoding"] == "delimited" &&
		params["proto"] == "io.prometheus.client.MetricFamily" {
		defer close(ch)
		for {
			mf := &dto.MetricFamily{}
			if _, err = pbutil.ReadDelimited(resp.Body, mf); err != nil {
				if err == io.EOF {
					break
				}
				return fmt.Errorf("reading metric family protocol buffer failed: %v", err)
			}
			ch <- mf
		}
	} else {
		if err := ParseReader(resp.Body, ch); err != nil {
			return err
		}
	}
	return nil
}
80116
func Proto(w dns.ResponseWriter) string {
	// FIXME(miek): why not a method on Request
	if _, ok := w.RemoteAddr().(*net.UDPAddr); ok {
		return "udp"
	}
	if _, ok := w.RemoteAddr().(*net.TCPAddr); ok {
		return "tcp"
	}
	return "udp"
}
1103711
func PrintOCSPResponse(resp []byte) {
	b64Resp := base64.StdEncoding.EncodeToString(resp)

	out := map[string]string{"ocspResponse": b64Resp}
	jsonOut, err := json.Marshal(out)
	if err != nil {
		return
	}
	fmt.Printf("%s\n", jsonOut)
}
515796
func (c *Config) GetInt64Ok(key string) (i int64, ok bool) {
	v, ok := c.GetOk(key)
	if !ok {
		return 0, false
	}
	i, ok = int64(0), false
	switch iType := v.(type) {
	case uint8:
		i, ok = int64(iType), true
	case int8:
		i, ok = int64(iType), true
	case uint16:
		i, ok = int64(iType), true
	case int16:
		i, ok = int64(iType), true
	case uint32:
		i, ok = int64(iType), true
	case int32:
		i, ok = int64(iType), true
	case uint:
		i, ok = int64(iType), true
	case int:
		i, ok = int64(iType), true
	case uint64:
		i, ok = int64(iType), true
	case int64:
		i, ok = iType, true
	}
	return
}
750738
func (t *Tag) Proto() *api.Tag {
	kv := strings.SplitN(t.Tag, ":", 2)
	if len(kv) != 2 {
		panic(fmt.Sprintf("bad tag %q", t.Tag))
	}
	return &api.Tag{
		Key:        kv[0],
		Value:      kv[1],
		AttachedBy: t.RegisteredBy,
		AttachedTs: google.NewTimestamp(t.RegisteredTs),
	}
}
1205838
func (pm *PickleMachine) opcode_PROTO() error {
	var version int8
	err := pm.readBinaryInto(&version, false)
	if err != nil {
		return err
	}
	if version != 2 {
		return fmt.Errorf("Unsupported version #%d detected", version)
	}

	return nil
}
559288
func (c *Controller) RenderJSONP(callback string, o interface{}) Result {
	c.setStatusIfNil(http.StatusOK)

	return RenderJSONResult{o, callback}
}
1000074
func requireOK(d time.Duration, resp *http.Response, e error) (time.Duration, *http.Response, error) {
	if e != nil {
		if resp != nil {
			resp.Body.Close()
		}
		return d, nil, e
	}
	if resp.StatusCode != 200 {
		var buf bytes.Buffer
		io.Copy(&buf, resp.Body)
		resp.Body.Close()
		return d, nil, fmt.Errorf("Unexpected response code: %d (%s)", resp.StatusCode, buf.Bytes())
	}
	return d, resp, nil
}
341327
func (b *Remote) retryLogHook(attemptNum int, resp *http.Response) {
	if b.CLI != nil {
		// Ignore the first retry to make sure any delayed output will
		// be written to the console before we start logging retries.
		//
		// The retry logic in the TFE client will retry both rate limited
		// requests and server errors, but in the remote backend we only
		// care about server errors so we ignore rate limit (429) errors.
		if attemptNum == 0 || resp.StatusCode == 429 {
			// Reset the last retry time.
			b.lastRetry = time.Now()
			return
		}

		if attemptNum == 1 {
			b.CLI.Output(b.Colorize().Color(strings.TrimSpace(initialRetryError)))
		} else {
			b.CLI.Output(b.Colorize().Color(strings.TrimSpace(
				fmt.Sprintf(repeatedRetryError, time.Since(b.lastRetry).Round(time.Second)))))
		}
	}
}
247363
func (c *Context) GetOk(key interface{}) (interface{}, bool) {
	store := c.getStore()
	val, ok := store[key]
	if !ok {
		if c.Parent != nil {
			return c.Parent.GetOk(key)
		}
	}
	return val, ok
}
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()
}
42793
func parseError(resp *http.Response) error {
	dnsError := Error{}
	err := decodeBody(resp, &dnsError)

	// if there was an error decoding the body, just return that
	if err != nil {
		return fmt.Errorf("Error parsing error body for non-200 request: %s", err)
	}
	return fmt.Errorf("API Error (%d): %s", resp.StatusCode, dnsError.Join())
}
210561
func RequireOK(resp *http.Response, err error) (*http.Response, error) {
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != http.StatusOK {
		return nil, extractError(resp)
	}
	return resp, nil
}
614957
func (m *Meta) uiHook() *UiHook {
	return &UiHook{
		Colorize: m.Colorize(),
		Ui:       m.Ui,
	}
}