v0.0.490 documentation and extra-params in exerr
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m2s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m2s
This commit is contained in:
71
README.md
71
README.md
@@ -8,7 +8,7 @@ This should not have any heavy dependencies (gin, mongo, etc) and add missing ba
|
||||
Potentially needs `export GOPRIVATE="gogs.mikescher.com"`
|
||||
|
||||
|
||||
### Packages:
|
||||
## Packages:
|
||||
|
||||
| Name | Maintainer | Description |
|
||||
|-------------|------------|---------------------------------------------------------------------------------------------------------------|
|
||||
@@ -21,7 +21,7 @@ Potentially needs `export GOPRIVATE="gogs.mikescher.com"`
|
||||
| reflectext | Mike | Utility for golang reflection |
|
||||
| fsext | Mike | Utility for filesytem access |
|
||||
| | | |
|
||||
| mongoext | Mike | Utility/Helper functions for mongodb |
|
||||
| mongoext | Mike | Utility/Helper functions for mongodb (kinda abandoned) |
|
||||
| cursortoken | Mike | MongoDB cursortoken implementation |
|
||||
| pagination | Mike | Pagination implementation |
|
||||
| | | |
|
||||
@@ -42,4 +42,69 @@ Potentially needs `export GOPRIVATE="gogs.mikescher.com"`
|
||||
| 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:
|
||||
```go
|
||||
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)
|
Reference in New Issue
Block a user