Documentation ¶
Index ¶
- func Client() *http.Client
- func Deserialize[E runtime.ErrorHandler, T any](body io.ReadCloser) (T, *runtime.Status)
- func Do[E runtime.ErrorHandler, H HttpExchange, T any](req *http.Request) (resp *http.Response, t T, status *runtime.Status)
- func GetContentLocation(req *http.Request) string
- func ReadAll(body io.ReadCloser) ([]byte, error)
- func WriteResponse(w http.ResponseWriter, data []byte, status *runtime.Status, headers ...string)
- type Default
- type HttpExchange
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Client ¶
Example ¶
cp := Client() if cp != nil { cp = nil } fmt.Printf("test: Client() [!nil:%v]\n", Client() != nil)
Output: test: Client() [!nil:true]
func Deserialize ¶
func Deserialize[E runtime.ErrorHandler, T any](body io.ReadCloser) (T, *runtime.Status)
Deserialize - templated function, providing deserialization of a request/response body
Example ¶
result, status := Deserialize[runtime.DebugError, []byte](nil) fmt.Printf("test: Deserialize[DebugError,[]byte](nil) -> [%v] [status:%v]\n", string(result), status) resp := new(http.Response) result, status = Deserialize[runtime.DebugError, []byte](resp.Body) fmt.Printf("test: Deserialize[DebugError,[]byte](resp) -> [%v] [status:%v]\n", string(result), status) resp.Body = &httptest.ReaderCloser{Reader: strings.NewReader("Hello World String"), Err: nil} result, status = Deserialize[runtime.DebugError, []byte](resp.Body) fmt.Printf("test: Deserialize[DebugError,[]byte](resp) -> [%v] [status:%v]\n", string(result), status) resp.Body = &httptest.ReaderCloser{Reader: bytes.NewReader([]byte("Hello World []byte")), Err: nil} result2, status2 := Deserialize[runtime.DebugError, []byte](resp.Body) fmt.Printf("test: Deserialize[DebugError,[]byte](resp) -> [%v] [status:%v]\n", string(result2), status2)
Output: [[] github.com/gotemplates/core/exchange/deserialize [body is nil]] test: Deserialize[DebugError,[]byte](nil) -> [] [status:Invalid Content] [[] github.com/gotemplates/core/exchange/deserialize [body is nil]] test: Deserialize[DebugError,[]byte](resp) -> [] [status:Invalid Content] test: Deserialize[DebugError,[]byte](resp) -> [Hello World String] [status:OK] test: Deserialize[DebugError,[]byte](resp) -> [Hello World []byte] [status:OK]
func Do ¶
func Do[E runtime.ErrorHandler, H HttpExchange, T any](req *http.Request) (resp *http.Response, t T, status *runtime.Status)
Example ¶
req, _ := http.NewRequest("GET", "https://www.google.com/search?q=test", nil) resp, buf, status := Do[runtime.DebugError, Default, []byte](req) fmt.Printf("test: Do[DebugError,[]byte,DefaultExchange](req) -> [status:%v] [buf:%v] [resp:%v]\n", status, len(buf) > 0, resp != nil)
Output: test: Do[DebugError,[]byte,DefaultExchange](req) -> [status:OK] [buf:true] [resp:true]
func GetContentLocation ¶
func ReadAll ¶
func ReadAll(body io.ReadCloser) ([]byte, error)
ReadAll - read all the body, with a deferred close
func WriteResponse ¶
WriteResponse - write a http.Response, utilizing the data, status, and headers for controlling the content
Types ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.