pomerium/internal/encoding/base64.go
Caleb Doxsey aad8ac2e61
replace GetAllPages with InitialSync, improve merge performance (#1624)
* replace GetAllPages with InitialSync, improve merge performance

* fmt proto

* add test for base64 function

* add sync test

* go mod tidy

Co-authored-by: Bobby DeSimone <bobbydesimone@gmail.com>
2020-11-30 12:21:44 -07:00

23 lines
463 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 interface{}) 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)
}