Go to file
Mike Schwörer a8e6f98a89
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
v0.0.501
2024-08-07 19:31:36 +02:00
_data v0.0.184 re-add missing array methods from merge commit 56684b2c0b 2023-07-19 19:29:59 +02:00
.gitea/workflows v0.0.318 add failure mail to testx.yml 2023-11-13 15:34:58 +01:00
.idea v0.0.400 added CommentTrimmer and DBOptions to sq 2024-03-09 14:59:32 +01:00
bfcodegen v0.0.413 fix tests 2024-03-11 21:00:30 +01:00
cmdext try to fix test 'cmdext:TestFailOnStderr' 2023-09-25 18:04:56 +02:00
confext v0.0.287 fix bug in confext::ApplyEnvOverrides if a struct env key exists in the os.env 2023-10-12 10:02:42 +02:00
cryptext v0.0.374 ppwgen 2024-01-14 01:37:38 +01:00
cursortoken v0.0.489 2024-07-23 14:21:03 +02:00
dataext v0.0.447 2024-05-10 21:33:01 +02:00
enums v0.0.402 add PackageName() and TypeName() to enums_codegen 2024-03-10 12:49:31 +01:00
exerr v0.0.490 documentation and extra-params in exerr 2024-07-27 23:44:18 +02:00
fsext v0.0.289 fsext 2023-10-26 11:29:08 +02:00
ginext v0.0.492 2024-08-02 16:19:21 +02:00
gojson v0.0.492 2024-08-02 16:19:21 +02:00
googleapi fix tests 2023-12-17 14:04:35 +01:00
imageext v0.0.495 2024-08-07 14:00:02 +02:00
langext v0.0.496 wpdf fixes and wpdf test.go 2024-08-07 15:34:06 +02:00
mathext v0.0.482 mathext.Percentile 2024-07-12 16:33:42 +02:00
mongoext v0.0.455 add proper json/bson marshalling to exerr [severity|type|category] 2024-05-16 15:38:42 +02:00
pagination v0.0.473 add ctx to wmo.FilterQuery|Sort|Pagination 2024-06-14 17:24:59 +02:00
reflectext v0.0.480 2024-07-02 11:32:22 +02:00
rext v0.0.244 2023-08-18 13:27:02 +02:00
rfctime v0.0.434 2024-04-15 10:43:26 +02:00
scn v0.0.353 add scn.sendmessage 2024-01-04 12:38:03 +01:00
sq v0.0.408 2024-03-11 16:41:47 +01:00
syncext v0.0.315 atomic 2023-11-12 03:10:55 +01:00
termext Fix tests 2023-08-14 16:32:39 +02:00
timeext v0.0.481 2024-07-04 16:24:49 +02:00
totpext remove ginext/mongoext (no-dep lib) 2022-10-27 16:07:42 +02:00
tst v0.0.383 sq.InsertMultiple 2024-02-09 15:17:51 +01:00
wmo v0.0.491 small optimization in Paginate method 2024-07-31 00:15:09 +02:00
wpdf v0.0.501 2024-08-07 19:31:36 +02:00
zipext remove ginext/mongoext (no-dep lib) 2022-10-27 16:07:42 +02:00
.gitignore copy langext & timeext from bm 2022-10-27 16:00:57 +02:00
go.mod v0.0.493 fix panic in RegisterImage for very short images 2024-08-07 09:22:37 +02:00
go.sum v0.0.493 fix panic in RegisterImage for very short images 2024-08-07 09:22:37 +02:00
goextVersion.go v0.0.501 2024-08-07 19:31:36 +02:00
LICENSE copy langext & timeext from bm 2022-10-27 16:00:57 +02:00
Makefile try to fix test 'cmdext:TestFailOnStderr' 2023-09-25 18:04:56 +02:00
README.md v0.0.490 documentation and extra-params in exerr 2024-07-27 23:44:18 +02:00
TODO.md v0.0.402 add PackageName() and TypeName() to enums_codegen 2024-03-10 12:49:31 +01:00

