Documentation ¶
Index ¶
- Constants
- func Indent(body io.ReadCloser, h http.Header, prefix, indent string) (io.ReadCloser, *core.Status)
- func Marshal(v any) ([]byte, *core.Status)
- func New[T any](v any, h http.Header) (t T, status *core.Status)
- func NewReadCloser(v any) (io.ReadCloser, int64, *core.Status)
- func NewStatusFrom(uri string) *core.Status
Examples ¶
Constants ¶
View Source
const ( StatusOKUri = "urn:status:ok" StatusNotFoundUri = "urn:status:notfound" StatusTimeoutUri = "urn:status:timeout" )
Variables ¶
This section is empty.
Functions ¶
func Indent ¶
func Indent(body io.ReadCloser, h http.Header, prefix, indent string) (io.ReadCloser, *core.Status)
Example ¶
package main import ( "bytes" "fmt" "github.com/behavioral-ai/core/iox" "io" ) const ( customerAddr = "file://[cwd]/test/customer-address.txt" ) func main() { buf, status := iox.ReadFile(customerAddr) fmt.Printf("test: iox.ReadFile() -> [status:%v] %v\n", status, string(buf)) if status.OK() { //fmt.Printf("test:") c := io.NopCloser(bytes.NewReader(buf)) c2, status1 := Indent(c, nil, "", " ") if status1.OK() { buf2, status := iox.ReadAll(c2, nil) fmt.Printf("test: Indent() -> [status:%v] %v\n", status, string(buf2)) } } }
Output: test: iox.ReadFile() -> [status:OK] [{"customer-id":"C001","created-ts":"0001-01-01T00:00:00Z","address-1":"1514 Cedar Ridge Road","address-2":"","city":"Vinton","state":"IA","postal-code":"52349","email":"before-email@hotmail.com"}] test: Indent() -> [status:OK] [ { "customer-id": "C001", "created-ts": "0001-01-01T00:00:00Z", "address-1": "1514 Cedar Ridge Road", "address-2": "", "city": "Vinton", "state": "IA", "postal-code": "52349", "email": "before-email@hotmail.com" } ]
func New ¶
New - create a new type from JSON content, supporting: string, *url.URL, []byte, io.Reader, io.ReadCloser
func NewReadCloser ¶
NewReadCloser - create an io.ReadCloser from a type
func NewStatusFrom ¶
NewStatusFrom - create a new Status from a URI
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.