Skip to content
Snippets Groups Projects

Update file README.md

Merged Lars Niklas Schröder requested to merge lasc2163/webservice:fix-readme into main
Files
4
+ 25
3
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"unicode"
fp "path/filepath"
configParser "github.com/caarlos0/env/v9"
@@ -12,9 +13,13 @@ import (
const BODY_SIZE_LIMIT = 32 * 1024 * 1024 // 32 MB, in bytes
var version string = "n/a"
type Config struct {
Version string `env:"VERSION" envDefault:"N/A"`
Version string
FontColor string `env:"FONT_COLOR" envDefault:""`
LogLevel string `env:"LOG_LEVE" envDefault:"error"`
@@ -31,7 +36,9 @@ type Config struct {
func New() ( *Config, error ){
cfg := Config{}
cfg := Config{
Version: version,
}
if err := configParser.Parse( &cfg ); err != nil {
return nil, err
@@ -61,7 +68,6 @@ func New() ( *Config, error ){
)
}
if len( cfg.DatabaseHost ) >= 1 && len( cfg.DatabasePassword ) >= 2 {
if ! fp.IsLocal( cfg.DatabasePassword ) && ! fp.IsAbs( cfg.DatabasePassword ) {
return nil, errors.New(
@@ -81,6 +87,22 @@ func New() ( *Config, error ){
}
}
if len( cfg.FontColor ) >= 1 {
if len( cfg.FontColor ) >= 21 {
return nil, errors.New(
fmt.Sprintln( "Font color too long" ),
)
}
for _, r := range cfg.FontColor {
if ! unicode.IsLetter( r ) {
return nil, errors.New(
fmt.Sprintln( "Invalid character in font color" ),
)
}
}
}
return &cfg, nil
}
Loading