https://github.com/xmidt-org/praetor
Praetor provides a simple, opinionated way of integrating consul, especially service discovery, into a go.uber.org/fx application.
https://github.com/xmidt-org/praetor
Last synced: 11 days ago
JSON representation
Praetor provides a simple, opinionated way of integrating consul, especially service discovery, into a go.uber.org/fx application.
- Host: GitHub
- URL: https://github.com/xmidt-org/praetor
- Owner: xmidt-org
- License: apache-2.0
- Created: 2023-10-24T03:57:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-05T20:07:13.000Z (18 days ago)
- Last Synced: 2025-05-13T00:52:21.215Z (11 days ago)
- Language: Go
- Size: 212 KB
- Stars: 0
- Watchers: 12
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# praetor
praetor integrates go.uber.org/fx with consul.
[](https://github.com/xmidt-org/praetor/actions)
[](http://codecov.io/github/xmidt-org/praetor?branch=main)
[](https://goreportcard.com/report/github.com/xmidt-org/praetor)
[](https://github.com/xmidt-org/praetor/blob/main/LICENSE)
[](https://sonarcloud.io/dashboard?id=xmidt-org_PROJECT)
[](CHANGELOG.md)
[](https://pkg.go.dev/github.com/xmidt-org/praetor)## Summary
Praetor provides a basic, opinionated way of integrating consul into a go.uber.org/fx application.
## Table of Contents
- [Usage](#usage)
- [Code of Conduct](#code-of-conduct)
- [Install](#install)
- [Contributing](#contributing)## Usage
`praetor.Provide()` creates an `*api.Client` object as well as several of the commonly used services.
```go
import github.com/xmidt-org/praetorapp := fx.New(
praetor.Provide(),
fx.Invoke(
// praetor.Provide() makes the following possible:
func(client *api.Config) {
// ...
},
func(agent *api.Agent) {
// ...
},
func(agent *api.Catalog) {
// ...
},
func(agent *api.Health) {
// ...
},
func(agent *api.KV) {
// ...
},
),
)
```If an `api.Config` is provided within the application, it will be used to create the consul client.
```go
import github.com/xmidt-org/praetorapp := fx.New(
fx.Supply(
// this api.Config can come from external sources
api.Config{
Scheme: "https",
Address: "foobar.com",
}
),
praetor.Provide(),
)
```A custom configuration can be easily integrated using the standard `go.uber.org/fx` tools.
```go
import github.com/xmidt-org/praetortype MyConfiguration struct {
Scheme string
Address string// anything else desired ....
}app := fx.New(
fx.Supply(
MyConfiguration{
Scheme: "https",
Address: "foobar.com",
}
),
praetor.Provide(),
fx.Provide(
// this will be used by praetor
func(src MyConfiguration) api.Config {
return api.Config{
Scheme: src.Scheme,
Address: src.Address,
}
},
),
)
```## Code of Conduct
This project and everyone participating in it are governed by the [XMiDT Code Of Conduct](https://xmidt.io/docs/community/code_of_conduct/).
By participating, you agree to this Code.## Install
go get -u github.com/xmidt-org/praetor
## Contributing
Refer to [CONTRIBUTING.md](CONTRIBUTING.md).