// getShuntVoltageRaw gets the raw shunt voltage (16-bit signed integer, so +-32767)
423955
func (i *INA3221Driver) getShuntVoltageRaw(channel INA3221Channel) (int16, error) {
	val, err := i.readWordFromRegister(ina3221RegShuntVoltage1 + (uint8(channel)-1)*2)
	if err != nil {
		return 0, err
	}

	value := int32(val)
	if value > 0x7FFF {
		value -= 0x10000
	}

	return int16(value), nil
}
1046035
func getUintEnvVar(envVar string, def *uint) *uint {
	if strVal := os.Getenv(envVar); strVal != "" {
		if parsedVal, err := strconv.ParseUint(strVal, 10, 16); err == nil {
			val := uint(parsedVal)
			return &val
		}
	}
	return def
}
1201161
func (c *ResourceConfig) GetRaw(k string) (interface{}, bool) {
	return c.get(k, c.Raw)
}
322174
func (h *HTTPRangeSpec) GetLength(resourceSize int64) (rangeLength int64, err error) {
	switch {
	case resourceSize < 0:
		return 0, errors.New("Resource size cannot be negative")

	case h == nil:
		rangeLength = resourceSize

	case h.IsSuffixLength:
		specifiedLen := -h.Start
		rangeLength = specifiedLen
		if specifiedLen > resourceSize {
			rangeLength = resourceSize
		}

	case h.Start >= resourceSize:
		return 0, errInvalidRange

	case h.End > -1:
		end := h.End
		if resourceSize <= end {
			end = resourceSize - 1
		}
		rangeLength = end - h.Start + 1

	case h.End == -1:
		rangeLength = resourceSize - h.Start

	default:
		return 0, errors.New("Unexpected range specification case")
	}

	return rangeLength, nil
}
77341
func (c *client) getRaw(ctx context.Context, urlPath string, query url.Values) (http.Header, []byte, error) {
	u := fmt.Sprintf("%s/%s", strings.TrimSuffix(c.BaseURL, "/"), strings.TrimPrefix(urlPath, "/"))
	if query != nil {
		u = fmt.Sprintf("%s?%s", u, query.Encode())
	}
	r, err := ctxhttp.Get(ctx, c.Client, u)
	if err != nil {
		return http.Header{}, []byte{}, transient.Tag.Apply(err)
	}

	defer r.Body.Close()
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return r.Header, []byte{}, errors.Annotate(err, "could not read response body").Err()
	}

	switch r.StatusCode {
	case http.StatusOK:
		return r.Header, bytes.TrimPrefix(body, jsonPrefix), nil

	case http.StatusTooManyRequests:
		logging.Errorf(ctx, "Gitiles quota error.\nResponse headers: %v\nResponse body: %s",
			r.Header, body)
		return r.Header, body, status.Errorf(codes.ResourceExhausted, "insufficient Gitiles quota")

	case http.StatusNotFound:
		return r.Header, body, status.Errorf(codes.NotFound, "not found")

	default:
		logging.Errorf(ctx, "gitiles: unexpected HTTP %d response.\nResponse headers: %v\nResponse body: %s",
			r.StatusCode,
			r.Header, body)
		return r.Header, body, status.Errorf(codes.Internal, "unexpected HTTP %d from Gitiles", r.StatusCode)
	}
}
615120
func (c *connection) getBestVersion(apiKey int16) int16 {
	if requested, ok := c.apiVersions[apiKey]; ok {
		supported := proto.SupportedByDriver[apiKey]
		if min(supported.MaxVersion, requested.MaxVersion) >= max(supported.MinVersion, requested.MinVersion) {
			return min(supported.MaxVersion, requested.MaxVersion)
		}
	}
	return 0
}
1282752
func (kinesis *Kinesis) GetShardIterator(args *RequestArgs) (resp *GetShardIteratorResp, err error) {
	params := makeParams("GetShardIterator")
	resp = &GetShardIteratorResp{}
	err = kinesis.query(params, args.params, resp)
	if err != nil {
		return nil, err
	}
	return
}
997636
func (u *UserLDAPMapping) GetAvatarURL() string {
	if u == nil || u.AvatarURL == nil {
		return ""
	}
	return *u.AvatarURL
}
760820
func (p *PullRequestComment) GetPullRequestURL() string {
	if p == nil || p.PullRequestURL == nil {
		return ""
	}
	return *p.PullRequestURL
}
208251
func (h *histogram) getRandomBoundIdx() int {
	cnt := h.Buckets[len(h.Buckets)-1].Count
	randCnt := randInt64(0, cnt)
	for i, bkt := range h.Buckets {
		if bkt.Count >= randCnt {
			if bkt.Count-bkt.Repeat > randCnt {
				return 2 * i
			}
			return 2*i + 1
		}
	}
	return 0
}
342471
func (e *InsufficientResourceError) GetInsufficientAmount() int64 {
	return e.requested - (e.capacity - e.used)
}
193881
func (t *Template) GetAWSGameLiftAliasWithName(name string) (*resources.AWSGameLiftAlias, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSGameLiftAlias:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSGameLiftAlias not found", name)
}
1141089
func (_class VMGuestMetricsClass) GetPVDriversDetected(sessionID SessionRef, self VMGuestMetricsRef) (_retval bool, _err error) {
	_method := "VM_guest_metrics.get_PV_drivers_detected"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVMGuestMetricsRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertBoolToGo(_method + " -> ", _result.Value)
	return
}
126744
func (r RequestParams) GetIntUnslashed(key string) (int, bool) {
	v := r.Get(key)
	if v != "" {
		if len(v) > 1 {
			if v[0] == '/' {
				v = v[1:]
			}
		}

		vInt, err := strconv.Atoi(v)
		if err != nil {
			return -1, false
		}
		return vInt, true
	}

	return -1, false
}
104205
func (o *Organization) GetAvatarURL() string {
	if o == nil || o.AvatarURL == nil {
		return ""
	}
	return *o.AvatarURL
}
601032
func (t *Template) GetAWSGuardDutyMasterWithName(name string) (*resources.AWSGuardDutyMaster, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSGuardDutyMaster:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSGuardDutyMaster not found", name)
}
1133132
func getGetterUrl(taskEnv EnvReplacer, artifact *structs.TaskArtifact) (string, error) {
	source := taskEnv.ReplaceEnv(artifact.GetterSource)

	// Handle an invalid URL when given a go-getter url such as
	// git@github.com:hashicorp/nomad.git
	gitSSH := false
	if strings.HasPrefix(source, gitSSHPrefix) {
		gitSSH = true
		source = source[len(gitSSHPrefix):]
	}

	u, err := url.Parse(source)
	if err != nil {
		return "", fmt.Errorf("failed to parse source URL %q: %v", artifact.GetterSource, err)
	}

	// Build the url
	q := u.Query()
	for k, v := range artifact.GetterOptions {
		q.Add(k, taskEnv.ReplaceEnv(v))
	}
	u.RawQuery = q.Encode()

	// Add the prefix back
	url := u.String()
	if gitSSH {
		url = fmt.Sprintf("%s%s", gitSSHPrefix, url)
	}

	return url, nil
}