Help us shape the future of Go! Take the 2026 Go Developer Survey

rest

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionCreate     = 1
	ActionBulkCreate = 2
	ActionUpdate     = 3
	ActionUpdateById = 4
	ActionReplace    = 5
	ActionDelete     = 6
	ActionBulkDelete = 7
	ActionSort       = 8
)

Variables

View Source
var ErrCollectionForbidden = errors.NewPublic("the collection is forbidden")
View Source
var ErrTxnNotExist = errors.NewPublic("the txn does not exist")
View Source
var ErrTxnTimeOut = errors.NewPublic("the transaction has timed out")

Functions

This section is empty.

Types

type BulkCreateDto

type BulkCreateDto struct {
	Collection string `path:"collection" vd:"snake"`
	Data       []M    `json:"data" vd:"gt=0"`
	Xdata      M      `json:"xdata,omitempty"`
	Txn        string `json:"txn,omitempty" vd:"omitempty,uuid"`
}

type BulkDeleteDto

type BulkDeleteDto struct {
	Collection string `path:"collection" vd:"snake"`
	Filter     M      `json:"filter" vd:"gt=0"`
	Xfilter    M      `json:"xfilter,omitempty"`
	Txn        string `json:"txn,omitempty" vd:"omitempty,uuid"`
}

type CommitDto

type CommitDto struct {
	Txn string `json:"txn" vd:"uuid"`
}

type Controller

type Controller struct {
	*Service
}

func (*Controller) BulkCreate

func (x *Controller) BulkCreate(ctx context.Context, c *app.RequestContext)

func (*Controller) BulkDelete

func (x *Controller) BulkDelete(ctx context.Context, c *app.RequestContext)

func (*Controller) Commit

func (x *Controller) Commit(ctx context.Context, c *app.RequestContext)

func (*Controller) Create

func (x *Controller) Create(ctx context.Context, c *app.RequestContext)

func (*Controller) Delete

func (x *Controller) Delete(ctx context.Context, c *app.RequestContext)

func (*Controller) Find

func (x *Controller) Find(ctx context.Context, c *app.RequestContext)

func (*Controller) FindById

func (x *Controller) FindById(ctx context.Context, c *app.RequestContext)

func (*Controller) FindOne

func (x *Controller) FindOne(ctx context.Context, c *app.RequestContext)

func (*Controller) Replace

func (x *Controller) Replace(ctx context.Context, c *app.RequestContext)

func (*Controller) Size

func (x *Controller) Size(ctx context.Context, c *app.RequestContext)

func (*Controller) Sort

func (x *Controller) Sort(ctx context.Context, c *app.RequestContext)

func (*Controller) Transaction

func (x *Controller) Transaction(ctx context.Context, c *app.RequestContext)

func (*Controller) Update

func (x *Controller) Update(ctx context.Context, c *app.RequestContext)

func (*Controller) UpdateById

func (x *Controller) UpdateById(ctx context.Context, c *app.RequestContext)

type CreateDto

type CreateDto struct {
	Collection string `path:"collection" vd:"snake"`
	Data       M      `json:"data" vd:"gt=0"`
	Xdata      M      `json:"xdata,omitempty"`
	Txn        string `json:"txn,omitempty" vd:"omitempty,uuid"`
}

type DeleteDto

type DeleteDto struct {
	Collection string `path:"collection" vd:"snake"`
	Id         string `path:"id" vd:"mongodb"`
	Txn        string `query:"txn,omitempty" vd:"omitempty,uuid"`
}

type FindByIdDto

type FindByIdDto struct {
	Collection string   `path:"collection" vd:"snake"`
	Id         string   `path:"id" vd:"mongodb"`
	Keys       []string `query:"keys,omitempty"`
}

type FindDto

type FindDto struct {
	Collection string   `path:"collection" vd:"snake"`
	Pagesize   int64    `header:"x-pagesize" vd:"omitempty,min=0,max=1000"`
	Page       int64    `header:"x-page" vd:"omitempty,min=0"`
	Filter     M        `json:"filter" vd:"required"`
	Xfilter    M        `json:"xfilter,omitempty"`
	Sort       []string `query:"sort,omitempty" vd:"omitempty,dive,sort"`
	Keys       []string `query:"keys,omitempty"`
}

type FindOneDto

type FindOneDto struct {
	Collection string   `path:"collection" vd:"snake"`
	Filter     M        `json:"filter" vd:"gt=0"`
	Xfilter    M        `json:"xfilter,omitempty"`
	Keys       []string `query:"keys,omitempty"`
}

type M

type M = map[string]interface{}

type Option

type Option func(x *Service)

func SetCipher added in v0.4.7

func SetCipher(v *cipher.Cipher) Option

func SetDatabase

func SetDatabase(v *mongo.Database) Option

func SetDynamicValues

func SetDynamicValues(v *values.DynamicValues) Option

func SetJetStream

func SetJetStream(v nats.JetStreamContext) Option

func SetKeyValue

func SetKeyValue(v nats.KeyValue) Option

func SetMongoClient

func SetMongoClient(v *mongo.Client) Option

func SetRedis

func SetRedis(v *redis.Client) Option

type PendingDto

type PendingDto struct {
	Action int                `bson:"action"`
	Name   string             `bson:"name"`
	Id     primitive.ObjectID `bson:"id,omitempty"`
	Filter M                  `bson:"filter,omitempty"`
	Data   interface{}        `bson:"data,omitempty"`
}

