-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.go
More file actions
45 lines (37 loc) · 1.25 KB
/
config.go
File metadata and controls
45 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Copyright (c) New Cloud Technologies, Ltd. 2013-2026.
* Author: Vitaly Isaev <vitaly.isaev@myoffice.team>
* License: https://github.com/newcloudtechnologies/memlimiter/blob/master/LICENSE
*/
package memlimiter
import (
"errors"
"math"
"github.com/newcloudtechnologies/memlimiter/controller/nextgc"
"github.com/newcloudtechnologies/memlimiter/utils/config/bytes"
)
// Config - high-level MemLimiter config.
type Config struct {
// GoMemoryLimit optionally sets Go runtime soft memory limit via debug.SetMemoryLimit.
// Zero means disabled.
GoMemoryLimit bytes.Bytes `json:"go_memory_limit"`
// ControllerNextGC - NextGC-based controller
ControllerNextGC *nextgc.ControllerConfig `json:"controller_nextgc"` //nolint:tagliatelle
// TODO:
// if new controller implementation appears, put its config here and make switch in Prepare()
// (only one subsection must be not nil).
}
// Prepare validates config.
func (c *Config) Prepare() error {
if c == nil {
// This means that user wants to use stub instead of real memlimiter
return nil
}
if c.ControllerNextGC == nil {
return errors.New("empty ControllerNextGC")
}
if c.GoMemoryLimit.Value > uint64(math.MaxInt64) {
return errors.New("GoMemoryLimit exceeds int64 range")
}
return nil
}