aboutsummaryrefslogtreecommitdiff
path: root/lib/http/endpoint_response_example_test.go
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2024-03-15lib/http: refactoring Client methods to return struct ClientResponseShulhan
Instead of returning three variables, [http.Response], []byte, and error, we combine the [http.Response] and []byte into single struct: ClientResponse.
2024-03-14lib/http: refactor Client methods to use struct ClientRequestShulhan
2024-03-09lib/http: refactoring NewServer and NewClientShulhan
The NewServer and NewClient now accept non-pointer options, so the caller unable to modify the options once the server or client has been created.
2024-03-09lib/http: refactor of RegisterEndpoint and RegisterSSE to non-pointerShulhan
Once the endpoint registered, the caller should not able to changes any values on endpoint again.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2023-09-14all: fix variable shadowing as reported by shadow toolShulhan
The shadow tool [1] report a variable where its name is declared twice or more, in different scope. [1] https://pkg.go.dev/golang.org/x/tools@v0.13.0/go/analysis/passes/shadow
2023-09-11lib/http: realign struct for better size allocationShulhan
The realignment reduce the cost of the following struct, * EndpointResponse: from 72 to 56 bytes (-16 bytes) * RangePosition: from 48 to 24 bytes (-24 bytes) * testCase in TestParseContentRange: from 24 to 16 bytes (-8 bytes)
2023-02-25all: access embedded field or methods using the type nameShulhan
This is for clarity in the code, better to be explicit by typing where the field or methods come from.
2022-08-29lib/http: increase time sleep waiting for server on example endpointShulhan
On container, sometimes the test fail with the following error 2022-08-28 19:32:21 UTC DefaultErrorHandler: POST /error/custom: Custom error 2022/08/28 19:32:22 Do: Get "http://127.0.0.1:7016/?": dial tcp 127.0.0.1:7016: connect: connection refused FAIL github.com/shuLhan/share/lib/http 1.583s This was caused by server is not ready yet to accept connection when testing executed.
2022-01-09lib/http: refactoring NewClient to accept single structShulhan
Previously, the NewClient function accept three parameters: serverURL, http.Header, and insecure. If we want to add another parameter, for example timeout it will cause changes on the function signature. To prevent this changes in the future, we change it now. The NewClient now accept single struct. While at it, we add option to set Timeout. The Timeout affect the http Transport Timeout and TLSHandshakeTimeout. The field is optional, if not set it will set to 10 seconds.
2021-07-30lib/http: add missing license headerShulhan
2021-03-14all: refactoring http.Client methods signatureShulhan
Previously, parameters to method Delete, Get, Post, PostForm, PostFormData, PostJSON, Put, and PutJSON are in the following order: (headers, path, params) This is sometimes confusing. To make it better and works with format of HTTP request header, METHOD PATH HEADERS PARAMS we move the path to the first parameter and headers as the second parameter, so the call to client methods would be (path, headers, params)
2021-03-04http: refactoring parameters on Callback and CallbackErrorHandlerShulhan
Previously, the parameters to Callback has three types: the http.ResponseWriter, *http.Request, and []byte for response body. Not only the type names are long, there is no information on the registered Endpoint on the receiver of Callback. This changes wrap the three parameters into single type EndpointRequest with addition field Endpoint, which contains the registered Endpoint. On the CallbackErrorHandler we also have three parameters, but instead of request body we have an error. This changes store the error for CallbackErrorHandler inside EndpointRequest.Error field.
2021-03-04http: rename "GenericResponse" to "EndpointResponse"Shulhan
Well, the hard thing in software is naming a thing. Using the term Generic is too generic, so we change it to make it closer with Endpoint.