11 Star 42 Fork 14

Gitee 极速下载/webp-server-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/webp-sh/webp_server_go
克隆/下载
webp-server.go 3.13 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"flag"
"fmt"
"os"
"runtime"
"webp_server_go/config"
"webp_server_go/encoder"
"webp_server_go/handler"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/etag"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
log "github.com/sirupsen/logrus"
)
// https://docs.gofiber.io/api/fiber
var app = fiber.New(fiber.Config{
ServerHeader: "WebP Server Go",
AppName: "WebP Server Go",
DisableStartupMessage: true,
ProxyHeader: "X-Real-IP",
ReadBufferSize: config.Config.ReadBufferSize, // per-connection buffer size for requests' reading. This also limits the maximum header size. Increase this buffer if your clients send multi-KB RequestURIs and/or multi-KB headers (for example, BIG cookies).
Concurrency: config.Config.Concurrency, // Maximum number of concurrent connections.
DisableKeepalive: config.Config.DisableKeepalive, // Disable keep-alive connections, the server will close incoming connections after sending the first response to the client
})
func setupLogger() {
log.SetOutput(os.Stdout)
log.SetReportCaller(true)
formatter := &log.TextFormatter{
EnvironmentOverrideColors: true,
FullTimestamp: true,
TimestampFormat: config.TimeDateFormat,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
return fmt.Sprintf("[%d:%s]", f.Line, f.Function), ""
},
}
log.SetFormatter(formatter)
log.SetLevel(log.InfoLevel)
// fiber logger format
app.Use(logger.New(logger.Config{
Format: config.FiberLogFormat,
TimeFormat: config.TimeDateFormat,
}))
app.Use(recover.New(recover.Config{}))
fmt.Println("Allowed file types as source:", config.Config.AllowedTypes)
fmt.Println("Convert to WebP Enabled:", config.Config.EnableWebP)
fmt.Println("Convert to AVIF Enabled:", config.Config.EnableAVIF)
fmt.Println("Convert to JXL Enabled:", config.Config.EnableJXL)
}
func init() {
// Our banner
banner := fmt.Sprintf(`
▌ ▌ ▌ ▛▀▖ ▞▀▖ ▞▀▖
▌▖▌▞▀▖▛▀▖▙▄▘ ▚▄ ▞▀▖▙▀▖▌ ▌▞▀▖▙▀▖ ▌▄▖▞▀▖
▙▚▌▛▀ ▌ ▌▌ ▖ ▌▛▀ ▌ ▐▐ ▛▀ ▌ ▌ ▌▌ ▌
▘ ▘▝▀▘▀▀ ▘ ▝▀ ▝▀▘▘ ▘ ▝▀▘▘ ▝▀ ▝▀
WebP Server Go - v%s
Developed by WebP Server team. https://github.com/webp-sh`, config.Version)
// main init is the last one to be called
flag.Parse()
// process cli params
if config.DumpConfig {
fmt.Println(config.SampleConfig)
os.Exit(0)
}
if config.ShowVersion {
fmt.Printf("\n %c[1;32m%s%c[0m\n\n", 0x1B, banner+"", 0x1B)
os.Exit(0)
}
config.LoadConfig()
fmt.Printf("\n %c[1;32m%s%c[0m\n\n", 0x1B, banner, 0x1B)
setupLogger()
}
func main() {
if config.Prefetch {
go encoder.PrefetchImages()
}
app.Use(etag.New(etag.Config{
Weak: true,
}))
listenAddress := config.Config.Host + ":" + config.Config.Port
app.Get("/healthz", handler.Healthz)
app.Get("/*", handler.Convert)
fmt.Println("WebP Server Go is Running on http://" + listenAddress)
_ = app.Listen(listenAddress)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/webp-server-go.git
git@gitee.com:mirrors/webp-server-go.git
mirrors
webp-server-go
webp-server-go
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385