update-deps #1
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea/
|
||||
|
||||
top-wallpaper
|
59
.gitea/workflows/lint.yml
Normal file
59
.gitea/workflows/lint.yml
Normal file
@@ -0,0 +1,59 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "*"
|
||||
|
||||
name: 🚨 Test Code Base
|
||||
run-name: ${{ github.workflow }}-{{ github.ref_name }}-{{ github.run_number }}
|
||||
|
||||
env:
|
||||
GO_VERSION: '1.24.6'
|
||||
|
||||
jobs:
|
||||
test-go:
|
||||
name: 🔍 🐹 Go Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: 🛡️ 🔒 Add Siteworx CA Certificates
|
||||
run: |
|
||||
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
|
||||
update-ca-certificates
|
||||
|
||||
- name: ⚙️ 🐹 Set up Go Environment
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
cache: true
|
||||
|
||||
- name: 📖 🔍 Checkout Repository Code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: 📦 📥 Install Dependencies
|
||||
run: |
|
||||
go mod download
|
||||
|
||||
- name: ✅ 🔍 Run Go Tests
|
||||
run: |
|
||||
go test -v ./... -coverprofile=coverage.out
|
||||
|
||||
golangci-lint:
|
||||
name: 🧹 Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 📥 Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: 🛠️ Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
|
||||
- name: 📦 📥 Install Dependencies
|
||||
run: |
|
||||
go mod download
|
||||
|
||||
- name: ✅ 🔍 Run Go Lint
|
||||
uses: golangci/golangci-lint-action@v8.0.0
|
61
.golangci.yml
Normal file
61
.golangci.yml
Normal file
@@ -0,0 +1,61 @@
|
||||
version: "2"
|
||||
linters:
|
||||
default: none
|
||||
enable:
|
||||
- bodyclose
|
||||
- gocritic
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- testifylint
|
||||
- unused
|
||||
settings:
|
||||
govet:
|
||||
disable:
|
||||
- fieldalignment
|
||||
enable-all: true
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
rules:
|
||||
- linters:
|
||||
- bodyclose
|
||||
path: .*_test.go
|
||||
- linters:
|
||||
- bodyclose
|
||||
path: router/timeout_response.go
|
||||
# False positives on CGO generated code
|
||||
- linters:
|
||||
- staticcheck
|
||||
path: vips/.*
|
||||
text: 'SA4000:'
|
||||
# False positives on CGO generated code
|
||||
- linters:
|
||||
- gocritic
|
||||
path: vips/.*
|
||||
text: dupSubExpr
|
||||
# False positives on CGO generated code
|
||||
- linters:
|
||||
- staticcheck
|
||||
text: 'ST1005:'
|
||||
paths:
|
||||
- .tmp
|
||||
- vendor
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
enable:
|
||||
- goimports
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- .tmp
|
||||
- vendor
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
@@ -1,10 +1,10 @@
|
||||
FROM siteworxpro/golang:1.24.3 AS build
|
||||
FROM siteworxpro/golang:1.24.6 AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ADD . .
|
||||
|
||||
ENV GOPRIVATE=git.s.int
|
||||
ENV GOPRIVATE=gitea.siteworxpro.com
|
||||
ENV GOPROXY=direct
|
||||
ENV CGO_ENABLED=0
|
||||
|
||||
|
20
go.mod
20
go.mod
@@ -1,24 +1,24 @@
|
||||
module github.com/siteworxpro/top-wallpaper
|
||||
|
||||
go 1.24.3
|
||||
go 1.24.6
|
||||
|
||||
require (
|
||||
github.com/labstack/echo/v4 v4.13.3
|
||||
github.com/labstack/echo/v4 v4.13.4
|
||||
github.com/labstack/gommon v0.4.2
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/redis/go-redis/v9 v9.7.0
|
||||
github.com/redis/go-redis/v9 v9.12.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
golang.org/x/crypto v0.31.0 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/time v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.41.0 // indirect
|
||||
golang.org/x/net v0.43.0 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
golang.org/x/time v0.12.0 // indirect
|
||||
)
|
||||
|
18
go.sum
18
go.sum
@@ -4,16 +4,22 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
|
||||
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
|
||||
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
|
||||
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
|
||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
@@ -23,6 +29,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
|
||||
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
||||
github.com/redis/go-redis/v9 v9.12.1 h1:k5iquqv27aBtnTm2tIkROUDp8JBXhXZIVu1InSgvovg=
|
||||
github.com/redis/go-redis/v9 v9.12.1/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
@@ -31,15 +39,25 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
||||
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/siteworxpro/top-wallpaper/redis"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Get(c echo.Context) error {
|
||||
|
16
main.go
16
main.go
@@ -2,17 +2,22 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"github.com/labstack/gommon/log"
|
||||
tphttp "github.com/siteworxpro/top-wallpaper/http"
|
||||
"github.com/siteworxpro/top-wallpaper/reddit"
|
||||
"github.com/siteworxpro/top-wallpaper/redis"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const ContextKeyLogger contextKey = "logger"
|
||||
|
||||
func main() {
|
||||
|
||||
ctx, fn := context.WithCancel(context.Background())
|
||||
@@ -22,7 +27,8 @@ func main() {
|
||||
|
||||
if err != nil {
|
||||
log.Error("Could not initialize Redis client: ", err)
|
||||
os.Exit(1)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
e := echo.New()
|
||||
@@ -55,7 +61,7 @@ func main() {
|
||||
}
|
||||
|
||||
ctx = redis.WithContext(ctx, rc)
|
||||
ctx = context.WithValue(ctx, "logger", e.Logger)
|
||||
ctx = context.WithValue(ctx, ContextKeyLogger, e.Logger)
|
||||
|
||||
go reddit.Fetch(ctx)
|
||||
|
||||
|
@@ -60,15 +60,16 @@ func GetLatestImage(httpGet func(url string) (*http.Response, error)) (string, e
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(response.Body)
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("error fetching reddit data: %s", response.Status)
|
||||
}
|
||||
|
||||
jsonBytes, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
redditData := redditResponse{}
|
||||
err = json.Unmarshal(jsonBytes, &redditData)
|
||||
|
@@ -2,9 +2,6 @@ package reddit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/siteworxpro/top-wallpaper/redis"
|
||||
"github.com/siteworxpro/top-wallpaper/resize"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -12,6 +9,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/siteworxpro/top-wallpaper/redis"
|
||||
"github.com/siteworxpro/top-wallpaper/resize"
|
||||
)
|
||||
|
||||
func Fetch(ctx context.Context) {
|
||||
@@ -50,6 +51,11 @@ func Fetch(ctx context.Context) {
|
||||
default:
|
||||
|
||||
val, err := rc.Get(redis.CacheKey)
|
||||
if err != nil {
|
||||
l.Error("Error fetching from Redis: ", err)
|
||||
break
|
||||
}
|
||||
|
||||
if val != "" {
|
||||
l.Info("Reddit image fetched from cache...")
|
||||
|
||||
@@ -76,11 +82,11 @@ func Fetch(ctx context.Context) {
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
response, err := httpClient.Do(request)
|
||||
response, e := httpClient.Do(request)
|
||||
|
||||
if err != nil {
|
||||
l.Error("Error fetching image from Reddit: ", err)
|
||||
return nil, err
|
||||
if e != nil {
|
||||
l.Error("Error fetching image from Reddit: ", e)
|
||||
return nil, e
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
@@ -94,6 +100,11 @@ func Fetch(ctx context.Context) {
|
||||
return response, nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
l.Error("Error getting latest image URL: ", err)
|
||||
break
|
||||
}
|
||||
|
||||
response, err := http.Get(latestImageVal)
|
||||
if err != nil {
|
||||
l.Error("Error fetching image from Reddit: ", err)
|
||||
@@ -119,6 +130,11 @@ func Fetch(ctx context.Context) {
|
||||
imageData := string(imageDataBytes)
|
||||
resized, err := resize.Shrink(imageData, uint(size), 70)
|
||||
|
||||
if err != nil {
|
||||
l.Error("Error resizing image: ", err)
|
||||
break
|
||||
}
|
||||
|
||||
err = rc.Set(redis.CacheKey, resized, 10*time.Minute)
|
||||
if err != nil {
|
||||
l.Warn("could not cache image")
|
||||
|
@@ -4,10 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
@@ -3,10 +3,11 @@ package resize
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/nfnt/resize"
|
||||
i "image"
|
||||
"image/jpeg"
|
||||
_ "image/png"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
)
|
||||
|
||||
func Shrink(image string, maxSize uint, quality int) (string, error) {
|
||||
|
Reference in New Issue
Block a user