io2

package
v0.0.0-...-b511e1a Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 11 Imported by: 3

Documentation

Index

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 FileName

func FileName(uri any) string

FileName - return the OS correct file name from a URI

func New

func New[T any](v any, h http.Header) (t T, status *runtime.Status)

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

func NewStatusFrom(uri string) *runtime.Status

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 ReadAll

func ReadAll(body io.Reader, h http.Header) ([]byte, *runtime.Status)

ReadAll - read the body with a Status

func ReadFile

func ReadFile(uri string) ([]byte, *runtime.Status)

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

func ValidateUri(uri string) *runtime.Status

Types

type EncodingReader

type EncodingReader interface {
	io.ReadCloser
}

func NewEncodingReader

func NewEncodingReader(r io.Reader, h http.Header) (EncodingReader, *runtime.Status)

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 NewEncodingWriter(w io.Writer, h http.Header) (EncodingWriter, *runtime.Status)

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

Jump to

Keyboard shortcuts

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