From 5d265dce33ad31c64f815dfdaa70fd51a970d9ac Mon Sep 17 00:00:00 2001 From: Nova Kwok Date: Fri, 15 Sep 2023 14:13:30 +0800 Subject: [PATCH] Parse flat before load config (#275) * Parse flat before load config * Bump version to 0.9.11 --- config/config.go | 2 +- encoder/encoder.go | 2 +- webp-server.go | 31 ++++++++++++++----------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/config/config.go b/config/config.go index 9cf6003..84ae2bc 100644 --- a/config/config.go +++ b/config/config.go @@ -59,7 +59,7 @@ var ( ProxyMode bool Prefetch bool Config jsonFile - Version = "0.9.9" + Version = "0.9.11" WriteLock = cache.New(5*time.Minute, 10*time.Minute) RemoteRaw = "./remote-raw" Metadata = "./metadata" diff --git a/encoder/encoder.go b/encoder/encoder.go index 116b186..0d94b28 100644 --- a/encoder/encoder.go +++ b/encoder/encoder.go @@ -20,12 +20,12 @@ var ( ) func init() { + vips.LoggingSettings(nil, vips.LogLevelError) vips.Startup(&vips.Config{ ConcurrencyLevel: runtime.NumCPU(), }) boolFalse.Set(false) intMinusOne.Set(-1) - } func resizeImage(img *vips.ImageRef, extraParams config.ExtraParams) error { diff --git a/webp-server.go b/webp-server.go index 16a9293..266e3ec 100644 --- a/webp-server.go +++ b/webp-server.go @@ -47,23 +47,17 @@ func setupLogger() { } func init() { - // main init is the last one to be called - flag.Parse() - config.LoadConfig() - setupLogger() -} - -func main() { // Our banner banner := fmt.Sprintf(` -▌ ▌ ▌ ▛▀▖ ▞▀▖ ▞▀▖ -▌▖▌▞▀▖▛▀▖▙▄▘ ▚▄ ▞▀▖▙▀▖▌ ▌▞▀▖▙▀▖ ▌▄▖▞▀▖ -▙▚▌▛▀ ▌ ▌▌ ▖ ▌▛▀ ▌ ▐▐ ▛▀ ▌ ▌ ▌▌ ▌ -▘ ▘▝▀▘▀▀ ▘ ▝▀ ▝▀▘▘ ▘ ▝▀▘▘ ▝▀ ▝▀ - -WebP Server Go - v%s -Develop by WebP Server team. https://github.com/webp-sh`, config.Version) - + ▌ ▌ ▌ ▛▀▖ ▞▀▖ ▞▀▖ + ▌▖▌▞▀▖▛▀▖▙▄▘ ▚▄ ▞▀▖▙▀▖▌ ▌▞▀▖▙▀▖ ▌▄▖▞▀▖ + ▙▚▌▛▀ ▌ ▌▌ ▖ ▌▛▀ ▌ ▐▐ ▛▀ ▌ ▌ ▌▌ ▌ + ▘ ▘▝▀▘▀▀ ▘ ▝▀ ▝▀▘▘ ▘ ▝▀▘▘ ▝▀ ▝▀ + + WebP Server Go - v%s + Develop 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) @@ -77,11 +71,15 @@ Develop by WebP Server team. https://github.com/webp-sh`, config.Version) 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, })) @@ -89,7 +87,6 @@ Develop by WebP Server team. https://github.com/webp-sh`, config.Version) listenAddress := config.Config.Host + ":" + config.Config.Port app.Get("/*", handler.Convert) - fmt.Printf("\n %c[1;32m%s%c[0m\n\n", 0x1B, banner, 0x1B) fmt.Println("WebP Server Go is Running on http://" + listenAddress) _ = app.Listen(listenAddress)