Skip to content

How to run a cleanup function on control-c? #266

@comicsads

Description

@comicsads

I would like to run a target/function when another target gets closed using ctrl-c. The reason for this is I'm creating a webserver using go, and have a mage target to build an executable and run it, and the only way to close it is by using ctrl-c. I would like to be able to run the target Cleanup() after hitting ctrl-c.
Is there anyway to do this? Is this what context.Context() is for?
Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions