Nacelle

Go service framework
/

Postgres utilities

The github.com/go-nacelle/pgutil package provides Postgres utilities.


This library creates a sqlx connection wrapped in a nacelle logger. The supplied initializer adds this connection into the nacelle service container under the key db. The initializer will block until a ping succeeds.

1
2
3
4
5
6
func setup(processes nacelle.ProcessContainer, services nacelle.ServiceContainer) error {
    processes.RegisterInitializer(pgutil.NewInitializer())

    // additional setup
    return nil
}

This library uses golang migrate to optionally run migrations on application startup. To configure migrations, supply a source driver to the initializer, as follows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import (
    _ "github.com/golang-migrate/migrate/v4/source/file"
    "github.com/golang-migrate/migrate/v4/source"
)

func setup(processes nacelle.ProcessContainer, services nacelle.ServiceContainer) error {
    migrationSourceDriver, err := source.Open("file:///migrations")
	if err != nil {
		return err
	}

    processes.RegisterInitializer(pgutil.NewInitializer(
        pgutil.WithMigrationSourceDriver(migrationSourceDriver)
    ))

    // ...
}