BFB goext library

A collection of general & useful library methods

This should not have any heavy dependencies (gin, mongo, etc) and add missing basic language features...

Potentially needs export GOPRIVATE="gogs.mikescher.com"

Packages:

Name Maintainer Description
langext Mike General uttility/helper functions, (everything thats missing from go standard library)
mathext Mike Utility/Helper functions for math
cryptext Mike Utility/Helper functions for encryption
syncext Mike Utility/Helper funtions for multi-threading / mutex / channels
dataext Mike Various useful data structures
zipext Mike Utility for zip/gzip/tar etc
reflectext Mike Utility for golang reflection
fsext Mike Utility for filesytem access
mongoext Mike Utility/Helper functions for mongodb (kinda abandoned)
cursortoken Mike MongoDB cursortoken implementation
pagination Mike Pagination implementation
totpext Mike Implementation of TOTP (2-Factor-Auth)
termext Mike Utilities for terminals (mostly color output)
confext Mike Parses environment configuration into structs
cmdext Mike Runner for external commands/processes
sq Mike Utility functions for sql based databases (primarily sqlite)
tst Mike Utility functions for unit tests
rfctime Mike Classes for time seriallization, with different marshallign method for mongo and json
gojson Mike Same interface for marshalling/unmarshalling as go/json, except with proper serialization of null arrays/maps
bfcodegen Mike Various codegen tools (run via go generate)
rext Mike Regex Wrapper, wraps regexp with a better interface
wmo Mike Mongo Wrapper, wraps mongodb with a better interface
scn Mike SimpleCloudNotifier

Usage:

exerr

  • see mongoext/builder.go for full info

Short summary:

  • An better error package with metadata, listener, api-output and error-traces
  • Initialize with exerr.Init()
  • Never return err direct, always use exerr.Wrap(err, "...") - add metadata where applicable
  • at the end either Print(), Fatal() or Output() your error (print = stdout, fatal = panic, output = json API response)
  • You can add listeners with exerr.RegisterListener(), and save the full errors to a db or smth

wmo

  • A typed wrapper around the official mongo-go-driver
  • Use wmo.W[...](...) to wrap the collections and type-ify them
  • The new collections have all the usual methods, but types
  • Also they have List() and Paginate() methods for paginated listings (witehr with a cursortoken or page/limit)
  • Register additional hooks with WithDecodeFunc, WithUnmarshalHook, WithMarshalHook, WithModifyingPipeline, WithModifyingPipelineFunc
  • List(), Paginate(), etc support filter interfaces
    • Rule(s) of thumb:
      • filter the results in the filter interface
      • sort the results in the sort function of the filter interface
      • add joins ($lookup's) in the WithModifyingPipelineFunc/WithModifyingPipeline

ginext

  • A wrapper around gin-gonic/gin
  • create the gin engine with ginext.NewEngine
  • Add routes with engine.Routes()...
    • .Use(..) adds a middleware
    • .Group(..) adds a group
    • .Get().Handle(..) adds a handler
  • Handler return values (in contract to ginext) - values implement the ginext.HTTPResponse interface
  • Every handler starts with something like:
func (handler Handler) CommunityMetricsValues(pctx ginext.PreContext) ginext.HTTPResponse {
    type communityURI struct {
        Version     string             `uri:"version"`
        CommunityID models.CommunityID `uri:"cid"`
    }
    type body struct {
        UserID  models.UserID  `json:"userID"`
        EventID models.EventID `json:"eventID"`
    }

    var u uri
    var b body
    ctx, gctx, httpErr := pctx.URI(&u).Body(&b).Start() // can have more unmarshaller, like header, form, etc
    if httpErr != nil {
    	return *httpErr
    }
    defer ctx.Cancel()

    // do stuff
}

sq

  • TODO (like mongoext for sqlite/sql databases)