mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-15 10:25:55 -07:00
feat: configurable mbz rate limit
This commit is contained in:
parent
d2277aea32
commit
7b18ebb294
2 changed files with 13 additions and 1 deletions
|
|
@ -23,6 +23,7 @@ const (
|
||||||
ENABLE_FULL_IMAGE_CACHE_ENV = "KOITO_ENABLE_FULL_IMAGE_CACHE"
|
ENABLE_FULL_IMAGE_CACHE_ENV = "KOITO_ENABLE_FULL_IMAGE_CACHE"
|
||||||
LOG_LEVEL_ENV = "KOITO_LOG_LEVEL"
|
LOG_LEVEL_ENV = "KOITO_LOG_LEVEL"
|
||||||
MUSICBRAINZ_URL_ENV = "KOITO_MUSICBRAINZ_URL"
|
MUSICBRAINZ_URL_ENV = "KOITO_MUSICBRAINZ_URL"
|
||||||
|
MUSICBRAINZ_RATE_LIMIT_ENV = "KOITO_MUSICBRAINZ_RATE_LIMIT"
|
||||||
ENABLE_LBZ_RELAY_ENV = "KOITO_ENABLE_LBZ_RELAY"
|
ENABLE_LBZ_RELAY_ENV = "KOITO_ENABLE_LBZ_RELAY"
|
||||||
LBZ_RELAY_URL_ENV = "KOITO_LBZ_RELAY_URL"
|
LBZ_RELAY_URL_ENV = "KOITO_LBZ_RELAY_URL"
|
||||||
LBZ_RELAY_TOKEN_ENV = "KOITO_LBZ_RELAY_TOKEN"
|
LBZ_RELAY_TOKEN_ENV = "KOITO_LBZ_RELAY_TOKEN"
|
||||||
|
|
@ -45,6 +46,7 @@ type config struct {
|
||||||
// baseUrl string
|
// baseUrl string
|
||||||
databaseUrl string
|
databaseUrl string
|
||||||
musicBrainzUrl string
|
musicBrainzUrl string
|
||||||
|
musicBrainzRateLimit int
|
||||||
logLevel int
|
logLevel int
|
||||||
structuredLogging bool
|
structuredLogging bool
|
||||||
enableFullImageCache bool
|
enableFullImageCache bool
|
||||||
|
|
@ -95,6 +97,10 @@ func loadConfig(getenv func(string) string) (*config, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cfg.listenPort = defaultListenPort
|
cfg.listenPort = defaultListenPort
|
||||||
}
|
}
|
||||||
|
cfg.musicBrainzRateLimit, err = strconv.Atoi(getenv(MUSICBRAINZ_RATE_LIMIT_ENV))
|
||||||
|
if err != nil {
|
||||||
|
cfg.musicBrainzRateLimit = 1
|
||||||
|
}
|
||||||
cfg.musicBrainzUrl = getenv(MUSICBRAINZ_URL_ENV)
|
cfg.musicBrainzUrl = getenv(MUSICBRAINZ_URL_ENV)
|
||||||
if cfg.musicBrainzUrl == "" {
|
if cfg.musicBrainzUrl == "" {
|
||||||
cfg.musicBrainzUrl = defaultMusicBrainzUrl
|
cfg.musicBrainzUrl = defaultMusicBrainzUrl
|
||||||
|
|
@ -192,6 +198,12 @@ func MusicBrainzUrl() string {
|
||||||
return globalConfig.musicBrainzUrl
|
return globalConfig.musicBrainzUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MusicBrainzRateLimit() int {
|
||||||
|
lock.RLock()
|
||||||
|
defer lock.RUnlock()
|
||||||
|
return globalConfig.musicBrainzRateLimit
|
||||||
|
}
|
||||||
|
|
||||||
func LogLevel() int {
|
func LogLevel() int {
|
||||||
lock.RLock()
|
lock.RLock()
|
||||||
defer lock.RUnlock()
|
defer lock.RUnlock()
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func NewMusicBrainzClient() *MusicBrainzClient {
|
||||||
ret := new(MusicBrainzClient)
|
ret := new(MusicBrainzClient)
|
||||||
ret.url = cfg.MusicBrainzUrl()
|
ret.url = cfg.MusicBrainzUrl()
|
||||||
ret.userAgent = "Koito/0.0.1 (contact@koito.app)"
|
ret.userAgent = "Koito/0.0.1 (contact@koito.app)"
|
||||||
ret.requestQueue = queue.NewRequestQueue(1, 1)
|
ret.requestQueue = queue.NewRequestQueue(cfg.MusicBrainzRateLimit(), cfg.MusicBrainzRateLimit())
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue