gorun

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 4 Imported by: 0

README

gorun

Project Badges

gorun is a Go package that provides a simple interface to run, monitor, and stop external programs, capturing their output and handling graceful shutdowns.

Usage

Installation
go get github.com/cdvelop/gorun
Example
package main

import (
    "os"
    "github.com/cdvelop/gorun"
)

func main() {
    config := &gorun.GoRunConfig{
        ExecProgramPath: "your_program",
        RunArguments:    func() []string { return []string{"--flag"} },
        ExitChan:        make(chan bool),
        Logger:          os.Stdout,
    }

    runner := gorun.New(config)

    // Start the program
    if err := runner.RunProgram(); err != nil {
        panic(err)
    }

    // ... do other work ...

    // Stop the program gracefully
    if err := runner.StopProgram(); err != nil {
        panic(err)
    }
}
API
type GoRunConfig

Configuration for running an external program.

  • ExecProgramPath string: Path to the executable.
  • RunArguments func() []string: Function returning the arguments to pass.
  • ExitChan chan bool: Channel to signal exit.
  • Writer io.Writer: Where to write program output.
func New(config *GoRunConfig) *GoRun

Creates a new runner instance.

func (g *GoRun) RunProgram() error

Runs the configured program and captures its output.

func (g *GoRun) StopProgram() error

Stops the running program gracefully.


For more details, see the GoDoc or the source

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoRun

type GoRun struct {
	*GoRunConfig
	Cmd       *exec.Cmd
	IsRunning bool
}

func New

func New(c *GoRunConfig) *GoRun

func (*GoRun) RunProgram

func (h *GoRun) RunProgram() error

func (*GoRun) StopProgram

func (h *GoRun) StopProgram() error

type GoRunConfig

type GoRunConfig struct {
	ExecProgramPath string // eg: "server/main.exe"
	RunArguments    func() []string
	ExitChan        chan bool
	Logger          io.Writer
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL