svc包

weixin_37816121發表於2020-10-21

go get github.com/judwhite/go-svc/svc

package main

import (
	"github.com/judwhite/go-svc/svc"
	"log"
	"os"
	"syscall"
	"time"
)

type pro struct {

}

func main()  {

	pro :=&pro{}

	svc.Run(pro,syscall.SIGINT)


}

func (p *pro)Init( e svc.Environment) error{
	port := os.Getpid()
	log.Printf("程式已經初始化 埠為%d  \n",port)
	return nil

}

func (p *pro)Start() error{
	log.Printf("程式已經start\n")
	go func() {
		tik := time.NewTicker(3*time.Second)
		for  {
			c := <-tik.C
			log.Printf("當前時間為:%s \n",c.Format("2006-01-02 15:04:05"))
		}

	}()
	return nil
}

func (p *pro)Stop() error{
	log.Printf("程式已經stop\n")
	return nil
}

輸出
在這裡插入圖片描述

相關文章