// Copyright © 2023 Roberto Hidalgo // SPDX-License-Identifier: Apache-2.0 package payload import ( "encoding/base64" "encoding/json" ) type Parser interface { Parse() (*Payload, error) } type Kind string const ( KindText Kind = "text" KindJSON Kind = "json" KindForm Kind = "form" ) type Payload struct { Kind Kind `json:"type"` Value any `json:"value"` } func (p *Payload) Encoded() ([]byte, error) { b, err := json.Marshal(map[string]any{"type": p.Kind, "value": p.Value}) if err != nil { return nil, err } return []byte(base64.StdEncoding.EncodeToString(b)), nil }