-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (48 loc) · 1.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"log"
"net"
"net/http"
"net/http/fcgi"
"runtime"
)
func main() {
log.Println("listening for nginx connections at localhost:8081")
log.Println("press ctrl + c to close...")
runtime.GOMAXPROCS(runtime.NumCPU())
addr, err := net.ResolveUnixAddr("unix", "/tmp/gofcgi.socket")
if err != nil {
return
}
listener, err := net.ListenUnix("unix", addr)
if err != nil {
return
}
defer listener.Close()
http.HandleFunc("/", index)
err = fcgi.Serve(listener, nil)
if err != nil {
log.Println("fcgi.Serve:", err.Error())
}
}
func index(w http.ResponseWriter, req *http.Request) {
w.Header().Add("Content-Type", "text/html")
fmt.Fprintf(w, header)
fmt.Fprintf(w, "Hello world, "+req.URL.Path)
fmt.Fprintf(w, footer)
}
var header = `
<!DOCTYPE html>
<html>
<head>
<title> GO + FCGI </title>
<style> .centered {margin-left:auto;margin-right:auto;width:90%;} </style>
</head>
<body>
<h3 class="centered"> GO + FCGI </h3>
<div class="centered">`
var footer = `
</div>
</body>
</html>`