mediatyper

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package mediatyper parses and formats HTTP media type strings of the form type/subtype+suffix; params. It is a port of the npm media-typer package using only the Go standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(m MediaType) (string, error)

Format reconstructs a media type string from a MediaType value. It returns an error if the type or subtype are not valid tokens.

Types

type MediaType

type MediaType struct {
	// Type is the top-level type, e.g. "application".
	Type string
	// Subtype is the subtype without any suffix, e.g. "vnd.api".
	Subtype string
	// Suffix is the optional structured suffix without the "+", e.g. "json".
	Suffix string
	// Parameters holds media type parameters keyed by lower-case name.
	Parameters map[string]string
}

MediaType represents a parsed media type.

func Parse

func Parse(s string) (MediaType, error)

Parse parses a media type string. It validates token syntax for the type, subtype, optional "+suffix" and parameter names, returning an error on invalid input.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL