summaryrefslogtreecommitdiff
path: root/vendor/github.com/KimMachineGun/automemlimit/memlimit/provider.go
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2025-03-09 17:47:56 +0100
committerLibravatar Terin Stock <terinjokes@gmail.com>2025-03-10 01:59:49 +0100
commit3ac1ee16f377d31a0fb80c8dae28b6239ac4229e (patch)
treef61faa581feaaeaba2542b9f2b8234a590684413 /vendor/github.com/KimMachineGun/automemlimit/memlimit/provider.go
parent[chore] update URLs to forked source (diff)
downloadgotosocial-3ac1ee16f377d31a0fb80c8dae28b6239ac4229e.tar.xz
[chore] remove vendor
Diffstat (limited to 'vendor/github.com/KimMachineGun/automemlimit/memlimit/provider.go')
-rw-r--r--vendor/github.com/KimMachineGun/automemlimit/memlimit/provider.go43
1 files changed, 0 insertions, 43 deletions
diff --git a/vendor/github.com/KimMachineGun/automemlimit/memlimit/provider.go b/vendor/github.com/KimMachineGun/automemlimit/memlimit/provider.go
deleted file mode 100644
index 4f83770d1..000000000
--- a/vendor/github.com/KimMachineGun/automemlimit/memlimit/provider.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package memlimit
-
-import (
- "fmt"
-)
-
-// Provider is a function that returns the memory limit.
-type Provider func() (uint64, error)
-
-// Limit is a helper Provider function that returns the given limit.
-func Limit(limit uint64) func() (uint64, error) {
- return func() (uint64, error) {
- return limit, nil
- }
-}
-
-// ApplyRationA is a helper Provider function that applies the given ratio to the given provider.
-func ApplyRatio(provider Provider, ratio float64) Provider {
- if ratio == 1 {
- return provider
- }
- return func() (uint64, error) {
- if ratio <= 0 || ratio > 1 {
- return 0, fmt.Errorf("invalid ratio: %f, ratio should be in the range (0.0,1.0]", ratio)
- }
- limit, err := provider()
- if err != nil {
- return 0, err
- }
- return uint64(float64(limit) * ratio), nil
- }
-}
-
-// ApplyFallback is a helper Provider function that sets the fallback provider.
-func ApplyFallback(provider Provider, fallback Provider) Provider {
- return func() (uint64, error) {
- limit, err := provider()
- if err != nil {
- return fallback()
- }
- return limit, nil
- }
-}