// GetLimitCtx retrieves the ctxLimit data from the request context. If not set,
// the return value is 0 which is interpreted as no limit.
483360
func GetLimitCtx(r *http.Request) int {
	limit, ok := r.Context().Value(m.CtxLimit).(string)
	if !ok {
		return 0
	}
	intValue, err := strconv.Atoi(limit)
	if err != nil {
		return 0
	}
	return intValue
}
1151808
func PaginationCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		to, from := r.FormValue("to"), r.FormValue("from")
		if to == "" {
			to = "20"
		}

		if from == "" {
			from = "0"
		}

		offset, err := strconv.Atoi(from)
		if err != nil {
			http.Error(w, "invalid from value", 422)
			return
		}
		count, err := strconv.Atoi(to)
		if err != nil {
			http.Error(w, "invalid to value", 422)
			return
		}

		ctx := context.WithValue(r.Context(), ctxCount, count)
		ctx = context.WithValue(ctx, ctxOffset, offset)
		next.ServeHTTP(w, r.WithContext(ctx))
	})
}
1090146
func maxIndex(start, limit, total int) (max int) {
	if limit <= 0 {
		limit = mock.DefaultLimit
	}
	if limit > mock.MaxLimit {
		limit = mock.MaxLimit
	}
	max = total
	if start+limit < max {
		max = start + limit
	}
	return max
}
1204794
func (b *Buffer) ViewLimit(limit int64) *View {
	if limit > b.size {
		limit = b.size
	}

	return &View{
		cur:  b.first,
		cidx: b.fidx,
		size: limit,

		b: b,
	}
}
909034
func GetCountCtx(r *http.Request) int {
	count, ok := r.Context().Value(ctxCount).(int)
	if !ok {
		apiLog.Warn("count is not set or is not an int")
		return 20
	}
	return count
}
932147
func GetBlockIndex0Ctx(r *http.Request) int {
	idx, ok := r.Context().Value(ctxBlockIndex0).(int)
	if !ok {
		apiLog.Error("block index0 is not set or is not an int")
		return -1
	}
	return idx
}
151421
func (c *Client) RateLimits(ctx context.Context) (*RateLimits, *Response, error) {
	req, err := c.NewRequest("GET", "rate_limit", nil)
	if err != nil {
		return nil, nil, err
	}

	response := new(struct {
		Resources *RateLimits `json:"resources"`
	})
	resp, err := c.Do(ctx, req, response)
	if err != nil {
		return nil, nil, err
	}

	if response.Resources != nil {
		c.rateMu.Lock()
		if response.Resources.Core != nil {
			c.rateLimits[coreCategory] = *response.Resources.Core
		}
		if response.Resources.Search != nil {
			c.rateLimits[searchCategory] = *response.Resources.Search
		}
		c.rateMu.Unlock()
	}

	return response.Resources, resp, nil
}
114916
func GetNoTxListCtx(r *http.Request) int {
	notxlist, ok := r.Context().Value(ctxNoTxList).(int)
	if !ok {
		return 0
	}
	return notxlist
}
900857
func (wxa *MiniProgram) GetWXACodeUnlimit(coderParams QRCoder) (response []byte, err error) {
	return wxa.fetchCode(getWXACodeUnlimitURL, coderParams)
}
13402
func GetSessionFromCtx(ctx context.Context) *session.Session {
	sessionVal := ctx.Value(constants.SessionCtxKey)
	if sessionVal == nil {
		logger.Log.Warn("ctx doesn't contain a session, are you calling GetSessionFromCtx from inside a remote?")
		return nil
	}
	return sessionVal.(*session.Session)
}
1250551
func GetMaxOpenFileLimit() (curLimit, maxLimit uint64, err error) {
	var rlimit syscall.Rlimit
	if err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err == nil {
		curLimit = rlimit.Cur
		maxLimit = rlimit.Max
	}

	return curLimit, maxLimit, err
}
1146199
func GetNbBlocksCtx(r *http.Request) int {
	nbBlocks, ok := r.Context().Value(ctxNbBlocks).(int)
	if !ok {
		return 0
	}
	return nbBlocks
}
1118642
func GetMaxSockets() (int, error) {
	if initVersionError != nil {
		return 0, initVersionError
	}
	if initContextError != nil {
		return 0, initContextError
	}
	return defaultCtx.GetMaxSockets()
}
329083
func GetMaxMemoryLimit() (curLimit, maxLimit uint64, err error) {
	var rlimit syscall.Rlimit
	if err = syscall.Getrlimit(syscall.RLIMIT_DATA, &rlimit); err == nil {
		curLimit = rlimit.Cur
		maxLimit = rlimit.Max
	}

	return curLimit, maxLimit, err
}
507067
func CtxDomain(r *http.Request) string {
	val := r.Context().Value(domainCtx)
	if val == nil {
		return ""
	}
	return val.(string)
}
1030386
func GetNoAsmCtx(r *http.Request) bool {
	noAsm, ok := r.Context().Value(ctxNoAsm).(bool)
	if !ok {
		return false
	}
	return noAsm
}
1016006
func GetStatusInfoCtx(r *http.Request) string {
	statusInfo, ok := r.Context().Value(ctxGetStatus).(string)
	if !ok {
		apiLog.Warn("status info is not set or is not a string")
		return ""
	}
	return statusInfo
}