chore: better config
/ publish (push) Successful in 3m1s

This commit is contained in:
2026-03-07 20:55:04 +01:00
parent fca1030e1a
commit eab7eb3879
5 changed files with 24 additions and 4 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ func (s *Service) GetImage(ctx context.Context, uid string, options Options) (im
outBuff := bytes.NewBuffer(make([]byte, 0, 1024))
if options.Quality == 0 {
options.Quality = 80
options.Quality = s.cfg.Quality
}
err = jpeg.Encode(outBuff, decImage, &jpeg.Options{Quality: options.Quality})
+5 -2
View File
@@ -3,6 +3,7 @@ package images
import (
"os"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
"github.com/valkey-io/valkey-go"
"golang.org/x/sync/semaphore"
)
@@ -17,13 +18,15 @@ type Service struct {
fs fileSystem
cache valkey.Client
seph *semaphore.Weighted
cfg *config.ImageConfig
}
func New(fs fileSystem, cache valkey.Client, maxConcurency int64) *Service {
func New(fs fileSystem, cfg *config.ImageConfig, cache valkey.Client) *Service {
return &Service{
fs: fs,
cache: cache,
seph: semaphore.NewWeighted(maxConcurency),
seph: semaphore.NewWeighted(cfg.Concurency),
cfg: cfg,
}
}
+10
View File
@@ -0,0 +1,10 @@
package config
func Default() Cfg {
return Cfg{
Image: &ImageConfig{
Concurency: 10,
Quality: 80,
},
}
}
+7
View File
@@ -9,6 +9,7 @@ import (
type Cfg struct {
FileSystem *WebdavConfig `env:", prefix=FILESYSTEM_"`
Cache *ValkeyConfig `env:", prefix=CACHE_"`
Image *ImageConfig `env:", prefix=IMAGE_"`
}
type WebdavConfig struct {
@@ -30,7 +31,13 @@ type ValkeyConfig struct {
InitAddress []string `env:"ADDRESS"`
}
type ImageConfig struct {
Concurency int64 `env:"CONCURENCY"`
Quality int `env:"QUALITY"`
}
func Read(ctx context.Context) (cfg Cfg, err error) {
cfg = Default()
err = envconfig.ProcessWith(ctx, &envconfig.Config{
Target: &cfg,
+1 -1
View File
@@ -50,7 +50,7 @@ func (s *Server) registerOther() (h http.Handler) {
}
_ = resthome.New(mux, page.New(fs))
_ = restimage.New(mux, images.New(fs, valkeyClient, 4))
_ = restimage.New(mux, images.New(fs, s.cfg.Image, valkeyClient))
mux.Handle("/", http.FileServer(http.FS(web.GetStaticFS())))