This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/data/data.go

42 lines
1.0 KiB
Go
Raw Normal View History

package data
import "io"
2023-03-28 00:44:39 +00:00
import "bytes"
// Data represents arbitrary polymorphic data that can be used for data transfer
// between applications.
type Data map[Mime] io.ReadCloser
// Mime represents a MIME type.
type Mime struct {
// Type is the first half of the MIME type, and Subtype is the second
// half. The separating slash is not included in either. For example,
// text/html becomes:
// Mime { Type: "text", Subtype: "html" }
Type, Subtype string
}
2023-03-28 05:00:54 +00:00
// M is shorthand for creating a MIME type.
func M (ty, subtype string) Mime {
return Mime { ty, subtype }
}
// String returns the string representation of the MIME type.
func (mime Mime) String () string {
return mime.Type + "/" + mime.Subtype
}
var MimePlain = Mime { "text", "plain" }
var MimeFile = Mime { "text", "uri-list" }
2023-03-28 00:44:39 +00:00
type byteReadCloser struct { *bytes.Reader }
func (byteReadCloser) Close () error { return nil }
// Text returns plain text Data given a string.
func Text (text string) Data {
return Data {
MimePlain: byteReadCloser { bytes.NewReader([]byte(text)) },
}
}