winservice

package module
v0.0.0-...-1075c0c Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2022 License: MIT Imports: 6 Imported by: 0

README

winservice

Go implements simple and easy-to-use windows services

How to use

go get "github.com/iGwkang/winservice"

import "github.com/iGwkang/winservice"

var (
	command = flag.String("o", "", "[install/uninstall/start/stop/status]")
)

func main() {
	flag.Parse()

	ws := &winservice.WinService{
		SvcName: "Your Service Name",
		ExecuteFunc: func() {
			// service run function
		},
	}

	if ws.IsWindowsService() {
		ws.Run()
	} else {
		switch *command {
		case "install":
			fmt.Println(ws.InstallService("-o", "test"))
		case "uninstall":
			fmt.Println(ws.UninstallService())
		case "start":
			fmt.Println(ws.StartService())
		case "stop":
			fmt.Println(ws.StopService())
		case "status":
			fmt.Println(ws.Status())
		default:
			ws.ExecuteFunc()
		}
	}
}

Documentation

Rendered for windows/amd64

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WinService

type WinService struct {
	SvcName     string
	ExecuteFunc func()
	// contains filtered or unexported fields
}

func (*WinService) Execute

func (ws *WinService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (svcSpecificEC bool, exitCode uint32)

func (*WinService) InstallService

func (ws *WinService) InstallService(args ...string) error

func (*WinService) IsWindowsService

func (ws *WinService) IsWindowsService() bool

func (*WinService) Run

func (ws *WinService) Run() error

func (*WinService) StartService

func (ws *WinService) StartService() error

func (*WinService) Status

func (ws *WinService) Status() (svc.State, error)

func (*WinService) StopService

func (ws *WinService) StopService() error

func (*WinService) UninstallService

func (ws *WinService) UninstallService() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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