Documentation ¶
Index ¶
- Constants
- func Decode(buf []byte, h http.Header) ([]byte, *core.Status)
- func FileName(uri any) string
- func Mount(fs embed.FS)
- func ReadAll(body io.Reader, h http.Header) ([]byte, *core.Status)
- func ReadFile(uri any) ([]byte, *core.Status)
- func ReadFileWithEncoding(uri string, h http.Header) ([]byte, *core.Status)
- func ValidateUri(uri string) *core.Status
- func ZipFile(uri string) *core.Status
- type EncodingReader
- type EncodingWriter
Examples ¶
Constants ¶
View Source
const ( AcceptEncoding = "Accept-Encoding" AcceptEncodingValue = "gzip, deflate, br" ContentEncoding = "Content-Encoding" GzipEncoding = "gzip" BrotliEncoding = "br" DeflateEncoding = "deflate" CompressEncoding = "compress" NoneEncoding = "none" ApplicationGzip = "application/x-gzip" ApplicationBrotli = "application/x-br" ApplicationDeflate = "application/x-deflate" )
View Source
const (
CwdVariable = "[cwd]"
)
View Source
const (
PkgPath = "github/behavioral-ai/core/iox"
)
Variables ¶
This section is empty.
Functions ¶
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]/test/status-504.json) -> [type:string] [buf:82] [status:OK] test: ReadFile(file://[cwd]/test/address1.json) -> [type:string] [buf:68] [status:OK] test: ReadFile(file://[cwd]/test/status-504.json) -> [type:*url.URL] [buf:82] [status:OK] test: ReadFile(file://[cwd]/test/address1.json) -> [type:*url.URL] [buf:68] [status:OK]
func ReadFileWithEncoding ¶
ReadFileWithEncoding - read a file with a possible encoding and a Status
Example ¶
buf, status := ReadFileWithEncoding(helloWorldGzip, nil) fmt.Printf("test: ReadFileWithEncoding(\"%v\",nil) -> [buf:%v] [status:%v]\n", helloWorldGzip, string(buf), status) h := make(http.Header) h.Set(ContentEncoding, GzipEncoding) buf, status = ReadFileWithEncoding(helloWorldGzip, h) fmt.Printf("test: ReadFileWithEncoding(\"%v\",h) -> [buf:%v] [status:%v]\n", helloWorldGzip, string(buf), status) buf, status = ReadFileWithEncoding(helloWorldTxt, nil) fmt.Printf("test: ReadFileWithEncoding(\"%v\",nil) -> [buf:%v] [status:%v]\n", helloWorldTxt, string(buf), status)
Output: test: ReadFileWithEncoding("file://[cwd]/test/hello-world.gz",nil) -> [buf:Hello World!!] [status:OK] test: ReadFileWithEncoding("file://[cwd]/test/hello-world.gz",h) -> [buf:Hello World!!] [status:OK] test: ReadFileWithEncoding("file://[cwd]/test/hello-world.txt",nil) -> [buf:Hello World!!] [status:OK]
func ValidateUri ¶
Types ¶
type EncodingReader ¶
type EncodingReader interface { io.ReadCloser }
func NewEncodingReader ¶
func NewGzipReader ¶
func NewGzipReader(r io.Reader) (EncodingReader, *core.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
Click to show internal directories.
Click to hide internal directories.