better error management + shortcode overflow control

This commit is contained in:
ycc
2026-02-04 18:28:14 +01:00
parent bb3640c1c3
commit b1ecd04a28
6 changed files with 105 additions and 65 deletions

View File

@@ -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