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

github.com/go-micro/plugins/v4/wrapper/select/shard

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/go-micro/plugins/v4/wrapper/select/shard

  • v1.2.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Shard Wrapper

The shard wrapper is a way of sharding calls based on metadata key-value so requests can be pinned to a particular backend node.

For example if you want to use session affinity aka sticky sessions you can specify the header value for sessions e.g. X-From-Session or X-From-User

X-From-Session or X-From-User is likely a unique session token or user id. The shard wrapper will look for the key you specify and use the crc32 checksum of the value against the nodes much like the gomemcache library. It uses a selector strategy to achieve this.

Usage

Pass in the wrapper when you create your service with the key you want to shard on

wrapper := shard.NewClientWrapper("X-From-Session")

service := micro.NewService(
	micro.Name("foo"),
	micro.WrapClient(wrapper),
)

Alternatively wrap the client and use independently

wrapper := shard.NewClientWrapper("X-From-Session")

client := wrapper(service.Client())

FAQs

Package last updated on 01 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