以后台形式运行golang程序

安装:

go get github.com/icattlecoder/godaemon

示例:

package main

import (
    _ "github.com/icattlecoder/godaemon"
    "log"
    "net/http"
)

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/index", func(rw http.ResponseWriter, req *http.Request) {
        rw.Write([]byte("hello, golang!\n"))
    })
    log.Fatalln(http.ListenAndServe(":7070", mux))
}

运行

./example -d=true
~$ curl http://127.0.0.1:7070/index
hello, golang!
    原文作者:IOS
    原文地址: https://segmentfault.com/a/1190000000589972
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