From 092f047d142f2d0ef78f2db9c31abf40daa1bf76 Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 30 Nov 2023 14:16:39 +0100 Subject: [PATCH] changed type of 'response.Content' from interface{] to string --- go.sum | 2 ++ internal/api/response.go | 2 +- internal/api/server.go | 4 ++-- internal/api/{stream.go => streams.go} | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) rename internal/api/{stream.go => streams.go} (99%) diff --git a/go.sum b/go.sum index b453435..7d8aba0 100644 --- a/go.sum +++ b/go.sum @@ -13,3 +13,5 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/internal/api/response.go b/internal/api/response.go index c89a896..afc11f4 100644 --- a/internal/api/response.go +++ b/internal/api/response.go @@ -10,7 +10,7 @@ import ( // struct for server responses type response struct { StatusCode int - Content interface{} + Content string error error } diff --git a/internal/api/server.go b/internal/api/server.go index 404c5a1..08103ac 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -33,12 +33,12 @@ func registerHandlers() { func serveRandomImageName(writer http.ResponseWriter, request *http.Request) { timestamp := time.Now().UnixMilli() var response response - response.Content, response.error = internal.GetRandomImage() + response.Content, response.Size, response.error = internal.GetRandomImage() if response.error != nil { response.StatusCode = 404 } response.send(writer) - loggo.DebugTimed("served random image '"+response.Content.(string)+"'", timestamp) + loggo.DebugTimed("served random image '"+response.Content+"'", timestamp) } // request url: '/image' - serve an image diff --git a/internal/api/stream.go b/internal/api/streams.go similarity index 99% rename from internal/api/stream.go rename to internal/api/streams.go index e112fd4..d55ff21 100644 --- a/internal/api/stream.go +++ b/internal/api/streams.go @@ -33,6 +33,8 @@ func streamColorPalette(writer http.ResponseWriter, image string, amount int, al algorithm = strings.ToLower(algorithm) if algorithm == "wu" { algo = 0 + } else { + algorithm = "wsm" } colors, error := color_thief.GetPaletteFromFile(image, amount, algo) if error != nil {