all repos

x @ 3cc36e195be9b8468106cc37b604fe0d61ae7d02

go extra()
2 files changed, 19 insertions(+), 0 deletions(-)
docs(is, envy): add docs
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2025-12-19 17:48:47 +0200
Authored at: 2025-12-19 17:41:15 +0200
Change ID: pxuprtvktourmuuunqpzrtwyqznkqvlu
Parent: 39836f8
M envy/env.go
···
        
        1
        +// Package envy provides type-safe environment variable access.

      
        
        2
        +//

      
        
        3
        +// It supports automatic conversion from string environment variables to common Go types:

      
        
        4
        +// string, int, int64, float64, bool, and time.Duration.

      
        
        5
        +//

      
        
        6
        +// If an environment variable is not set or cannot be parsed, functions return the zero value

      
        
        7
        +// of the requested type.

      
        1
        8
         package envy

      
        2
        9
         

      
        3
        10
         import (

      ···
        6
        13
         	"time"

      
        7
        14
         )

      
        8
        15
         

      
        
        16
        +// Get retrieves an environment variable and converts it to the specified type T.

      
        
        17
        +// Supported types: string, int, int64, float64, bool, time.Duration.

      
        
        18
        +//

      
        
        19
        +// If the environment variable is not set or cannot be parsed, returns the zero value of T.

      
        9
        20
         func Get[T comparable](key string) T {

      
        10
        21
         	var zero T

      
        11
        22
         	val, ok := os.LookupEnv(key)

      ···
        41
        52
         	return res.(T)

      
        42
        53
         }

      
        43
        54
         

      
        
        55
        +// GetOrDefault retrieves an environment variable, if not set, returns default value.

      
        
        56
        +// Supported types: string, int, int64, float64, bool, time.Duration.

      
        44
        57
         func GetOrDefault[T comparable](key string, def T) T {

      
        45
        58
         	var zero T

      
        46
        59
         	if val := Get[T](key); val != zero {

      
M is/is.go
···
        8
        8
         	"testing"

      
        9
        9
         )

      
        10
        10
         

      
        
        11
        +// Equal asserts that two values are equal.

      
        11
        12
         func Equal[T any](tb testing.TB, expected, got T) {

      
        12
        13
         	tb.Helper()

      
        13
        14
         

      ···
        16
        17
         	}

      
        17
        18
         }

      
        18
        19
         

      
        
        20
        +// Err asserts error conditions with flexible expected values:

      
        
        21
        +//   - nil: asserts no error occurred

      
        
        22
        +//   - string: asserts error message contains the string

      
        
        23
        +//   - error: asserts errors.Is matches

      
        
        24
        +//   - reflect.Type: asserts errors.As succeeds

      
        19
        25
         func Err(tb testing.TB, got error, expected any) {

      
        20
        26
         	tb.Helper()

      
        21
        27