MCPcopy Index your code
hub / github.com/coder/coder / PositiveInt32

Method PositiveInt32

coderd/httpapi/queryparams.go:103–121  ·  view source on GitHub ↗

PositiveInt32 function checks if the given value is 32-bit and positive. We can't use `uint32` as the value must be within the range <0,2147483647> as database expects it. Otherwise, the database query fails with `pq: OFFSET must not be negative`.

(vals url.Values, def int32, queryParam string)

Source from the content-addressed store, hash-verified

101// We can't use `uint32` as the value must be within the range <0,2147483647>
102// as database expects it. Otherwise, the database query fails with `pq: OFFSET must not be negative`.
103func (p *QueryParamParser) PositiveInt32(vals url.Values, def int32, queryParam string) int32 {
104 v, err := parseQueryParam(p, vals, func(v string) (int32, error) {
105 intValue, err := strconv.ParseInt(v, 10, 32)
106 if err != nil {
107 return 0, err
108 }
109 if intValue < 0 {
110 return 0, xerrors.Errorf("value is negative")
111 }
112 return int32(intValue), nil
113 }, def, queryParam)
114 if err != nil {
115 p.Errors = append(p.Errors, codersdk.ValidationError{
116 Field: queryParam,
117 Detail: fmt.Sprintf("Query param %q must be a valid 32-bit positive integer: %s", queryParam, err.Error()),
118 })
119 }
120 return v
121}
122
123// PositiveInt64 function checks if the given value is 64-bit and positive.
124func (p *QueryParamParser) PositiveInt64(vals url.Values, def int64, queryParam string) int64 {

Callers 5

provisionerDaemonsMethod · 0.95
ParsePaginationFunction · 0.95
getChatMessagesMethod · 0.95
getChatUserPromptsMethod · 0.95

Calls 3

parseQueryParamFunction · 0.85
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected