refactor: разнести пакеты и обновить валидацию
This commit is contained in:
29
protocol/config.go
Normal file
29
protocol/config.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package protocol
|
||||
|
||||
type Config struct {
|
||||
MaxRouteLen int
|
||||
MaxTextLen int
|
||||
MaxTemplateLen int
|
||||
}
|
||||
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
MaxRouteLen: 3,
|
||||
MaxTextLen: 200,
|
||||
MaxTemplateLen: 200,
|
||||
}
|
||||
}
|
||||
|
||||
func NormalizeConfig(cfg Config) Config {
|
||||
def := DefaultConfig()
|
||||
if cfg.MaxRouteLen <= 0 {
|
||||
cfg.MaxRouteLen = def.MaxRouteLen
|
||||
}
|
||||
if cfg.MaxTextLen <= 0 {
|
||||
cfg.MaxTextLen = def.MaxTextLen
|
||||
}
|
||||
if cfg.MaxTemplateLen <= 0 {
|
||||
cfg.MaxTemplateLen = def.MaxTemplateLen
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
Reference in New Issue
Block a user