type PublishDto

type PublishDto struct {
	Action int         `json:"action"`
	Id     string      `json:"id,omitempty"`
	Filter M           `json:"filter,omitempty"`
	Data   interface{} `json:"data,omitempty"`
	Result interface{} `json:"result"`
}

type ReplaceDto

type ReplaceDto struct {
	Collection string `path:"collection" vd:"snake"`
	Id         string `path:"id" vd:"mongodb"`
	Data       M      `json:"data" vd:"gt=0"`
	Xdata      M      `json:"xdata,omitempty"`
	Txn        string `json:"txn,omitempty" vd:"omitempty,uuid"`
}

type Service

type Service struct {
	Mgo       *mongo.Client
	Db        *mongo.Database
	RDb       *redis.Client
	JetStream nats.JetStreamContext
	KeyValue  nats.KeyValue
	Values    *values.DynamicValues
	Cipher    *cipher.Cipher
}

func New

func New(options ...Option) *Service

func (*Service) BulkCreate

func (x *Service) BulkCreate(ctx context.Context, name string, docs []interface{}) (result interface{}, err error)

func (*Service) BulkDelete

func (x *Service) BulkDelete(ctx context.Context, name string, filter M, transaction bool) (result interface{}, err error)

func (*Service) Commit

func (x *Service) Commit(ctx context.Context, txn string) (_ interface{}, err error)

func (*Service) Create

func (x *Service) Create(ctx context.Context, name string, doc interface{}) (result interface{}, err error)

func (*Service) Delete

func (x *Service) Delete(ctx context.Context, name string, id primitive.ObjectID, transaction bool) (result interface{}, err error)

func (*Service) Find

func (x *Service) Find(ctx context.Context, name string, filter M, option *options.FindOptions) (data []M, err error)

func (*Service) FindOne

func (x *Service) FindOne(ctx context.Context, name string, filter M, option *options.FindOneOptions) (data M, err error)

func (*Service) Invoke

func (x *Service) Invoke(ctx context.Context, dto PendingDto) (_ interface{}, _ error)

func (*Service) IsForbid added in v0.4.3

func (x *Service) IsForbid(name string) bool

func (*Service) Pending

func (x *Service) Pending(ctx context.Context, txn string, dto PendingDto) (err error)

func (*Service) Pipe

func (x *Service) Pipe(input M, paths []string, kind interface{}) (err error)

func (*Service) Projection

func (x *Service) Projection(name string, keys []string) (result bson.M)

func (*Service) Publish

func (x *Service) Publish(ctx context.Context, name string, dto PublishDto) (err error)

func (*Service) Replace

func (x *Service) Replace(ctx context.Context, name string, id primitive.ObjectID, doc interface{}) (result interface{}, err error)

func (*Service) Sensitive added in v0.5.0

func (x *Service) Sensitive(name string, v M)

func (*Service) Size

func (x *Service) Size(ctx context.Context, name string, filter M) (_ int64, err error)

func (*Service) Sort

func (x *Service) Sort(ctx context.Context, name string, key string, ids []primitive.ObjectID) (result interface{}, err error)

func (*Service) Transaction

func (x *Service) Transaction(ctx context.Context, txn string)

func (*Service) Transform

func (x *Service) Transform(data M, rules M) (err error)

func (*Service) TxnNotExists added in v0.4.2

func (x *Service) TxnNotExists(ctx context.Context, key string) (err error)

func (*Service) Update

func (x *Service) Update(ctx context.Context, name string, filter M, update interface{}, option *options.UpdateOptions) (result interface{}, err error)

func (*Service) UpdateById

func (x *Service) UpdateById(ctx context.Context, name string, id primitive.ObjectID, update interface{}, option *options.UpdateOptions) (result interface{}, err error)

type SizeDto

type SizeDto struct {
	Collection string `path:"collection" vd:"snake"`
	Filter     M      `json:"filter" vd:"required"`
	Xfilter    M      `json:"xfilter,omitempty"`
}

type SortDto

type SortDto struct {
	Collection string      `path:"collection" vd:"snake"`
	Data       SortDtoData `json:"data" vd:"structonly"`
	Txn        string      `json:"txn,omitempty" vd:"omitempty,uuid"`
}

type SortDtoData

type SortDtoData struct {
	Key    string               `json:"key"  vd:"required"`
	Values []primitive.ObjectID `json:"values"  vd:"gt=0,dive,mongodb"`
}

type UpdateByIdDto

type UpdateByIdDto struct {
	Collection   string        `path:"collection" vd:"snake"`
	Id           string        `path:"id" vd:"mongodb"`
	Data         M             `json:"data" vd:"gt=0"`
	Xdata        M             `json:"xdata,omitempty"`
	ArrayFilters []interface{} `json:"arrayFilters,omitempty"`
	Txn          string        `json:"txn,omitempty" vd:"omitempty,uuid"`
}

type UpdateDto

type UpdateDto struct {
	Collection   string        `path:"collection" vd:"snake"`
	Filter       M             `json:"filter" vd:"gt=0"`
	Xfilter      M             `json:"xfilter,omitempty"`
	Data         M             `json:"data" vd:"gt=0"`
	Xdata        M             `json:"xdata,omitempty"`
	ArrayFilters []interface{} `json:"arrayFilters,omitempty"`
	Txn          string        `json:"txn,omitempty" vd:"omitempty,uuid"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL