better error management + shortcode overflow control
This commit is contained in:
@@ -3,6 +3,7 @@ package client
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
@@ -65,6 +66,18 @@ func GetConfig() *Config {
|
||||
return instance
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if c.StoragePath == "" {
|
||||
return errors.New("storage_path is required")
|
||||
}
|
||||
|
||||
if c.Chunksize < 1024 || c.Chunksize > 10*1024*1024 {
|
||||
return fmt.Errorf("chunksize must be between 1KB and 10MB, got %d", c.Chunksize)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) Load(filename string) error {
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
@@ -74,6 +87,9 @@ func (c *Config) Load(filename string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid config: %w", err)
|
||||
}
|
||||
// override values if not set or wrong
|
||||
if c.HttpTimeOut <= 0 {
|
||||
c.HttpTimeOut = 10
|
||||
|
||||
Reference in New Issue
Block a user