Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

0.9.1: Service Integration

Pre-release
Pre-release
Compare
Choose a tag to compare
released this 23 Nov 06:52
· 35 commits to main since this release

This release changes the API of the HTTP server to integrate with the Service library. The public interface now requires using the Lifecycle object to start and stop the server. The Lifecycle also allows adding hooks for lifecycle events.

server, err := http.NewServer(
    "service name",
    http.ServerConfiguration{
        //...
    },
    handler,
    logger,
)
if err != nil {
    // Handle configuration error
}
// Lifecycle from the github.com/containerssh/service package
lifecycle := service.NewLifecycle(server)
//Add an event hook
lifecycle.OnRunning(...)
go func() {
    if err := lifecycle.Run(); err != nil {
        // Handle error
    }
}()
// Do something else, then shut down the server.
// You can pass a context for the shutdown deadline.
lifecycle.Shutdown(context.Background())