lockserver/config/types.go

37 lines
619 B
Go

package config
import (
"encoding/base64"
"encoding/json"
)
type JSONBytes []byte
func (j JSONBytes) MarshalJSON() ([]byte, error) {
return json.Marshal(base64.URLEncoding.EncodeToString(j))
}
func (j JSONBytes) String() string {
return base64.URLEncoding.EncodeToString(j)
}
func (j *JSONBytes) UnmarshalJSON(data []byte) error {
var str string
err := json.Unmarshal(data, &str)
if err != nil {
return err
}
parsed, err := base64.URLEncoding.DecodeString(str)
if err != nil {
return err
}
*j = JSONBytes(parsed)
return nil
}
func (j JSONBytes) AsByteArrayArray() []byte {
return []byte(j)
}