Skip to content

jhulten/go-ctxcli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ctxcli: Extend golang context to CLI GoDoc Build Status

ctxcli is a Go library extending the standard context with handling for OS signals.

Features

  • Create a child context that cancels when an OS signal like SIGINT is received.
  • Helper functions to exit or panic when the provided context is cancelled.
  • Consistent API with the context standard library.

Example

package main

import (
    "context"
    "log"
    "time"
    "github.com/jhulten/go-ctxcli"
)

func main() {
    ctx := context.Background()
    ctx = ctxcli.WithInterrupt(ctx)

    for {
        log.Print(".")
        time.Sleep(500 * time.Millisecond)
        ctxcli.ExitIfCancelled(ctx)
    }
}

About

A Go library extending the standard context with handling for OS signals

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages