service

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 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"
	"github.com/sanrentai/service/log"
)

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) {
	log.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 Run

func Run(prg *Program)

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()
	// 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