forked from goproxy/goproxy.cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (53 loc) · 1.35 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
62
63
package main
import (
"context"
"crypto/tls"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/air-gases/defibrillator"
"github.com/air-gases/limiter"
"github.com/air-gases/logger"
"github.com/air-gases/redirector"
"github.com/aofei/air"
"github.com/goproxy/goproxy.cn/base"
"github.com/goproxy/goproxy.cn/handler"
)
func main() {
if !base.Air.DebugMode {
base.Air.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
}
base.Air.NotFoundHandler = handler.NotFoundHandler
base.Air.MethodNotAllowedHandler = handler.MethodNotAllowedHandler
base.Air.ErrorHandler = handler.Error
base.Air.ErrorLogger = log.New(base.Logger, "", 0)
base.Air.Pregases = []air.Gas{
logger.Gas(logger.GasConfig{
Logger: &base.Logger,
IncludeClientAddress: true,
}),
defibrillator.Gas(defibrillator.GasConfig{}),
redirector.WWW2NonWWWGas(redirector.WWW2NonWWWGasConfig{
HTTPSEnforced: true,
}),
limiter.BodySizeGas(limiter.BodySizeGasConfig{
MaxBytes: 1 << 20,
}),
}
shutdownChan := make(chan os.Signal, 1)
signal.Notify(shutdownChan, os.Interrupt, syscall.SIGTERM)
go func() {
if err := base.Air.Serve(); err != nil {
base.Logger.Error().Err(err).
Msg("air server error")
}
}()
<-shutdownChan
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
base.Air.Shutdown(ctx)
}