Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyComp[T any](c *T, modifiers ...CompOption[T]) T
- func ApplyMeta[T any](m *T, modifiers ...MetaOption[T]) T
- type AtlasDataType
- type BSONOperator
- type Base64Decoder
- type CacheHit
- type CacheHitter
- type CacheID
- type CacheIdentifier
- type CacheKey
- type CacheMulti
- type CacheOperator
- type Cacher
- type CertGenerator
- type ChangeEvent
- type CompOption
- type DBOperator
- type DateFilterOptions
- type DecodeCursorOptions
- type DeleteManyOptions
- type DeleteOneOptions
- type ElemMatchFilterOptions
- type ElemsInArrayFilterOptions
- type FSysFileReader
- type FieldInArrayFilterOptions
- type FilterOptions
- type FindManyOptions
- type FindOneOptions
- type Geocoder
- type GoogleMaps
- type GzipReader
- type GzipUtil
- type GzipWriter
- type HTTPClient
- type HTTPDoer
- type HTTPRequester
- type HTTPWriter
- type Identifiable
- type Identifier
- type IndexEntry
- type InsertOneOptions
- type JSONOption
- type JSONOptions
- type Level
- type Logger
- type Marshaler
- type MatchBehavior
- type MetaOption
- type MongoChangeStream
- type MongoClient
- type MongoCollection
- type MongoCursor
- type MongoDatabase
- type MongoFilter
- type MongoLookupTarget
- type MongoOperator
- type MongoOutCSChan
- type MongoPipeliner
- type MongoSpecialized
- type MongoUtil
- type MongoVerb
- type PaginationOptions
- type ProcessChangeStreamOptions
- type PubSubMessage
- type Reader
- type RedisClient
- type ReplaceOneOptions
- type RequestOption
- type RequestOptions
- type RespAuth
- type RespAuthorize
- type RespAuthorizeMany
- type RespErr
- type RespMsg
- type RespOperation
- type RespSearch
- type SearchIndexEntry
- type SearchOptions
- type Semaphore
- type SortDirection
- type TextOptions
- type Tool
- type ToolOption
- type ToolOptions
- type Unmarshaler
- type VectorSearchField
- type WatchCollectionOptions
- type WatchDBOptions
Constants ¶
const ( MongoLookupFullDocument MongoLookupTarget = "fullDocument" MongoLookupDocumentKey MongoLookupTarget = "documentKey" MongoLookupOperationType MongoLookupTarget = "operationType" TypeArray AtlasDataType = "array" TypeBoolean AtlasDataType = "boolean" TypeDate AtlasDataType = "date" TypeFacetDate AtlasDataType = "dateFacet" TypeNumber AtlasDataType = "number" TypeFacetNumber AtlasDataType = "numberFacet" TypeGeo AtlasDataType = "geo" TypeDocument AtlasDataType = "document" TypeEmbeddedDoc AtlasDataType = "embeddedDocument" TypeObjectID AtlasDataType = "objectId" TypeString AtlasDataType = "string" TypeFacetString AtlasDataType = "stringFacet" TypeAutocomplete AtlasDataType = "autocomplete" TypeToken AtlasDataType = "token" VerbElemMatch MongoVerb = "$elemMatch" VerbMatch MongoVerb = "$match" VerbSkip MongoVerb = "$skip" VerbLimit MongoVerb = "$limit" VerbSort MongoVerb = "$sort" VerbCount MongoVerb = "$count" VerbSearch MongoVerb = "$search" OpAnd BSONOperator = "$and" OpOr BSONOperator = "$or" OpNor BSONOperator = "$nor" OpGT BSONOperator = "$gt" OpGTE BSONOperator = "$gte" OpLT BSONOperator = "$lt" OpLTE BSONOperator = "$lte" OpNE BSONOperator = "$ne" OpIn BSONOperator = "$in" OpNin BSONOperator = "$nin" Ascending SortDirection = 1 Descending SortDirection = -1 MatchAll MatchBehavior = "$all" MatchIn MatchBehavior = "$in" MatchEqual MatchBehavior = "$eq" )
const DefaultIndent = " "
Variables ¶
var ErrInvalidInput = errors.New("invalid input")
Functions ¶
func ApplyComp ¶
func ApplyComp[T any](c *T, modifiers ...CompOption[T]) T
func ApplyMeta ¶
func ApplyMeta[T any](m *T, modifiers ...MetaOption[T]) T
Types ¶
type AtlasDataType ¶ added in v0.0.5
type AtlasDataType = string
AtlasDataType represents the data types recognized by MongoDB Atlas.
type BSONOperator ¶ added in v0.0.5
type BSONOperator = string
BSONOperator represents BSON query operators in MongoDB.
type Base64Decoder ¶ added in v0.0.5
type CacheHit ¶ added in v0.0.5
type CacheHit struct {
V string `json:"v"`
}
CacheHit represents a cache entry that holds a JSON string.
type CacheHitter ¶ added in v0.0.5
type CacheIdentifier ¶ added in v0.0.5
type CacheKey ¶ added in v0.0.5
type CacheKey struct {
ID fmt.Stringer
Microservice string
Collection string
Multi *CacheMulti
}
CacheKey represents a cache key. It is used to identify a cache entry & it can be used to generate a matching pattern using wildcards.
type CacheMulti ¶ added in v0.0.5
type CacheMulti struct {
RawQuery string
}
type CacheOperator ¶ added in v0.0.5
type CacheOperator interface {
Get(ctx context.Context, c CacheKey) (*CacheHit, error)
Set(ctx context.Context, c CacheKey, v CacheHit) error
BatchGet(ctx context.Context, c []CacheKey) ([]CacheHit, error)
BatchSet(ctx context.Context, e map[CacheKey]CacheHit) error
Flush(ctx context.Context, c CacheKey) error
BatchFlush(ctx context.Context, c []CacheKey) error
FlushAll(ctx context.Context) error
}
type Cacher ¶ added in v0.0.5
type Cacher interface {
CacheIdentifier
CacheHitter
CacheOperator
}
type CertGenerator ¶ added in v0.0.5
type ChangeEvent ¶ added in v0.0.5
type CompOption ¶
type CompOption[T any] func(*T)
type DBOperator ¶ added in v0.0.5
type DBOperator interface {
InsertOne(ctx context.Context, opts InsertOneOptions) error
FindOne(ctx context.Context, opts FindOneOptions) error
FindMany(ctx context.Context, opts FindManyOptions) ([]any, error)
ReplaceOne(ctx context.Context, opts ReplaceOneOptions) error
DeleteOne(ctx context.Context, opts DeleteOneOptions) error
DeleteMany(ctx context.Context, opts DeleteManyOptions) error
}
type DateFilterOptions ¶ added in v0.0.5
type DecodeCursorOptions ¶ added in v0.0.5
type DecodeCursorOptions struct {
Cursor MongoCursor
Receiver any
}
type DeleteManyOptions ¶ added in v0.0.5
type DeleteManyOptions struct {
Collection MongoCollection
Filter bson.M
}
type DeleteOneOptions ¶ added in v0.0.5
type DeleteOneOptions struct {
Collection MongoCollection
IDKey string
ID Identifier
}
type ElemMatchFilterOptions ¶ added in v0.0.5
type ElemsInArrayFilterOptions ¶ added in v0.0.5
type FSysFileReader ¶
type FSysFileReader interface {
FSysReadFile(fsys fs.ReadFileFS, path string) ([]byte, error)
}
type FieldInArrayFilterOptions ¶ added in v0.0.5
type FilterOptions ¶ added in v0.0.5
type FindManyOptions ¶ added in v0.0.5
type FindManyOptions struct {
Collection MongoCollection
Filter bson.M
SortByKey string
SortDirection SortDirection
Skip int64
Limit int64
Receiver any
}
type FindOneOptions ¶ added in v0.0.5
type FindOneOptions struct {
Collection MongoCollection
Receiver any
IDKey string
ID Identifier
}
type Geocoder ¶
type Geocoder interface {
TimezoneFromCoordinates(ctx context.Context, latitude, longitude float64) (string, error)
CityFromCoordinates(ctx context.Context, latitude, longitude float64) (string, error)
TimezoneDataFromCoordinates(ctx context.Context, latitude, longitude float64) (*maps.TimezoneResult, error)
GeocodeCoordinates(ctx context.Context, latitude, longitude float64) ([]maps.GeocodingResult, error)
SwapTimezone(t time.Time, tz string, toUTC, toMidnight bool) (time.Time, error)
IsUTC(t time.Time) bool
}
type GoogleMaps ¶ added in v0.0.5
type GoogleMaps interface {
Timezone(ctx context.Context, r *maps.TimezoneRequest) (*maps.TimezoneResult, error)
Geocode(ctx context.Context, r *maps.GeocodingRequest) ([]maps.GeocodingResult, error)
}
type HTTPClient ¶ added in v0.0.5
type HTTPRequester ¶
type HTTPWriter ¶
type HTTPWriter interface {
Write(w http.ResponseWriter, b []byte) (int, error)
}
type Identifiable ¶ added in v0.0.5
type Identifiable interface {
GetID() Identifier
}
type Identifier ¶ added in v0.0.5
type IndexEntry ¶ added in v0.0.5
type InsertOneOptions ¶ added in v0.0.5
type InsertOneOptions struct {
Collection MongoCollection
Document Identifiable
}
type JSONOption ¶
type JSONOption func(*JSONOptions)
func WithJSONEscapeHTML ¶
func WithJSONEscapeHTML(escape bool) JSONOption
func WithJSONIndent ¶
func WithJSONIndent(indent string) JSONOption
func WithJSONUseNumber ¶
func WithJSONUseNumber(use bool) JSONOption
type JSONOptions ¶
type JSONOptions struct {
Indent string // Enables indentation if non-empty.
EscapeHTML bool // Determines if HTML characters should be escaped.
UseNumber bool // If true, decodes numbers as `json.Number` instead of `float64`.
}
JSONOptions defines settings for encoding/decoding.
func ApplyJSONOptions ¶
func ApplyJSONOptions(opts *JSONOptions, modifiers ...JSONOption) JSONOptions
type MatchBehavior ¶ added in v0.0.5
type MatchBehavior = string
MatchBehavior defines different matching behaviors in MongoDB queries, such as in, all, and eq.
type MetaOption ¶
type MetaOption[T any] func(*T)
type MongoChangeStream ¶ added in v0.0.5
type MongoClient ¶ added in v0.0.5
type MongoCollection ¶ added in v0.0.5
type MongoCollection interface {
InsertOne(ctx context.Context, document any, opts ...options.Lister[options.InsertOneOptions]) (*mongo.InsertOneResult, error)
FindOne(ctx context.Context, filter any, opts ...options.Lister[options.FindOneOptions]) *mongo.SingleResult
Find(ctx context.Context, filter any, opts ...options.Lister[options.FindOptions]) *mongo.Cursor
ReplaceOne(ctx context.Context, filter any, document any, opts ...options.Lister[options.ReplaceOptions]) (*mongo.UpdateResult, error)
DeleteOne(ctx context.Context, filter any, opts ...options.Lister[options.DeleteOneOptions]) (*mongo.DeleteResult, error)
DeleteMany(ctx context.Context, filter any, opts ...options.Lister[options.DeleteManyOptions]) (*mongo.DeleteResult, error)
Aggregate(ctx context.Context, pipeline any, opts ...options.Lister[options.AggregateOptions]) (*mongo.Cursor, error)
Watch(ctx context.Context, pipeline any, opts ...options.Lister[options.ChangeStreamOptions]) (*mongo.ChangeStream, error)
}
type MongoCursor ¶ added in v0.0.5
type MongoDatabase ¶ added in v0.0.5
type MongoDatabase interface {
Watch(ctx context.Context, pipeline any, opts ...options.Lister[options.ChangeStreamOptions]) (*mongo.ChangeStream, error)
}
type MongoFilter ¶ added in v0.0.5
type MongoFilter interface {
Filter(opts FilterOptions) (bson.M, error)
FilterByFieldInArray(opts FieldInArrayFilterOptions) bson.M
FilterByElemMatch(opts ElemMatchFilterOptions) bson.M
FilterByElemsInArray(opts ElemsInArrayFilterOptions) bson.M
FilterByAllElemsInArray(opts ElemsInArrayFilterOptions) bson.M
FilterByFutureDate(opts DateFilterOptions) bson.D
FilterByPastDate(opts DateFilterOptions) bson.D
FilterByExactDate(opts DateFilterOptions) bson.D
CombineM(op BSONOperator, m ...bson.M) bson.M
}
type MongoLookupTarget ¶ added in v0.0.5
type MongoLookupTarget = string
MongoLookupTarget specifies the target field for the lookup stage in a MongoDB aggregation pipeline.
type MongoOperator ¶ added in v0.0.5
type MongoOperator interface {
MongoUtil
MongoFilter
MongoSpecialized
}
type MongoOutCSChan ¶ added in v0.0.5
type MongoOutCSChan = chan *ChangeEvent
MongoOutCSChan is a channel type used for sending decoded MongoDB change events.
type MongoPipeliner ¶ added in v0.0.5
type MongoSpecialized ¶ added in v0.0.5
type MongoSpecialized interface {
Search(ctx context.Context, opts SearchOptions) (*RespSearch, error)
WatchCollection(ctx context.Context, opts WatchCollectionOptions) error
WatchDB(ctx context.Context, opts WatchDBOptions) error
ProcessChangeStream(ctx context.Context, opts ProcessChangeStreamOptions) error
}
type MongoUtil ¶ added in v0.0.5
type MongoUtil interface {
CreateCollections(ctx context.Context, db string, collections ...string) error
CreateIndexes(ctx context.Context, db, collection string, e []IndexEntry) error
CreateSearchIndexes(ctx context.Context, db, collection string, e []SearchIndexEntry) error
NewTransactionSession(ctx context.Context) (context.Context, error)
}
type MongoVerb ¶ added in v0.0.5
type MongoVerb = string
MongoVerb defines a MongoDB operation keyword, such as match.
type PaginationOptions ¶ added in v0.0.5
func (*PaginationOptions) Verify ¶ added in v0.0.5
func (p *PaginationOptions) Verify() error
type ProcessChangeStreamOptions ¶ added in v0.0.5
type ProcessChangeStreamOptions struct {
ChangeStream MongoChangeStream
LookupKey string
Receiver any
Output MongoOutCSChan
}
type PubSubMessage ¶ added in v0.0.5
type RedisClient ¶ added in v0.0.5
type RedisClient interface {
Get(ctx context.Context, key string) *redis.StringCmd
Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd
FlushAll(ctx context.Context) *redis.StatusCmd
Scan(ctx context.Context, cursor uint64, match string, count int64) *redis.ScanCmd
TxPipeline() redis.Pipeliner
}
type ReplaceOneOptions ¶ added in v0.0.5
type ReplaceOneOptions struct {
Collection MongoCollection
Document Identifiable
IDKey string
ID Identifier
}
type RequestOption ¶
type RequestOption func(*RequestOptions)
func WithRequestBody ¶
func WithRequestBody(body io.Reader) RequestOption
func WithRequestHeader ¶
func WithRequestHeader(header http.Header) RequestOption
type RequestOptions ¶
func ApplyRequestOptions ¶
func ApplyRequestOptions(opts *RequestOptions, modifiers ...RequestOption) RequestOptions
type RespAuth ¶ added in v0.0.5
type RespAuth struct {
// Message is a descriptive message about the authentication result, written in Title Case.
// example:Login Successful
// readOnly:true
Message string `json:"message"`
// User contains the authenticated user's details.
// example:{"id":"123","name":"John Doe"}
// readOnly:true
User map[string]any `json:"user"`
}
RespAuth represents the response from an authentication operation. swagger:model
type RespAuthorize ¶ added in v0.0.5
type RespAuthorize struct {
// Code is the HTTP status code.
// example:200
// readOnly:true
Code int `json:"code"`
}
RespAuthorize represents an authorization response for a single entity. swagger:model
type RespAuthorizeMany ¶ added in v0.0.5
type RespAuthorizeMany struct {
// UnallowedEntities is the list of unauthorized entity IDs.
// example:["5f6d4b9b9c6f9f0001b9c6f9"]
// readOnly:true
UnallowedEntities []primitive.ObjectID `json:"unallowed_entities"`
}
RespAuthorizeMany represents an authorization response for multiple entities. swagger:model
type RespErr ¶ added in v0.0.5
type RespErr struct {
// Code is the HTTP status code or custom error code.
// example:400
// readOnly:true
Code int `json:"code"`
// Message describes the error, written in Title Case.
// example:Internal Server Error
// readOnly:true
Message string `json:"message"`
}
RespErr represents a standard error response from the application. swagger:model
type RespMsg ¶ added in v0.0.5
type RespMsg struct {
// Message is the response message, written in Title Case.
// example:Operation Completed
// readOnly:true
Message string `json:"message"`
}
RespMsg represents a simple message response from the application. swagger:model
type RespOperation ¶ added in v0.0.5
type RespOperation struct {
// Message describes the result of the operation, written in Title Case.
// example:Record Created Successfully
// readOnly:true
Message string `json:"message"`
// ID is the identifier of the affected resource.
// example:5f7b1b9b9b9b9b9b9b9b9b9b
// readOnly:true
ID string `json:"_id"`
}
RespOperation represents a standard response from a CRUD operation. swagger:model
type RespSearch ¶ added in v0.0.5
type RespSearch struct {
// Results is the list of search results.
// example:[{"id":"1","name":"Item1"},{"id":"2","name":"Item2"}]
// readOnly:true
Results []any `json:"results"`
// TotalCount is the total number of matching results.
// example:100
// readOnly:true
TotalCount int32 `json:"total_count"`
// LastPage is the last page number based on total results.
// example:10
// readOnly:true
LastPage int32 `json:"last_page"`
}
RespSearch represents the response from a search operation. swagger:model
type SearchIndexEntry ¶ added in v0.0.5
type SearchOptions ¶ added in v0.0.5
type SearchOptions struct {
Filter bson.M
T *TextOptions
P *PaginationOptions
SortByKey string
SortDirection SortDirection
Collection MongoCollection
Receiver any
}
type SortDirection ¶ added in v0.0.5
type SortDirection int
SortDirection represents the sorting order for MongoDB queries.
type TextOptions ¶ added in v0.0.5
type ToolOption ¶
type ToolOption[C any] func(*ToolOptions[C])
func WithLogger ¶
func WithLogger[C any](l Logger) ToolOption[C]
type ToolOptions ¶
func ApplyOptions ¶
func ApplyOptions[C any](opts *ToolOptions[C], modifiers ...ToolOption[C]) ToolOptions[C]
type Unmarshaler ¶
type Unmarshaler interface {
Unmarshal(data io.Reader, v any, opts JSONOptions) error
}
type VectorSearchField ¶ added in v0.0.5
type WatchCollectionOptions ¶ added in v0.0.5
type WatchCollectionOptions struct {
Collection MongoCollection
Receiver any
Pipeline MongoPipeliner
Options *options.ChangeStreamOptionsBuilder
LookupKey string
Output MongoOutCSChan
}
type WatchDBOptions ¶ added in v0.0.5
type WatchDBOptions struct {
Database MongoDatabase
Receiver any
Pipeline MongoPipeliner
Options *options.ChangeStreamOptionsBuilder
LookupKey string
Output MongoOutCSChan
}