Documentation ¶
Index ¶
- Constants
- func FileName(uri any) string
- func New[T any](v any, h http.Header) (t T, status *runtime.Status)
- func NewStatusFrom(uri string) *runtime.Status
- func ReadAll(body io.Reader, h http.Header) ([]byte, *runtime.Status)
- func ReadFile(uri string) ([]byte, *runtime.Status)
- func ValidateUri(uri string) *runtime.Status
- type EncodingReader
- type EncodingWriter
Examples ¶
Constants ¶
View Source
const ( AcceptEncoding = "Accept-Encoding" ContentEncoding = "Content-Encoding" GzipEncoding = "gzip" BrotliEncoding = "br" DeflateEncoding = "deflate" CompressEncoding = "compress" NoneEncoding = "none" AcceptEncodingValue = "gzip, deflate, br" )
View Source
const ( StatusOKUri = "urn:status:ok" StatusNotFoundUri = "urn:status:notfound" StatusTimeoutUri = "urn:status:timeout" )
View Source
const (
CwdVariable = "[cwd]"
)
View Source
const (
PkgPath = "github/advanced-go/core/io2"
)
Variables ¶
This section is empty.
Functions ¶
func New ¶
New - create a new type from JSON content, supporting: string, *url.URL, []byte, io.Reader, io.ReadCloser Note: content encoded []byte is not supported
func NewStatusFrom ¶
NewStatusFrom - create a new Status from a URI
Example ¶
uri := "file://[cwd]/io2test/status-504.json" status := NewStatusFrom(uri) fmt.Printf("test: NewStatusFrom() -> [code:%v] [location:%v] [errors:[%v]]\n", status.Code, status.Trace(), status.Error())
Output: test: NewStatusFrom() -> [code:504] [location:[ExampleStatus2_Marshalling]] [errors:[error 1]]
func ReadFile ¶
ReadFile - read a file with a Status
Example ¶
s := status504 buf, status := ReadFile(s) fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(s), len(buf), status) s = address1Url buf, status = ReadFile(s) fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(s), len(buf), status) s = status504 u := parseRaw(s) buf, status = ReadFile(u.String()) fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(u), len(buf), status) s = address1Url u = parseRaw(s) buf, status = ReadFile(u.String()) fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(u), len(buf), status)
Output: test: ReadFile(file://[cwd]/io2test/status-504.json) -> [type:string] [buf:82] [status:OK] test: ReadFile(file://[cwd]/io2test/address1.json) -> [type:string] [buf:68] [status:OK] test: ReadFile(file://[cwd]/io2test/status-504.json) -> [type:*url.URL] [buf:82] [status:OK] test: ReadFile(file://[cwd]/io2test/address1.json) -> [type:*url.URL] [buf:68] [status:OK]
func ValidateUri ¶
Types ¶
type EncodingReader ¶
type EncodingReader interface { io.ReadCloser }
func NewEncodingReader ¶
func NewGzipReader ¶
func NewGzipReader(r io.Reader) (EncodingReader, *runtime.Status)
func NewIdentityReader ¶
func NewIdentityReader(r io.Reader) EncodingReader
NewIdentityReader - The default (identity) encoding; the use of no transformation whatsoever
type EncodingWriter ¶
type EncodingWriter interface { io.WriteCloser ContentEncoding() string }
func NewEncodingWriter ¶
func NewGzipWriter ¶
func NewGzipWriter(w io.Writer) EncodingWriter
func NewIdentityWriter ¶
func NewIdentityWriter(w io.Writer) EncodingWriter
NewIdentityWriter - The default (identity) encoding; the use of no transformation whatsoever
Source Files ¶
Click to show internal directories.
Click to hide internal directories.