kelseyhightower / envconfig

Golang library for managing configuration data from environment variables
MIT License
5.01k stars 377 forks source link

Trim String which is surrounded by white space #168

Closed keizo042 closed 4 years ago

keizo042 commented 4 years ago

I'd like to remove white space when we use string type field.

$ cat main.go
package main

import (
    "fmt"
    "github.com/kelseyhightower/envconfig"
)

type A struct {
    B string `envconfig:"B"`
}

func main() {
    var a A
    if err := envconfig.Process("", &a); err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(a.B)
}

$  B="   a" go run main.go
   a
kelseyhightower commented 4 years ago

Thanks for the contribution and putting some thought into this.

This is a breaking change and will not allow anyone to leverage a value with leading spaces. This would surprise people and there would be no way for them to work around it.