mimetypes

package
v0.67.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mimetype 管理与 Mime type 相关的数据

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mimetype

type Mimetype[M any, U any] struct {
	Name      string
	Problem   string
	Marshal   M
	Unmarshal U
}

type Mimetypes

type Mimetypes[M any, U any] struct {
	// contains filtered or unexported fields
}

Mimetypes 提供对 mimetype 的管理

M 表示解码方法地的类型; U 表示编码方法的类型;

func New

func New[M any, U any]() *Mimetypes[M, U]

func (*Mimetypes[M, U]) Add

func (ms *Mimetypes[M, U]) Add(name string, m M, u U, problem string)

Add 添加新的编码方法

name 为编码名称; problem 为该编码在返回 [server.Problem] 对象时的 mimetype 报头值,如果为空,则会与 name 值相同;

func (*Mimetypes[M, U]) ContentType

func (ms *Mimetypes[M, U]) ContentType(h string) (U, encoding.Encoding, error)

ContentType 从 content-type 报头中获取解码和字符集函数

h 表示 content-type 报头的内容。如果字符集为 utf-8 或是未指定,返回的字符解码为 nil;

func (*Mimetypes[M, U]) Delete

func (ms *Mimetypes[M, U]) Delete(name string)

Delete 删除指定名称的编码方法

func (*Mimetypes[M, U]) Exists

func (ms *Mimetypes[M, U]) Exists(name string) bool

Exists 是否存在同名的

func (*Mimetypes[M, U]) Len

func (ms *Mimetypes[M, U]) Len() int

func (*Mimetypes[M, U]) MarshalFunc

func (ms *Mimetypes[M, U]) MarshalFunc(h string) *Mimetype[M, U]

MarshalFunc 从 h 解析出当前请求所需要的 mimetype 名称和对应的解码函数

*/* 或是空值 表示匹配任意内容,一般会选择第一个元素作匹配; xx/* 表示匹配以 xx/ 开头的任意元素,一般会选择 xx/* 开头的第一个元素; xx/ 表示完全匹配以 xx/ 的内容 如果传递的内容如下:

application/json;q=0.9,*/*;q=1

则因为 */* 的 q 值比较高,而返回 */* 匹配的内容

在不完全匹配的情况下,返回值的名称依然是具体名称。

text/*;q=0.9

返回的名称可能是:

text/plain

func (*Mimetypes[M, U]) Set

func (ms *Mimetypes[M, U]) Set(name string, m M, u U, problem string)

Set 修改或添加指定名称的相关配置

name 用于查找相关的编码方法; 如果 problem 为空,则会与 name 值相同;

Jump to

Keyboard shortcuts

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