Compare commits

...

7 Commits

Author SHA1 Message Date
3188b951fb v0.0.348 added listener and options to goext
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m35s
2023-12-27 20:29:37 +01:00
6b211d1443 fix tests
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m37s
2023-12-17 14:04:35 +01:00
b2b9b40792 v0.0.347
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m39s
2023-12-16 17:57:42 +01:00
2f915cb6c1 v0.0.346
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m56s
2023-12-13 16:22:15 +01:00
b2b93f570a v0.0.345
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 2m48s
2023-12-07 19:39:31 +01:00
8247fc4524 v0.0.344
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m11s
2023-12-07 19:36:21 +01:00
5dad44ad09 v0.0.343
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m2s
2023-12-07 18:29:17 +01:00
13 changed files with 92 additions and 50 deletions

View File

@@ -70,9 +70,9 @@ func GenerateCharsetIDSpecs(sourceDir string, destFile string) error {
newChecksum := cryptext.BytesSha256([]byte(newChecksumStr))
if newChecksum != oldChecksum {
fmt.Printf("[IDGenerate] Checksum has changed ( %s -> %s ), will generate new file\n\n", oldChecksum, newChecksum)
fmt.Printf("[CSIDGenerate] Checksum has changed ( %s -> %s ), will generate new file\n\n", oldChecksum, newChecksum)
} else {
fmt.Printf("[IDGenerate] Checksum unchanged ( %s ), nothing to do\n", oldChecksum)
fmt.Printf("[CSIDGenerate] Checksum unchanged ( %s ), nothing to do\n", oldChecksum)
return nil
}

View File

@@ -61,11 +61,15 @@ func GenerateEnumSpecs(sourceDir string, destFile string) error {
}
}
gocode, _, err := _generateEnumSpecs(sourceDir, oldChecksum, destFile, true)
gocode, _, changed, err := _generateEnumSpecs(sourceDir, destFile, oldChecksum, true)
if err != nil {
return err
}
if !changed {
return nil
}
err = os.WriteFile(destFile, []byte(gocode), 0o755)
if err != nil {
return err
@@ -74,11 +78,11 @@ func GenerateEnumSpecs(sourceDir string, destFile string) error {
return nil
}
func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, gofmt bool) (string, string, error) {
func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, gofmt bool) (string, string, bool, error) {
files, err := os.ReadDir(sourceDir)
if err != nil {
return "", "", err
return "", "", false, err
}
files = langext.ArrFilter(files, func(v os.DirEntry) bool { return v.Name() != path.Base(destFile) })
@@ -90,7 +94,7 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
for _, f := range files {
content, err := os.ReadFile(path.Join(sourceDir, f.Name()))
if err != nil {
return "", "", err
return "", "", false, err
}
newChecksumStr += "\n" + f.Name() + "\t" + cryptext.BytesSha256(content)
}
@@ -101,7 +105,7 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
fmt.Printf("[EnumGenerate] Checksum has changed ( %s -> %s ), will generate new file\n\n", oldChecksum, newChecksum)
} else {
fmt.Printf("[EnumGenerate] Checksum unchanged ( %s ), nothing to do\n", oldChecksum)
return "", oldChecksum, nil
return "", oldChecksum, false, nil
}
allEnums := make([]EnumDef, 0)
@@ -112,7 +116,7 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
fmt.Printf("========= %s =========\n\n", f.Name())
fileEnums, pn, err := processEnumFile(sourceDir, path.Join(sourceDir, f.Name()))
if err != nil {
return "", "", err
return "", "", false, err
}
fmt.Printf("\n")
@@ -125,21 +129,21 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
}
if pkgname == "" {
return "", "", errors.New("no package name found in any file")
return "", "", false, errors.New("no package name found in any file")
}
rdata := fmtEnumOutput(newChecksum, allEnums, pkgname)
if !gofmt {
return rdata, newChecksum, nil
return rdata, newChecksum, true, nil
}
fdata, err := format.Source([]byte(rdata))
if err != nil {
return "", "", err
return "", "", false, err
}
return string(fdata), newChecksum, nil
return string(fdata), newChecksum, true, nil
}
func processEnumFile(basedir string, fn string) ([]EnumDef, string, error) {

View File

@@ -37,10 +37,10 @@ func TestGenerateEnumSpecs(t *testing.T) {
_, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run()
tst.AssertNoErr(t, err)
s1, cs1, err := _generateEnumSpecs(tmpDir, "", "N/A", true)
s1, cs1, _, err := _generateEnumSpecs(tmpDir, "", "N/A", true)
tst.AssertNoErr(t, err)
s2, cs2, err := _generateEnumSpecs(tmpDir, "", "N/A", true)
s2, cs2, _, err := _generateEnumSpecs(tmpDir, "", "N/A", true)
tst.AssertNoErr(t, err)
tst.AssertEqual(t, cs1, cs2)
@@ -76,7 +76,7 @@ func TestGenerateEnumSpecsData(t *testing.T) {
_, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run()
tst.AssertNoErr(t, err)
s1, _, err := _generateEnumSpecs(tmpDir, "", "", true)
s1, _, _, err := _generateEnumSpecs(tmpDir, "", "", true)
tst.AssertNoErr(t, err)
fmt.Println()

View File

@@ -22,6 +22,8 @@ type GinWrapper struct {
ginDebug bool
bufferBody bool
requestTimeout time.Duration
listenerBeforeRequest []func(g *gin.Context)
listenerAfterRequest []func(g *gin.Context, resp HTTPResponse)
routeSpecs []ginRouteSpec
}
@@ -33,35 +35,41 @@ type ginRouteSpec struct {
Handler string
}
type Options struct {
AllowCors *bool // Add cors handler to allow all CORS requests on the default http methods
GinDebug *bool // Set gin.debug to true (adds more logs)
BufferBody *bool // Buffers the input body stream, this way the ginext error handler can later include the whole request body
Timeout *time.Duration // The default handler timeout
ListenerBeforeRequest []func(g *gin.Context) // Register listener that are called before the handler method
ListenerAfterRequest []func(g *gin.Context, resp HTTPResponse) // Register listener that are called after the handler method
}
// NewEngine creates a new (wrapped) ginEngine
// Parameters are:
// - [allowCors] Add cors handler to allow all CORS requests on the default http methods
// - [ginDebug] Set gin.debug to true (adds more logs)
// - [bufferBody] Buffers the input body stream, this way the ginext error handler can later include the whole request body
// - [timeout] The default handler timeout
func NewEngine(allowCors bool, ginDebug bool, bufferBody bool, timeout time.Duration) *GinWrapper {
func NewEngine(opt Options) *GinWrapper {
engine := gin.New()
wrapper := &GinWrapper{
engine: engine,
SuppressGinLogs: false,
allowCors: allowCors,
ginDebug: ginDebug,
bufferBody: bufferBody,
requestTimeout: timeout,
allowCors: langext.Coalesce(opt.AllowCors, false),
ginDebug: langext.Coalesce(opt.GinDebug, true),
bufferBody: langext.Coalesce(opt.BufferBody, false),
requestTimeout: langext.Coalesce(opt.Timeout, 24*time.Hour),
listenerBeforeRequest: opt.ListenerBeforeRequest,
listenerAfterRequest: opt.ListenerAfterRequest,
}
engine.RedirectFixedPath = false
engine.RedirectTrailingSlash = false
if allowCors {
if wrapper.allowCors {
engine.Use(CorsMiddleware())
}
// do not debug-print routes
gin.DebugPrintRouteFunc = func(_, _, _ string, _ int) {}
if !ginDebug {
if !wrapper.ginDebug {
gin.SetMode(gin.ReleaseMode)
ginlogger := gin.Logger()

View File

@@ -20,6 +20,10 @@ func Wrap(w *GinWrapper, fn WHandlerFunc) gin.HandlerFunc {
persistantData: &preContextData{},
}
for _, lstr := range w.listenerBeforeRequest {
lstr(g)
}
wrap, stackTrace, panicObj := callPanicSafe(fn, pctx)
if panicObj != nil {
@@ -45,6 +49,10 @@ func Wrap(w *GinWrapper, fn WHandlerFunc) gin.HandlerFunc {
}
}
for _, lstr := range w.listenerAfterRequest {
lstr(g, wrap)
}
if reqctx.Err() == nil {
wrap.Write(g)
}

6
go.mod
View File

@@ -8,7 +8,7 @@ require (
github.com/rs/xid v1.5.0
github.com/rs/zerolog v1.31.0
go.mongodb.org/mongo-driver v1.13.1
golang.org/x/crypto v0.16.0
golang.org/x/crypto v0.17.0
golang.org/x/sys v0.15.0
golang.org/x/term v0.15.0
)
@@ -33,7 +33,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
@@ -44,6 +44,6 @@ require (
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

6
go.sum
View File

@@ -88,6 +88,8 @@ github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
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=
@@ -143,6 +145,8 @@ golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -207,6 +211,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
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=

View File

@@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.342"
const GoextVersion = "0.0.348"
const GoextVersionTimestamp = "2023-12-07T17:57:06+0100"
const GoextVersionTimestamp = "2023-12-27T20:29:37+0100"

View File

@@ -1,7 +1,6 @@
package googleapi
import (
"fmt"
"gogs.mikescher.com/BlackForestBytes/goext/tst"
"os"
"testing"
@@ -18,7 +17,7 @@ func TestEncodeMimeMail(t *testing.T) {
MailBody{Plain: "Plain Text"},
nil)
fmt.Printf("%s\n\n", mail)
verifyMime(mail)
}
func TestEncodeMimeMail2(t *testing.T) {
@@ -35,7 +34,7 @@ func TestEncodeMimeMail2(t *testing.T) {
},
nil)
fmt.Printf("%s\n\n", mail)
verifyMime(mail)
}
func TestEncodeMimeMail3(t *testing.T) {
@@ -53,12 +52,12 @@ func TestEncodeMimeMail3(t *testing.T) {
{Data: []byte("HelloWorld"), Filename: "test.txt", IsInline: false, ContentType: "text/plain"},
})
fmt.Printf("%s\n\n", mail)
verifyMime(mail)
}
func TestEncodeMimeMail4(t *testing.T) {
b := tst.Must(os.ReadFile("/home/mike/Pictures/Screenshot_20220706_190205.png"))(t)
b := tst.Must(os.ReadFile("test_placeholder.png"))(t)
mail := encodeMimeMail(
"noreply@heydyno.de",
@@ -73,5 +72,9 @@ func TestEncodeMimeMail4(t *testing.T) {
{Data: b, Filename: "img.png", IsInline: true, ContentType: "image/png"},
})
fmt.Printf("%s\n\n", mail)
verifyMime(mail)
}
func verifyMime(mail string) {
//fmt.Printf("%s\n\n", mail)
}

View File

@@ -127,7 +127,7 @@ func TestSendMail4(t *testing.T) {
gclient := NewGoogleClient(auth)
b := tst.Must(os.ReadFile("/home/mike/Pictures/Screenshot_20220706_190205.png"))(t)
b := tst.Must(os.ReadFile("test_placeholder.png"))(t)
mail, err := gclient.SendMail(
ctx,

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -10,10 +10,23 @@ var PTrue = Ptr(true)
// PFalse := &false
var PFalse = Ptr(false)
// PNil := &nil
var PNil = Ptr[any](nil)
func Ptr[T any](v T) *T {
return &v
}
func DblPtr[T any](v T) **T {
v_ := &v
return &v_
}
func DblPtrNil[T any]() **T {
var v *T = nil
return &v
}
func PtrInt32(v int32) *int32 {
return &v
}

View File

@@ -5,7 +5,7 @@ type Pagination struct {
Limit int `json:"limit"` // max-page-size
TotalPages int `json:"totalPages"` // total page-count
TotalItems int `json:"totalItems"` // total items-count
CurrentPageCount int `json:"currntPageCount"` // item-count in current page ( == len(data) )
CurrentPageCount int `json:"currentPageCount"` // item-count in current page ( == len(data) )
}
func CalcPaginationTotalPages(totalItems int, limit int) int {