代码拉取完成,页面将自动刷新
package main
import (
"context"
"net/http"
"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/handler"
"github.com/rs/zerolog/log"
)
// a is the `air.Default`.
var a = air.Default
func main() {
a.ErrorHandler = errorHandler
a.Pregases = []air.Gas{
logger.Gas(logger.GasConfig{
IncludeClientAddress: true,
}),
defibrillator.Gas(defibrillator.GasConfig{}),
redirector.WWW2NonWWWGas(redirector.WWW2NonWWWGasConfig{}),
limiter.BodySizeGas(limiter.BodySizeGasConfig{
MaxBytes: 1 << 20,
}),
}
shutdownChan := make(chan os.Signal, 1)
signal.Notify(shutdownChan, os.Interrupt, syscall.SIGTERM)
go func() {
if err := a.Serve(); err != nil {
log.Error().Err(err).
Str("app_name", a.AppName).
Msg("server error")
}
}()
<-shutdownChan
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
a.Shutdown(ctx)
}
// errorHandler is the error handler.
func errorHandler(err error, req *air.Request, res *air.Response) {
if res.Written {
return
}
m := ""
if !req.Air.DebugMode && res.Status == http.StatusInternalServerError {
m = http.StatusText(res.Status)
} else {
m = err.Error()
}
res.WriteJSON(map[string]interface{}{
"Error": m,
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。