service

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: MIT Imports: 4 Imported by: 0

README

service

将golang编译后的程序,注册成windows系统服务

简单用法,可以同时在当前目录和系统日志里记录日志内容,支持INFO,ERROR,WARN.

package main

import (
	"fmt"
	"net/http"

	"github.com/sanrentai/service"
)

func main() {
	prg := &service.Program{
		Name:        "test",
		DisplayName: "TEST",
		Description: "this is a test",
		Runfunc:     Run,
	}
	service.Run(prg)
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
	service.Info("hello world")
	fmt.Fprintf(w, "hello world")
}

func Run() {
	http.HandleFunc("/", indexHandler)
	http.ListenAndServe(":8000", nil)
}

在以管理员身份运行 cmd
go build
example.exe -s install
example.exe -s uninstall

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error added in v0.0.2

func Error(v ...interface{}) error

func Errorf added in v0.0.2

func Errorf(format string, a ...interface{}) error

func Info added in v0.0.2

func Info(v ...interface{}) error

func Infof added in v0.0.2

func Infof(format string, a ...interface{}) error

func Run

func Run(prg *Program)

func Warning added in v0.0.2

func Warning(v ...interface{}) error

func Warningf added in v0.0.2

func Warningf(format string, a ...interface{}) error

Types

type Program

type Program struct {
	Name        string // Required name of the service. No spaces suggested.
	DisplayName string // Display name, spaces allowed.
	Description string // Long description of service.

	Runfunc  func() error
	Stopfunc func() error
	// contains filtered or unexported fields
}

func (*Program) Start

func (p *Program) Start(s service.Service) error

func (*Program) Stop

func (p *Program) Stop(s service.Service) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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