-
Notifications
You must be signed in to change notification settings - Fork 28
/
util.go
43 lines (35 loc) · 1011 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2021 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
package util
import (
"github.com/gin-gonic/gin"
"github.com/go-vela/types"
)
// HandleError appends the error to the handler chain for logging and outputs it.
func HandleError(c *gin.Context, status int, err error) {
msg := err.Error()
// nolint: errcheck // ignore checking error
c.Error(err)
c.AbortWithStatusJSON(status, types.Error{Message: &msg})
}
// MaxInt is a helper function to clamp the integer which
// prevents it from being higher then the provided value.
//
// Currently, Go only supports float64 via math. ( max | min ).
func MaxInt(a, b int) int {
if a > b {
return a
}
return b
}
// MinInt is a helper function to clamp the integer which
// prevents it from being lower then the provided value.
//
// Currently, Go only supports float64 via math. ( max | min ).
func MinInt(a, b int) int {
if a < b {
return a
}
return b
}