mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 05:32:02 +08:00
fix runtime.GOOS=="windows, add more test cases, bump to newer version of fiber and libwebp (#68)
* fix runtime.GOOS=="windows, add some test cases test cases are still limited for flag * update to latest fiber v2.4.0 & libwebp v1.2.0 manually test confirmed
This commit is contained in:
parent
f5e7ee5273
commit
9329ac65fe
@ -21,7 +21,7 @@ var (
|
||||
prefetch, proxyMode bool
|
||||
remoteRaw = "remote-raw"
|
||||
config Config
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
8
go.mod
8
go.mod
@ -4,13 +4,13 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/chai2010/webp v1.1.0
|
||||
github.com/gofiber/fiber/v2 v2.1.4
|
||||
github.com/gofiber/fiber/v2 v2.4.0
|
||||
github.com/sirupsen/logrus v1.6.0
|
||||
github.com/stretchr/testify v1.3.0
|
||||
golang.org/x/image v0.0.0-20200119044424-58c23975cae1
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/gofiber/fiber/v2 v2.1.4 => github.com/webp-sh/fiber/v2 v2.1.4
|
||||
github.com/chai2010/webp v1.1.0 => github.com/webp-sh/webp v1.1.1
|
||||
)
|
||||
github.com/chai2010/webp v1.1.0 => github.com/webp-sh/webp v1.2.0
|
||||
github.com/gofiber/fiber/v2 v2.4.0 => github.com/webp-sh/fiber/v2 v2.4.0
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ func autoUpdate() {
|
||||
}
|
||||
|
||||
var filename = fmt.Sprintf("webp-server-%s-%s", runtime.GOOS, runtime.GOARCH)
|
||||
if runtime.GOARCH == "windows" {
|
||||
if runtime.GOOS == "windows" {
|
||||
filename += ".exe"
|
||||
}
|
||||
var releaseUrl = "https://github.com/webp-sh/webp_server_go/releases/latest/download/" + filename
|
||||
|
@ -54,6 +54,20 @@ func deferInit() {
|
||||
}
|
||||
}
|
||||
|
||||
func switchProxyMode() {
|
||||
// Check for remote address
|
||||
matched, _ := regexp.MatchString(`^https?://`, config.ImgPath)
|
||||
proxyMode = false
|
||||
if matched {
|
||||
proxyMode = true
|
||||
} else {
|
||||
_, err := os.Stat(config.ImgPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Your image path %s is incorrect.Please check and confirm.", config.ImgPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Our banner
|
||||
banner := fmt.Sprintf(`
|
||||
@ -82,18 +96,7 @@ Develop by WebP Server team. https://github.com/webp-sh`, version)
|
||||
|
||||
go autoUpdate()
|
||||
config = loadConfig(configPath)
|
||||
|
||||
// Check for remote address
|
||||
matched, _ := regexp.MatchString(`^https?://`, config.ImgPath)
|
||||
proxyMode = false
|
||||
if matched {
|
||||
proxyMode = true
|
||||
} else {
|
||||
_, err := os.Stat(config.ImgPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Your image path %s is incorrect.Please check and confirm.", config.ImgPath)
|
||||
}
|
||||
}
|
||||
switchProxyMode()
|
||||
|
||||
if prefetch {
|
||||
go prefetchImages(config.ImgPath, config.ExhaustPath, config.Quality)
|
||||
|
@ -5,8 +5,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
@ -34,17 +36,40 @@ func TestDeferInit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMainFunction(t *testing.T) {
|
||||
// first test verbose mode
|
||||
assert.False(t, verboseMode)
|
||||
assert.Equal(t, log.GetLevel(), log.InfoLevel)
|
||||
os.Args = append(os.Args, "-v", "-prefetch")
|
||||
|
||||
// run main function
|
||||
go main()
|
||||
time.Sleep(time.Second * 2)
|
||||
// verbose, prefetch
|
||||
assert.Equal(t, log.GetLevel(), log.DebugLevel)
|
||||
assert.True(t, verboseMode)
|
||||
assert.True(t, prefetch)
|
||||
|
||||
// test read config value
|
||||
assert.Equal(t, "config.json", configPath)
|
||||
assert.False(t, prefetch)
|
||||
assert.Equal(t, runtime.NumCPU(), jobs)
|
||||
assert.Equal(t, false, dumpSystemd)
|
||||
assert.Equal(t, false, dumpConfig)
|
||||
assert.False(t, verboseMode)
|
||||
|
||||
// test port
|
||||
conn, err := net.DialTimeout("tcp", net.JoinHostPort("127.0.0.1", "3333"), time.Second*2)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, conn)
|
||||
}
|
||||
|
||||
func TestProxySwitch(t *testing.T) {
|
||||
// real proxy mode
|
||||
assert.False(t, proxyMode)
|
||||
config.ImgPath = "https://z.cn"
|
||||
switchProxyMode()
|
||||
assert.True(t, proxyMode)
|
||||
|
||||
// normal
|
||||
config.ImgPath = os.TempDir()
|
||||
switchProxyMode()
|
||||
assert.False(t, proxyMode)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user