| Age | Commit message (Collapse) | Author |
|
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/
|
|
Instead of returning three variables, [http.Response], []byte, and error,
we combine the [http.Response] and []byte into single struct:
ClientResponse.
|
|
|
|
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.
|
|
Once the endpoint registered, the caller should not able to changes
any values on endpoint again.
|
|
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.
|
|
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]
|
|
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
|
|
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)
|
|
This is for clarity in the code, better to be explicit by typing where
the field or methods come from.
|
|
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.
|
|
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.
|
|
|
|
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)
|
|
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.
|
|
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.
|