Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
88642770c5
|
|||
8528b5cb66 | |||
5ba84bd8ee
|
|||
1260b2dc77
|
|||
7d18b913c6
|
|||
d1f9069f2f |
@@ -6,7 +6,12 @@
|
|||||||
name: Build Docker and Deploy
|
name: Build Docker and Deploy
|
||||||
run-name: Build & Deploy ${{ gitea.ref }} on ${{ gitea.actor }}
|
run-name: Build & Deploy ${{ gitea.ref }} on ${{ gitea.actor }}
|
||||||
|
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run_tests:
|
run_tests:
|
||||||
@@ -34,3 +39,17 @@ jobs:
|
|||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cd "${{ gitea.workspace }}" && make test
|
run: cd "${{ gitea.workspace }}" && make test
|
||||||
|
|
||||||
|
- name: Send failure mail
|
||||||
|
if: failure()
|
||||||
|
uses: dawidd6/action-send-mail@v3
|
||||||
|
with:
|
||||||
|
server_address: smtp.fastmail.com
|
||||||
|
server_port: 465
|
||||||
|
secure: true
|
||||||
|
username: ${{secrets.MAIL_USERNAME}}
|
||||||
|
password: ${{secrets.MAIL_PASSWORD}}
|
||||||
|
subject: Pipeline on '${{ gitea.repository }}' failed
|
||||||
|
to: ${{ steps.commiter_info.outputs.MAIL }}
|
||||||
|
from: Gitea Actions <gitea_actions@blackforestbytes.de>
|
||||||
|
body: "Go to https://gogs.blackforestbytes.com/${{ gitea.repository }}/actions"
|
||||||
|
|
||||||
|
@@ -70,6 +70,7 @@ func init() {
|
|||||||
type Builder struct {
|
type Builder struct {
|
||||||
errorData *ExErr
|
errorData *ExErr
|
||||||
containsGinData bool
|
containsGinData bool
|
||||||
|
noLog bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func Get(err error) *Builder {
|
func Get(err error) *Builder {
|
||||||
@@ -190,6 +191,13 @@ func (b *Builder) System() *Builder {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func (b *Builder) NoLog() *Builder {
|
||||||
|
b.noLog = true
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
func (b *Builder) Id(key string, val fmt.Stringer) *Builder {
|
func (b *Builder) Id(key string, val fmt.Stringer) *Builder {
|
||||||
return b.addMeta(key, MDTID, newIDWrap(val))
|
return b.addMeta(key, MDTID, newIDWrap(val))
|
||||||
}
|
}
|
||||||
@@ -401,12 +409,14 @@ func extractHeader(header map[string][]string) []string {
|
|||||||
|
|
||||||
// Build creates a new error, ready to pass up the stack
|
// Build creates a new error, ready to pass up the stack
|
||||||
// If the errors is not SevWarn or SevInfo it gets also logged (in short form, without stacktrace) onto stdout
|
// If the errors is not SevWarn or SevInfo it gets also logged (in short form, without stacktrace) onto stdout
|
||||||
|
// Can be gloablly configured with ZeroLogErrTraces and ZeroLogAllTraces
|
||||||
|
// Can be locally suppressed with Builder.NoLog()
|
||||||
func (b *Builder) Build() error {
|
func (b *Builder) Build() error {
|
||||||
warnOnPkgConfigNotInitialized()
|
warnOnPkgConfigNotInitialized()
|
||||||
|
|
||||||
if pkgconfig.ZeroLogErrTraces && (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) {
|
if pkgconfig.ZeroLogErrTraces && !b.noLog && (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) {
|
||||||
b.errorData.ShortLog(stackSkipLogger.Error())
|
b.errorData.ShortLog(stackSkipLogger.Error())
|
||||||
} else if pkgconfig.ZeroLogAllTraces {
|
} else if pkgconfig.ZeroLogAllTraces && !b.noLog {
|
||||||
b.errorData.ShortLog(stackSkipLogger.Error())
|
b.errorData.ShortLog(stackSkipLogger.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module gogs.mikescher.com/BlackForestBytes/goext
|
module gogs.mikescher.com/BlackForestBytes/goext
|
||||||
|
|
||||||
go 1.19
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.9.1
|
github.com/gin-gonic/gin v1.9.1
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.315"
|
const GoextVersion = "0.0.321"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2023-11-12T03:10:55+0100"
|
const GoextVersionTimestamp = "2023-11-14T16:00:14+0100"
|
||||||
|
@@ -14,12 +14,12 @@ func (c *Coll[TData]) decodeSingle(ctx context.Context, dec Decodable) (TData, e
|
|||||||
if c.customDecoder != nil {
|
if c.customDecoder != nil {
|
||||||
res, err = (*c.customDecoder)(ctx, dec)
|
res, err = (*c.customDecoder)(ctx, dec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *new(TData), exerr.Wrap(err, "failed to decode single entity with custom-decoder").Type("decoder", *c.customDecoder).Build()
|
return *new(TData), exerr.Wrap(err, "failed to decode single entity with custom-decoder").Type("decoder", *c.customDecoder).NoLog().Build()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = dec.Decode(&res)
|
err = dec.Decode(&res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *new(TData), exerr.Wrap(err, "failed to decode single entity").Type("target-type", res).Build()
|
return *new(TData), exerr.Wrap(err, "failed to decode single entity").Type("target-type", res).NoLog().Build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,12 +75,12 @@ func (c *Coll[TData]) decodeSingleOrRequery(ctx context.Context, dec Decodable)
|
|||||||
var res genDoc
|
var res genDoc
|
||||||
err := dec.Decode(&res)
|
err := dec.Decode(&res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *new(TData), exerr.Wrap(err, "failed to ID-decode entity").Build()
|
return *new(TData), exerr.Wrap(err, "failed to ID-decode entity").NoLog().Build()
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err := c.findOneInternal(ctx, bson.M{"_id": res.ID}, false)
|
v, err := c.findOneInternal(ctx, bson.M{"_id": res.ID}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *new(TData), exerr.Wrap(err, "failed to re-query entity").Any("_id", res.ID).Build()
|
return *new(TData), exerr.Wrap(err, "failed to re-query entity").Any("_id", res.ID).NoLog().Build()
|
||||||
}
|
}
|
||||||
|
|
||||||
return *v, nil
|
return *v, nil
|
||||||
|
@@ -58,7 +58,7 @@ func (c *Coll[TData]) findOneInternal(ctx context.Context, filter bson.M, allowN
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, exerr.Wrap(err, "mongo-query[find-one] failed").Any("filter", filter).Str("collection", c.Name()).Build()
|
return nil, exerr.Wrap(err, "mongo-query[find-one] failed").Any("filter", filter).Str("collection", c.Name()).NoLog().Build()
|
||||||
}
|
}
|
||||||
|
|
||||||
return &res, nil
|
return &res, nil
|
||||||
@@ -75,19 +75,19 @@ func (c *Coll[TData]) findOneInternal(ctx context.Context, filter bson.M, allowN
|
|||||||
|
|
||||||
cursor, err := c.coll.Aggregate(ctx, pipeline)
|
cursor, err := c.coll.Aggregate(ctx, pipeline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed").Any("pipeline", pipeline).Str("collection", c.Name()).NoLog().Build()
|
||||||
}
|
}
|
||||||
|
|
||||||
if cursor.Next(ctx) {
|
if cursor.Next(ctx) {
|
||||||
v, err := c.decodeSingle(ctx, cursor)
|
v, err := c.decodeSingle(ctx, cursor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed to decode results").Any("pipeline", pipeline).Str("collection", c.Name()).NoLog().Build()
|
||||||
}
|
}
|
||||||
return &v, nil
|
return &v, nil
|
||||||
} else if allowNull {
|
} else if allowNull {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
return nil, exerr.Wrap(mongo.ErrNoDocuments, "mongo-aggregation [find-one] returned no documents").Any("pipeline", pipeline).Str("collection", c.Name()).NoLog().Build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,8 +42,8 @@ func (c *Coll[TData]) Paginate(ctx context.Context, filter pag.Filter, page int,
|
|||||||
pipelineCount := mongo.Pipeline{}
|
pipelineCount := mongo.Pipeline{}
|
||||||
pipelineCount = append(pipelineCount, bson.D{{Key: "$count", Value: "count"}})
|
pipelineCount = append(pipelineCount, bson.D{{Key: "$count", Value: "count"}})
|
||||||
|
|
||||||
pipelineList := langext.ArrConcat(mongo.Pipeline{}, pipelineFilter, pipelinePaginate, c.extraModPipeline)
|
pipelineList := langext.ArrConcat(pipelineFilter, pipelineSort, pipelinePaginate, c.extraModPipeline, pipelineSort)
|
||||||
pipelineTotalCount := langext.ArrConcat(mongo.Pipeline{}, pipelineFilter, pipelineCount)
|
pipelineTotalCount := langext.ArrConcat(pipelineFilter, pipelineCount)
|
||||||
|
|
||||||
cursorList, err := c.coll.Aggregate(ctx, pipelineList)
|
cursorList, err := c.coll.Aggregate(ctx, pipelineList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user