Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trpc-ecosystem/go-selector-dsn
https://github.com/trpc-ecosystem/go-selector-dsn
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/trpc-ecosystem/go-selector-dsn
- Owner: trpc-ecosystem
- License: other
- Created: 2023-08-11T07:08:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-16T11:38:46.000Z (8 months ago)
- Last Synced: 2024-10-21T15:26:16.780Z (3 months ago)
- Language: Go
- Size: 43 KB
- Stars: 0
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
English | [中文](README.zh_CN.md)
# Data Source Name Selector
[![Go Reference](https://pkg.go.dev/badge/github.com/trpc-ecosystem/go-selector-dsn.svg)](https://pkg.go.dev/github.com/trpc-ecosystem/go-selector-dsn)
[![Go Report Card](https://goreportcard.com/badge/trpc.group/trpc-go/trpc-selector-dsn)](https://goreportcard.com/report/trpc.group/trpc-go/trpc-selector-dsn)
[![LICENSE](https://img.shields.io/badge/license-Apache--2.0-green.svg)](https://github.com/trpc-ecosystem/go-selector-dsn/blob/main/LICENSE)
[![Releases](https://img.shields.io/github/release/trpc-ecosystem/go-selector-dsn.svg?style=flat-square)](https://github.com/trpc-ecosystem/go-selector-dsn/releases)
[![Tests](https://github.com/trpc-ecosystem/go-selector-dsn/actions/workflows/prc.yml/badge.svg)](https://github.com/trpc-ecosystem/go-selector-dsn/actions/workflows/prc.yml)
[![Coverage](https://codecov.io/gh/trpc-ecosystem/go-selector-dsn/branch/main/graph/badge.svg)](https://app.codecov.io/gh/trpc-ecosystem/go-selector-dsn/tree/main)DSN(Data Source Name) Selector implements a selector for tRPC-Go, which uses the client's target as a data source name , and returns it in the Node's Address
## client
```
client: # backend-config for client
service: # backend's config
- name: trpc.dsn.xxx.xxx
target: dsn://user:passwd@tcp(ip:port)/db # select returns the address after "://"
- name: trpc.dsn.xxx.xxx1
# dsn+polaris means that the host in target will be resolved by polaris, and the actual address will be replaced
# after the host, and the part after "://" will be returned
# polaris is specified when registering the selector, and can also be other selectors
target: dsn+polaris://user:passwd@tcp(host)/db
``````
// register selector
func init() {
// use target as data source name or uri directly
selector.Register("dsn", dsn.DefaultSelector)// selector which supports address resolution, polaris is the name of the address resolution selector
// dsn.URIHostExtractor{} is the extractor to extract the key of polaris service from target
selector.Register("dsn+polaris", dsn.NewResolvableSelector("polaris", &dsn.URIHostExtractor{}))
}```