pomerium/internal/encoding/base64.go
Caleb Doxsey 1a5b8b606f
core/lint: upgrade golangci-lint, replace interface{} with any (#5099)
* core/lint: upgrade golangci-lint, replace interface{} with any

* regen proto
2024-05-02 14:33:52 -06:00

23 lines
455 B
Go

package encoding
import (
"encoding/base64"
"encoding/json"
"strings"
)
// DecodeBase64OrJSON decodes a JSON string that can optionally be base64 encoded.
func DecodeBase64OrJSON(in string, out any) error {
in = strings.TrimSpace(in)
// the data can be base64 encoded
if !json.Valid([]byte(in)) {
bs, err := base64.StdEncoding.DecodeString(in)
if err != nil {
return err
}
in = string(bs)
}
return json.Unmarshal([]byte(in), out)
}