itfans avatar

以後台方式運行golang程式

🕦 by itfans





安裝:

VimL:
1
go get github.com/icattlecoder/godaemon

範例:

Stylus:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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))
}

運行

Crystal:
1
2
3
./example -d=true
~$ curl http://127.0.0.1:7070/index
hello, golang!





💘 相关文章

写一条评论

Based on Golang + fastHTTP + sdb | go1.16.13 Processed in 0ms