-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (51 loc) · 1.44 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
56
57
58
59
60
61
package main
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
protectedHeadersInbound = map[string]bool{
"content-type": true,
"content-length": true,
}
protectedHeadersOutbound = map[string]bool{
"x-powered-by": true,
"x-app-route": true,
}
)
func main() {
logger := log.New()
logger.SetFormatter(&log.JSONFormatter{})
logger.SetLevel(log.DebugLevel)
rootCmd := &cobra.Command{
Use: "gophpfpm",
Short: "Super fast HTTP proxy server for PHP FPM",
Long: `Web server for PHP written in Go. It's compatible with PHP-FPM communicating via FastCGI protocol using unix socket.`,
Run: func(cmd *cobra.Command, args []string) {
config, err := LoadConfig(cmd.PersistentFlags(), logger)
if err != nil {
logger.Fatalf("could not load config: %s", err)
}
logger.SetLevel(log.InfoLevel)
if config.Verbose {
logger.SetLevel(log.DebugLevel)
}
fCgiClient, err := NewFCgiClient(config, logger)
if err != nil {
logger.Fatalf("could not create FPM client: %s", err)
}
accessLogger := NewAccessLogger(config, logger)
monitor := NewMonitor(logger)
fpmClient := NewFpmClient(fCgiClient, config, monitor, logger)
svr := NewHttpServer(config, fpmClient, accessLogger, monitor, logger)
svr.PrepareServer()
config.LogConfig()
svr.StartServer()
},
}
DefineParams(rootCmd)
if err := rootCmd.Execute(); err != nil {
logger.Fatalf("could not run root command")
}
return
}