Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/zhengchengdong/arp4g-mongodb

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/zhengchengdong/arp4g-mongodb

  • v0.0.0-20221114095401-4ca6748c8810
  • Source
  • Go
  • Socket score

Version published
Created
Source

ARP4G-mongodb

这是ARP4G的MongoDB实现。

功能

  1. 实现基于MongoDB的持久化
  2. 实现基于MongoDB的互斥锁

如何使用

//定义仓库
type OrderRepository interface {
	Take(ctx context.Context, id any) (order *Order, found bool)
}

//定义Service
type OrderService struct {
	orderRepository OrderRepository
}

//获得mongodb客户端
mongoClient, err := mongo.Connect(context.Background(), options.Client().ApplyURI(
	"mongodb://localhost:27017/orders"))
if err != nil {
	panic(err)
}

//生成仓库的mongodb实现
mongoOrderRepo := mongorepo.NewMongodbRepository(mongoClient, "orders", "Order", func() *Order { return &Order{} })

//使用仓库生成Service
orderService := &OrderService{mongoOrderRepo}

这里使用NewMongodbRepository打包生成了MongoDB的仓库实现,仓库会使用MongoDB持久化,也会用MongoDB实现互斥锁。

func NewMongodbRepositoryWithMutexesimpl[T any](client *mongo.Client, database string, collection string, newEmptyEntity arp.NewZeroEntity[T], mutexesimpl arp.Mutexes) arp.QueryRepository[T]

也可以使用NewMongodbRepositoryWithMutexesimpl函数选择不同的互斥锁实现,比如,持久化到MongoDB,但是用Redis实现互斥锁

FAQs

Package last updated on 14 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc