Compare commits
No commits in common. "main" and "v1.0.11" have entirely different histories.
11
go.mod
11
go.mod
|
@ -2,18 +2,13 @@ module git.ex.umbach.dev/Alex/roese-utils
|
|||
|
||||
go 1.21.0
|
||||
|
||||
require (
|
||||
github.com/go-playground/validator/v10 v10.15.5
|
||||
github.com/gofiber/fiber/v2 v2.49.2
|
||||
github.com/rs/zerolog v1.31.0
|
||||
gorm.io/gorm v1.25.5
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.15.5 // indirect
|
||||
github.com/gofiber/fiber/v2 v2.49.2 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
|
@ -23,6 +18,7 @@ require (
|
|||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/rs/zerolog v1.31.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.49.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
|
@ -30,4 +26,5 @@ require (
|
|||
golang.org/x/net v0.8.0 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/text v0.8.0 // indirect
|
||||
gorm.io/gorm v1.25.5 // indirect
|
||||
)
|
||||
|
|
7
go.sum
7
go.sum
|
@ -2,12 +2,9 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/
|
|||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
|
@ -35,7 +32,6 @@ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
|||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
|
@ -47,7 +43,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
|
|||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
|
@ -60,6 +55,7 @@ golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU
|
|||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
@ -67,7 +63,6 @@ golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
|||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
|
||||
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||
|
|
|
@ -35,17 +35,11 @@ func GetTime() string {
|
|||
}
|
||||
|
||||
type LogManagerRequestBody struct {
|
||||
Type string // like system, grouptasks, etc
|
||||
Logs []string // array of logs
|
||||
Type string
|
||||
Logs []string
|
||||
}
|
||||
|
||||
const (
|
||||
LogTypeInfo = "I "
|
||||
LogTypeWarning = "W "
|
||||
LogTypeError = "E "
|
||||
)
|
||||
|
||||
func LogManagerRequestClient(requestMethod string, requestBody LogManagerRequestBody) {
|
||||
func LogManagerRequestClient(requestMethod string, body interface{}) {
|
||||
if usedLogManagerServerUrl == "" {
|
||||
log.Error().Msgf("Log manager server url is not set, skipping request")
|
||||
return
|
||||
|
@ -58,7 +52,7 @@ func LogManagerRequestClient(requestMethod string, requestBody LogManagerRequest
|
|||
req.SetRequestURI(usedLogManagerServerUrl + "/v1/log")
|
||||
req.Header.SetContentType("application/json")
|
||||
|
||||
reqestBodyBytes, err := json.Marshal(requestBody)
|
||||
reqestBodyBytes, err := json.Marshal(body)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to marshal request body, err: %s", err)
|
||||
|
|
|
@ -11,24 +11,11 @@ import (
|
|||
func GetTotalPages(database *gorm.DB, paginationLimit int, any interface{}, whereQuery interface{}, args ...interface{}) int {
|
||||
var totalPages int64
|
||||
|
||||
if whereQuery == nil {
|
||||
database.Model(any).
|
||||
Count(&totalPages)
|
||||
} else if len(args) == 0 { // here used with db.Where(&User{Name: "jinzhu", Age: 20}).First(&user)
|
||||
database.Model(any).
|
||||
Where(whereQuery).
|
||||
Count(&totalPages)
|
||||
} else { // here used with "name = ?", "jinzhu"
|
||||
database.Model(any).
|
||||
Where(whereQuery, args).
|
||||
Count(&totalPages)
|
||||
}
|
||||
|
||||
return CalculateTotalPages(int(totalPages), paginationLimit)
|
||||
}
|
||||
|
||||
func CalculateTotalPages(totalItems int, paginationLimit int) int {
|
||||
return int(math.Ceil(float64(totalItems) / float64(paginationLimit)))
|
||||
return int(math.Ceil(float64(totalPages) / float64(paginationLimit)))
|
||||
}
|
||||
|
||||
func GetPageOffset(page int, paginationLimit int) int {
|
||||
|
@ -39,47 +26,10 @@ type PageQuery struct {
|
|||
Page int
|
||||
}
|
||||
|
||||
func DbPageQuery(database *gorm.DB, query PageQuery, paginationLimit int, result any, orderBy string, whereQuery interface{}, args ...interface{}) *gorm.DB {
|
||||
if whereQuery == nil {
|
||||
return database.Limit(paginationLimit).
|
||||
Offset(GetPageOffset(query.Page, paginationLimit)).
|
||||
Order(orderBy).
|
||||
Find(result)
|
||||
}
|
||||
|
||||
if len(args) == 0 { // here used with db.Where(&User{Name: "jinzhu", Age: 20}).First(&user)
|
||||
return database.Limit(paginationLimit).
|
||||
Offset(GetPageOffset(query.Page, paginationLimit)).
|
||||
Where(whereQuery).
|
||||
Order(orderBy).
|
||||
Find(result)
|
||||
}
|
||||
|
||||
// here used with "name = ?", "jinzhu"
|
||||
func DbPageQuery(database *gorm.DB, query PageQuery, paginationLimit int, result any, orderBy, whereQuery interface{}, args ...interface{}) *gorm.DB {
|
||||
return database.Limit(paginationLimit).
|
||||
Offset(GetPageOffset(query.Page, paginationLimit)).
|
||||
Where(whereQuery, args).
|
||||
Order(orderBy).
|
||||
Find(result)
|
||||
}
|
||||
|
||||
// GetPage returns start and end for pagination
|
||||
// can be used like this: robots[start:end]
|
||||
func GetPage(lenList int, page int, limit int) (start int, end int) {
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
start = (page - 1) * limit
|
||||
end = page * limit
|
||||
|
||||
if start > lenList {
|
||||
start = lenList
|
||||
}
|
||||
|
||||
if end > lenList {
|
||||
end = lenList
|
||||
}
|
||||
|
||||
return start, end
|
||||
}
|
||||
|
|
|
@ -46,25 +46,6 @@ func GenerateSession() (string, error) {
|
|||
return string(r), nil
|
||||
}
|
||||
|
||||
func GenerateCode(codeLength int) (string, error) {
|
||||
var letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
r := make([]byte, codeLength)
|
||||
|
||||
for i := 0; i < codeLength; i++ {
|
||||
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to session: %v", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
r[i] = letters[num.Int64()]
|
||||
}
|
||||
|
||||
return string(r), nil
|
||||
}
|
||||
|
||||
func ParamsParserHelper(c *fiber.Ctx, params interface{}) error {
|
||||
if err := c.ParamsParser(params); err != nil {
|
||||
log.Error().Msgf("Failed to parse params, err: %s", err.Error())
|
||||
|
|
Loading…
Reference in New Issue