Skip to content

Praetor provides a simple, opinionated way of integrating consul, especially service discovery, into a go.uber.org/fx application.

License

Notifications You must be signed in to change notification settings

xmidt-org/praetor

Repository files navigation

praetor

praetor integrates go.uber.org/fx with consul.

Build Status codecov.io Go Report Card Apache V2 License Quality Gate Status GitHub release PkgGoDev

Summary

Praetor provides a basic, opinionated way of integrating consul into a go.uber.org/fx application.

Table of Contents

Usage

praetor.Provide() creates an *api.Client object as well as several of the commonly used services.

import github.com/xmidt-org/praetor

app := 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.

import github.com/xmidt-org/praetor

app := 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.

import github.com/xmidt-org/praetor

type 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. By participating, you agree to this Code.

Install

go get -u github.com/xmidt-org/praetor

Contributing

Refer to CONTRIBUTING.md.

About

Praetor provides a simple, opinionated way of integrating consul, especially service discovery, into a go.uber.org/fx application.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages