mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-27 13:48:49 +08:00

* Return Auth service Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Compose to run with SpiceDB and Auth svc Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth gRPC API Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove Users' policies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Groups to internal Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use shared groups in Users Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove unused code Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use pkg Groups in Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove Things groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Make imports consistent Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Groups networking Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove things groups-specific API Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Things Clients to the root Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Clients to Users root Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Temporarily remove tracing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix imports Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add buffer config for gRPC Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth type for Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use Auth for login Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add temporary solution for refresh token Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Tokenizer interface Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Updade tokens issuing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix token issuing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update JWT validator and refactor Tokenizer Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Rename access timeout Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Rename login to authenticate Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Identify to use SubjectID Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add Auth to Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use the Auth service for Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth schema Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix Auth for Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add auth for addons (#14) Signed-off-by: Arvindh <arvindh91@gmail.com> Speparate Login and Refresh tokens Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Merge authN and authZ requests for things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add connect and disconnect Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update sharing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix policies addition and removal Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update relation with roels Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add gRPC to Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Assign and Unassign members to group and Listing of Group members (#15) * add auth for addons Signed-off-by: Arvindh <arvindh91@gmail.com> * add assign and unassign to group Signed-off-by: Arvindh <arvindh91@gmail.com> * add group incomplete repo implementation Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Move coap mqtt and ws policies to spicedb (#16) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Remove old policies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> NOISSUE - Things authorize to return thingID (#18) This commit modifies the authorize endpoint to the grpc endpoint to return thingID. The authorize endpoint allows adapters to get the publisher of the message. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Add Groups to users service (#17) * add assign and unassign to group Signed-off-by: Arvindh <arvindh91@gmail.com> * add group incomplete repo implementation Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users stable 1 Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users stable 2 Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users & things Signed-off-by: Arvindh <arvindh91@gmail.com> * Amend signature Signed-off-by: Arvindh <arvindh91@gmail.com> * fix merge error Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Fix es code (#21) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Fix Bugs (#20) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Test e2e (#19) * fix: connect method Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix: e2e Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix changes in sdk and e2e Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(docker): remove unnecessary port mapping Remove the port mapping for MQTT broker in the docker-compose.yml file. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Enable group listing Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(responses): update ChannelsPage struct The ChannelsPage struct in the responses.go file has been updated. The "Channels" field has been renamed to "Groups" to provide more accurate naming. This change ensures consistency and clarity in the codebase. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(things): add UpdateClientSecret method Add the UpdateClientSecret method to the things service. This method allows updating the client secret for a specific client identified by the provided token, id, and key parameters. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Use smaller buffers for gRPC Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Clean up tests (#22) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add Connect Disconnect endpoints (#23) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Things share with users (#25) * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * add: things share with other users Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Rename gRPC Services (#24) * Rename things and users auth service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * docs: add authorization docs for gRPC services Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Rename things and users grpc services Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Remove mainflux.env package Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Listing of things, channels, groups, users (#26) * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Users (#27) * feat(groups): rename redis package to events - Renamed the `redis` package to `events` in the `internal/groups` directory. - Updated the file paths and names accordingly. - This change reflects the more accurate purpose of the package and improves code organization. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(auth): Modify identity method Change request and response of identity method Add accessToken and refreshToken to Token response Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * clean up users, remove dead code Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(users): add unit tests for user service This commit adds unit tests for the user service in the `users` package. The tests cover various scenarios and ensure the correct behavior of the service. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: List of user groups & removed repeating code in groups (#29) * removed repeating code in list groups Signed-off-by: Arvindh <arvindh91@gmail.com> * add: list of user group Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: otel handler operator name for endpoints Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Things Service (#28) * Rework things service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * add tests Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Auth Service (#30) * clean up auth service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(auth): remove unused import Remove the unused import of `emptypb` in `auth.pb.go`. This import is not being used in the codebase and can be safely removed. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Update API docs (#31) Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Remove TODO comments and cleanup the code Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Update dependenices Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Co-authored-by: b1ackd0t <28790446+rodneyosodo@users.noreply.github.com> Co-authored-by: Arvindh <30824765+arvindh123@users.noreply.github.com>
321 lines
13 KiB
Go
321 lines
13 KiB
Go
// Copyright (C) MongoDB, Inc. 2017-present.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
// not use this file except in compliance with the License. You may obtain
|
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
package bson
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
"reflect"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
|
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
|
"go.mongodb.org/mongo-driver/bson/bsontype"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
|
|
)
|
|
|
|
// ErrNilContext is returned when the provided DecodeContext is nil.
|
|
var ErrNilContext = errors.New("DecodeContext cannot be nil")
|
|
|
|
// ErrNilRegistry is returned when the provided registry is nil.
|
|
var ErrNilRegistry = errors.New("Registry cannot be nil")
|
|
|
|
// RawValue is a raw encoded BSON value. It can be used to delay BSON value decoding or precompute
|
|
// BSON encoded value. Type is the BSON type of the value and Value is the raw encoded BSON value.
|
|
//
|
|
// A RawValue must be an individual BSON value. Use the Raw type for full BSON documents.
|
|
type RawValue struct {
|
|
Type bsontype.Type
|
|
Value []byte
|
|
|
|
r *bsoncodec.Registry
|
|
}
|
|
|
|
// IsZero reports whether the RawValue is zero, i.e. no data is present on
|
|
// the RawValue. It returns true if Type is 0 and Value is empty or nil.
|
|
func (rv RawValue) IsZero() bool {
|
|
return rv.Type == 0x00 && len(rv.Value) == 0
|
|
}
|
|
|
|
// Unmarshal deserializes BSON into the provided val. If RawValue cannot be unmarshaled into val, an
|
|
// error is returned. This method will use the registry used to create the RawValue, if the RawValue
|
|
// was created from partial BSON processing, or it will use the default registry. Users wishing to
|
|
// specify the registry to use should use UnmarshalWithRegistry.
|
|
func (rv RawValue) Unmarshal(val interface{}) error {
|
|
reg := rv.r
|
|
if reg == nil {
|
|
reg = DefaultRegistry
|
|
}
|
|
return rv.UnmarshalWithRegistry(reg, val)
|
|
}
|
|
|
|
// Equal compares rv and rv2 and returns true if they are equal.
|
|
func (rv RawValue) Equal(rv2 RawValue) bool {
|
|
if rv.Type != rv2.Type {
|
|
return false
|
|
}
|
|
|
|
if !bytes.Equal(rv.Value, rv2.Value) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// UnmarshalWithRegistry performs the same unmarshalling as Unmarshal but uses the provided registry
|
|
// instead of the one attached or the default registry.
|
|
func (rv RawValue) UnmarshalWithRegistry(r *bsoncodec.Registry, val interface{}) error {
|
|
if r == nil {
|
|
return ErrNilRegistry
|
|
}
|
|
|
|
vr := bsonrw.NewBSONValueReader(rv.Type, rv.Value)
|
|
rval := reflect.ValueOf(val)
|
|
if rval.Kind() != reflect.Ptr {
|
|
return fmt.Errorf("argument to Unmarshal* must be a pointer to a type, but got %v", rval)
|
|
}
|
|
rval = rval.Elem()
|
|
dec, err := r.LookupDecoder(rval.Type())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return dec.DecodeValue(bsoncodec.DecodeContext{Registry: r}, vr, rval)
|
|
}
|
|
|
|
// UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses the provided DecodeContext
|
|
// instead of the one attached or the default registry.
|
|
func (rv RawValue) UnmarshalWithContext(dc *bsoncodec.DecodeContext, val interface{}) error {
|
|
if dc == nil {
|
|
return ErrNilContext
|
|
}
|
|
|
|
vr := bsonrw.NewBSONValueReader(rv.Type, rv.Value)
|
|
rval := reflect.ValueOf(val)
|
|
if rval.Kind() != reflect.Ptr {
|
|
return fmt.Errorf("argument to Unmarshal* must be a pointer to a type, but got %v", rval)
|
|
}
|
|
rval = rval.Elem()
|
|
dec, err := dc.LookupDecoder(rval.Type())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return dec.DecodeValue(*dc, vr, rval)
|
|
}
|
|
|
|
func convertFromCoreValue(v bsoncore.Value) RawValue { return RawValue{Type: v.Type, Value: v.Data} }
|
|
func convertToCoreValue(v RawValue) bsoncore.Value {
|
|
return bsoncore.Value{Type: v.Type, Data: v.Value}
|
|
}
|
|
|
|
// Validate ensures the value is a valid BSON value.
|
|
func (rv RawValue) Validate() error { return convertToCoreValue(rv).Validate() }
|
|
|
|
// IsNumber returns true if the type of v is a numeric BSON type.
|
|
func (rv RawValue) IsNumber() bool { return convertToCoreValue(rv).IsNumber() }
|
|
|
|
// String implements the fmt.String interface. This method will return values in extended JSON
|
|
// format. If the value is not valid, this returns an empty string
|
|
func (rv RawValue) String() string { return convertToCoreValue(rv).String() }
|
|
|
|
// DebugString outputs a human readable version of Document. It will attempt to stringify the
|
|
// valid components of the document even if the entire document is not valid.
|
|
func (rv RawValue) DebugString() string { return convertToCoreValue(rv).DebugString() }
|
|
|
|
// Double returns the float64 value for this element.
|
|
// It panics if e's BSON type is not bsontype.Double.
|
|
func (rv RawValue) Double() float64 { return convertToCoreValue(rv).Double() }
|
|
|
|
// DoubleOK is the same as Double, but returns a boolean instead of panicking.
|
|
func (rv RawValue) DoubleOK() (float64, bool) { return convertToCoreValue(rv).DoubleOK() }
|
|
|
|
// StringValue returns the string value for this element.
|
|
// It panics if e's BSON type is not bsontype.String.
|
|
//
|
|
// NOTE: This method is called StringValue to avoid a collision with the String method which
|
|
// implements the fmt.Stringer interface.
|
|
func (rv RawValue) StringValue() string { return convertToCoreValue(rv).StringValue() }
|
|
|
|
// StringValueOK is the same as StringValue, but returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) StringValueOK() (string, bool) { return convertToCoreValue(rv).StringValueOK() }
|
|
|
|
// Document returns the BSON document the Value represents as a Document. It panics if the
|
|
// value is a BSON type other than document.
|
|
func (rv RawValue) Document() Raw { return Raw(convertToCoreValue(rv).Document()) }
|
|
|
|
// DocumentOK is the same as Document, except it returns a boolean
|
|
// instead of panicking.
|
|
func (rv RawValue) DocumentOK() (Raw, bool) {
|
|
doc, ok := convertToCoreValue(rv).DocumentOK()
|
|
return Raw(doc), ok
|
|
}
|
|
|
|
// Array returns the BSON array the Value represents as an Array. It panics if the
|
|
// value is a BSON type other than array.
|
|
func (rv RawValue) Array() Raw { return Raw(convertToCoreValue(rv).Array()) }
|
|
|
|
// ArrayOK is the same as Array, except it returns a boolean instead
|
|
// of panicking.
|
|
func (rv RawValue) ArrayOK() (Raw, bool) {
|
|
doc, ok := convertToCoreValue(rv).ArrayOK()
|
|
return Raw(doc), ok
|
|
}
|
|
|
|
// Binary returns the BSON binary value the Value represents. It panics if the value is a BSON type
|
|
// other than binary.
|
|
func (rv RawValue) Binary() (subtype byte, data []byte) { return convertToCoreValue(rv).Binary() }
|
|
|
|
// BinaryOK is the same as Binary, except it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) BinaryOK() (subtype byte, data []byte, ok bool) {
|
|
return convertToCoreValue(rv).BinaryOK()
|
|
}
|
|
|
|
// ObjectID returns the BSON objectid value the Value represents. It panics if the value is a BSON
|
|
// type other than objectid.
|
|
func (rv RawValue) ObjectID() primitive.ObjectID { return convertToCoreValue(rv).ObjectID() }
|
|
|
|
// ObjectIDOK is the same as ObjectID, except it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) ObjectIDOK() (primitive.ObjectID, bool) {
|
|
return convertToCoreValue(rv).ObjectIDOK()
|
|
}
|
|
|
|
// Boolean returns the boolean value the Value represents. It panics if the
|
|
// value is a BSON type other than boolean.
|
|
func (rv RawValue) Boolean() bool { return convertToCoreValue(rv).Boolean() }
|
|
|
|
// BooleanOK is the same as Boolean, except it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) BooleanOK() (bool, bool) { return convertToCoreValue(rv).BooleanOK() }
|
|
|
|
// DateTime returns the BSON datetime value the Value represents as a
|
|
// unix timestamp. It panics if the value is a BSON type other than datetime.
|
|
func (rv RawValue) DateTime() int64 { return convertToCoreValue(rv).DateTime() }
|
|
|
|
// DateTimeOK is the same as DateTime, except it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) DateTimeOK() (int64, bool) { return convertToCoreValue(rv).DateTimeOK() }
|
|
|
|
// Time returns the BSON datetime value the Value represents. It panics if the value is a BSON
|
|
// type other than datetime.
|
|
func (rv RawValue) Time() time.Time { return convertToCoreValue(rv).Time() }
|
|
|
|
// TimeOK is the same as Time, except it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) TimeOK() (time.Time, bool) { return convertToCoreValue(rv).TimeOK() }
|
|
|
|
// Regex returns the BSON regex value the Value represents. It panics if the value is a BSON
|
|
// type other than regex.
|
|
func (rv RawValue) Regex() (pattern, options string) { return convertToCoreValue(rv).Regex() }
|
|
|
|
// RegexOK is the same as Regex, except it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) RegexOK() (pattern, options string, ok bool) {
|
|
return convertToCoreValue(rv).RegexOK()
|
|
}
|
|
|
|
// DBPointer returns the BSON dbpointer value the Value represents. It panics if the value is a BSON
|
|
// type other than DBPointer.
|
|
func (rv RawValue) DBPointer() (string, primitive.ObjectID) {
|
|
return convertToCoreValue(rv).DBPointer()
|
|
}
|
|
|
|
// DBPointerOK is the same as DBPoitner, except that it returns a boolean
|
|
// instead of panicking.
|
|
func (rv RawValue) DBPointerOK() (string, primitive.ObjectID, bool) {
|
|
return convertToCoreValue(rv).DBPointerOK()
|
|
}
|
|
|
|
// JavaScript returns the BSON JavaScript code value the Value represents. It panics if the value is
|
|
// a BSON type other than JavaScript code.
|
|
func (rv RawValue) JavaScript() string { return convertToCoreValue(rv).JavaScript() }
|
|
|
|
// JavaScriptOK is the same as Javascript, excepti that it returns a boolean
|
|
// instead of panicking.
|
|
func (rv RawValue) JavaScriptOK() (string, bool) { return convertToCoreValue(rv).JavaScriptOK() }
|
|
|
|
// Symbol returns the BSON symbol value the Value represents. It panics if the value is a BSON
|
|
// type other than symbol.
|
|
func (rv RawValue) Symbol() string { return convertToCoreValue(rv).Symbol() }
|
|
|
|
// SymbolOK is the same as Symbol, excepti that it returns a boolean
|
|
// instead of panicking.
|
|
func (rv RawValue) SymbolOK() (string, bool) { return convertToCoreValue(rv).SymbolOK() }
|
|
|
|
// CodeWithScope returns the BSON JavaScript code with scope the Value represents.
|
|
// It panics if the value is a BSON type other than JavaScript code with scope.
|
|
func (rv RawValue) CodeWithScope() (string, Raw) {
|
|
code, scope := convertToCoreValue(rv).CodeWithScope()
|
|
return code, Raw(scope)
|
|
}
|
|
|
|
// CodeWithScopeOK is the same as CodeWithScope, except that it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) CodeWithScopeOK() (string, Raw, bool) {
|
|
code, scope, ok := convertToCoreValue(rv).CodeWithScopeOK()
|
|
return code, Raw(scope), ok
|
|
}
|
|
|
|
// Int32 returns the int32 the Value represents. It panics if the value is a BSON type other than
|
|
// int32.
|
|
func (rv RawValue) Int32() int32 { return convertToCoreValue(rv).Int32() }
|
|
|
|
// Int32OK is the same as Int32, except that it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) Int32OK() (int32, bool) { return convertToCoreValue(rv).Int32OK() }
|
|
|
|
// AsInt32 returns a BSON number as an int32. If the BSON type is not a numeric one, this method
|
|
// will panic.
|
|
//
|
|
// Deprecated: Use AsInt64 instead. If an int32 is required, convert the returned value to an int32
|
|
// and perform any required overflow/underflow checking.
|
|
func (rv RawValue) AsInt32() int32 { return convertToCoreValue(rv).AsInt32() }
|
|
|
|
// AsInt32OK is the same as AsInt32, except that it returns a boolean instead of
|
|
// panicking.
|
|
//
|
|
// Deprecated: Use AsInt64OK instead. If an int32 is required, convert the returned value to an
|
|
// int32 and perform any required overflow/underflow checking.
|
|
func (rv RawValue) AsInt32OK() (int32, bool) { return convertToCoreValue(rv).AsInt32OK() }
|
|
|
|
// Timestamp returns the BSON timestamp value the Value represents. It panics if the value is a
|
|
// BSON type other than timestamp.
|
|
func (rv RawValue) Timestamp() (t, i uint32) { return convertToCoreValue(rv).Timestamp() }
|
|
|
|
// TimestampOK is the same as Timestamp, except that it returns a boolean
|
|
// instead of panicking.
|
|
func (rv RawValue) TimestampOK() (t, i uint32, ok bool) { return convertToCoreValue(rv).TimestampOK() }
|
|
|
|
// Int64 returns the int64 the Value represents. It panics if the value is a BSON type other than
|
|
// int64.
|
|
func (rv RawValue) Int64() int64 { return convertToCoreValue(rv).Int64() }
|
|
|
|
// Int64OK is the same as Int64, except that it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) Int64OK() (int64, bool) { return convertToCoreValue(rv).Int64OK() }
|
|
|
|
// AsInt64 returns a BSON number as an int64. If the BSON type is not a numeric one, this method
|
|
// will panic.
|
|
func (rv RawValue) AsInt64() int64 { return convertToCoreValue(rv).AsInt64() }
|
|
|
|
// AsInt64OK is the same as AsInt64, except that it returns a boolean instead of
|
|
// panicking.
|
|
func (rv RawValue) AsInt64OK() (int64, bool) { return convertToCoreValue(rv).AsInt64OK() }
|
|
|
|
// Decimal128 returns the decimal the Value represents. It panics if the value is a BSON type other than
|
|
// decimal.
|
|
func (rv RawValue) Decimal128() primitive.Decimal128 { return convertToCoreValue(rv).Decimal128() }
|
|
|
|
// Decimal128OK is the same as Decimal128, except that it returns a boolean
|
|
// instead of panicking.
|
|
func (rv RawValue) Decimal128OK() (primitive.Decimal128, bool) {
|
|
return convertToCoreValue(rv).Decimal128OK()
|
|
}
|