Documentation ¶
Index ¶
- Variables
- func Deserialize[E ErrorHandler, T any](gotBody, wantBody io.Reader, t *testing.T) (gotT, wantT T, success bool)
- func DispatchName(t any) string
- func NewAgent(uri string) messaging.OpsAgent
- func NewAgentWithChannel(uri string, ch *messaging.Channel) messaging.OpsAgent
- func NewRequest(uri any) (*http.Request, *core.Status)
- func NewRequestTest(uri any, t *testing.T) *http.Request
- func NewResponseTest(uri any, t *testing.T) *http.Response
- func ReadContent(rawHttp []byte) (*bytes.Buffer, error)
- func WriteResponse(url string, resp *http.Response) *core.Status
- type ErrorHandler
- type FileList
- type Notifier
- type Output
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DefaultTracer = new(defaultTracer)
)
View Source
var (
Dispatcher = new(testDispatch)
)
Functions ¶
func Deserialize ¶
func DispatchName ¶
Example ¶
fmt.Printf("test: DispatchName() -> %v\n", DispatchName(nil)) a := NewAgent("agent-test") fmt.Printf("test: DispatchName() -> %v\n", DispatchName(a)) t := messaging.NewTicker("ticker-test", 100) fmt.Printf("test: DispatchName() -> %v\n", DispatchName(t)) c := messaging.NewChannel("channel-test", false) fmt.Printf("test: DispatchName() -> %v\n", DispatchName(c)) m := messaging.NewControlMessage("", "", "event-test") fmt.Printf("test: DispatchName() -> %v\n", DispatchName(m)) fmt.Printf("test: DispatchName() -> %v\n", DispatchName(core.StatusNotFound())) r := new(http.Response) fmt.Printf("test: DispatchName() -> %v\n", DispatchName(r))
Output: test: DispatchName() -> <nil> test: DispatchName() -> agent-test test: DispatchName() -> ticker-test test: DispatchName() -> channel-test test: DispatchName() -> event-test test: DispatchName() -> Not Found test: DispatchName() -> *http.Response
func NewAgent ¶
Example ¶
a := NewAgent("urn:any") if _, ok := any(a).(messaging.Agent); ok { fmt.Printf("test: opsAgent() -> ok\n") } else { fmt.Printf("test: opsAgent() -> fail\n") }
Output: test: opsAgent() -> ok
func NewAgentWithChannel ¶
func NewResponseTest ¶
NewResponseTest - used from test packages
func WriteResponse ¶
Example ¶
package main import ( "fmt" "github.com/behavioral-ai/core/httpx" ) const ( testInputResponse = "file://[cwd]/test/test-response.txt" testOutputResponse = "file://[cwd]/test/test-response-2.txt" ) func _ExampleWriteStatusLine() { resp, status := httpx.NewResponseFromUri(testInputResponse) line := fmt.Sprintf("%v %v\n", resp.Proto, resp.Status) fmt.Printf("test: NewResponseFromUri() [status:%v] [%v]\n", status, line)
Output: test: NewResponseFromUri() [status:OK] [HTTP/1.1 200 OK] test: WriteResponse("file://[cwd]/test/test-response.txt") -> [status:OK]
Types ¶
type ErrorHandler ¶
ErrorHandler - error handler interface
type FileList ¶
type FileList struct {
Dir, Req, Resp string
}
FileList - note, req file name needs to have an extension
Example ¶
fi := FileList{ Dir: "/test", Req: "test-req.txt", Resp: "", } fmt.Printf("test: FileList() -> [req:%v] [resp:%v]\n", fi.RequestPath(), fi.ResponsePath())
Output: test: FileList() -> [req:/test/test-req.txt] [resp:/test/test-req-resp.txt]
func (FileList) NewRequest ¶
func (FileList) RequestPath ¶
func (FileList) ResponsePath ¶
type Notifier ¶
func NewNotifier ¶
func NewNotifier() Notifier
Example ¶
n := NewNotifier() n.Notify(core.StatusNotFound()) fmt.Printf("test: NewNotifier() -> [status:%v]\n", n.Status()) n.Reset() n.Notify(core.StatusNoContent()) fmt.Printf("test: NewNotifier() -> [status:%v]\n", n.Status())
Output: test: NewNotifier() -> [status:Not Found] test: NewNotifier() -> [status:No Content]
Click to show internal directories.
Click to hide internal directories.