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

0.9.3: Upgraded this library to match the new service library

Pre-release
Pre-release
Compare
Choose a tag to compare
released this 22 Nov 22:44
· 65 commits to main since this release

Previously, the SSH server could be started and stopped directly using the Run() and Shutdown() methods. This change integrates the SSH server with the new service library that makes it easier to manage multiple services in a single daemon. As a side effect, the SSH server can now only be started using the Lifecycle object:

// Create the server. See the description below for parameters.
server, err := sshserver.New(
    cfg,
    handler,
    logger,
)
if err != nil {
    // Handle configuration errors
    log.Fatalf("%v", err)
}
lifecycle := service.NewLifecycle(server)

defer func() {
    // The Run method will run the server and return when the server is shut down.
    // We are running this in a goroutine so the shutdown below can proceed after a minute.
    if err := lifecycle.Run(); err != nil {
        // Handle errors while running the server
    }
}()

time.Sleep(60 * time.Second)

// Shut down the server. Pass a context to indicate how long the server should wait
// for existing connections to finish. This function will return when the server
// has stopped. 
lifecycle.Stop(
    context.WithTimeout(
        context.Background(),
        30 * time.Second,
    ),
)

This gives you the option to register hooks for the various lifecycle events. For more details see the service library.