Documentation
¶
Index ¶
- func AddFormField(writer *multipart.Writer, parent string, child string, v any) error
- func CreateReadCloser(b []byte) io.ReadCloser
- func Maps(p map[string]any, s ...map[string]any) map[string]any
- func Must[T any](v T, err error) T
- func MustStringSlice(v any) []string
- func Sign(key string, message []byte) (string, error)
- func StringSlice(v any) (slice []string, err error)
- func StructToMap(s any) (map[string]any, error)
- func ToJSON(v any) string
- func ToJSONIndent(v any) string
- func ToURLValues(val any) (values url.Values, err error)
- func Traverse[V any](m any, keys ...any) (*V, error)
- func UUID() string
- type DirectReflection
- type Form
- type GetDirectReflectionFunction
- type MarshalFunction
- type MarshalOptions
- type MarshalResult
- type MultipartFile
- type StructToMapFunction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFormField ¶
AddFormField fills a form field with a key defined by parent[child] or child if parent is empty and writes them into multipart.Writer. Accepted values: string, []byte, func() (MultipartFile, error), and map[string]any
func CreateReadCloser ¶
func CreateReadCloser(b []byte) io.ReadCloser
CreateReadCloser constructs an io.ReadCloser from a byte slice.
func Must ¶
Must returns the provided value if err is nil; otherwise, it panics with the error. Useful for writing tests to reduce error handling boilerplate.
func MustStringSlice ¶
MustStringSlice takes a value of type any and converts them into a string slice. Panics on error.
func StringSlice ¶
StringSlice takes a value of type any and converts them into a string slice.
func StructToMap ¶
StructToMap converts a struct into map[string]any.
func ToJSONIndent ¶
ToJSONIndent returns the JSON string of v with indents or panics.
func ToURLValues ¶
ToURLValues converts v into url.Values.
Types ¶
type DirectReflection ¶
DirectReflection contains the result of GetDirectReflection.
func GetDirectReflection ¶
func GetDirectReflection(s any) DirectReflection
GetDirectReflection returns the direct reflect.Value of an object without the pointer.
type Form ¶
Form is a combined representation of bytes.Buffer and multipart.Writer.
type GetDirectReflectionFunction ¶
type GetDirectReflectionFunction func(s any) DirectReflection
GetDirectReflectionFunction returns the direct reflect.Value of an object without the pointer.
type MarshalFunction ¶
type MarshalFunction func(opts MarshalOptions) (result MarshalResult, err error)
MarshalFunction encodes the provided object according to the media type.
type MarshalOptions ¶
MarshalOptions contains the parameters for MarshalFunction.
type MarshalResult ¶
MarshalResult contains the result of MarshalFunction.
func Marshal ¶
func Marshal(opts MarshalOptions) (result MarshalResult, err error)
Marshal implements MarshalFunction by encoding the provided object according to the media type:
- "multipart/form-data": expects object to be a map[string]any and sets it as a multipart form.
- "application/x-www-form-urlencoded": expects object to be a map[string]any and encodes it as form values.
- "application/json": marshals object as JSON.
Returns an error if the media type is not among the list or the data doesn't match the expected format.
type MultipartFile ¶
type MultipartFile interface { Name() string io.ReadCloser }
MultipartFile is an interface to attach a file into the multipart form. os.File implements this interface.