aboutsummaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-03-02 18:28:58 +0700
committerShulhan <ms@kilabit.info>2024-03-05 14:53:03 +0700
commitb921ebfb3e81b367ff24305eb18c5dd073b38635 (patch)
tree89c88e32ad92af2ade65dec6552ddd06ddc0cd90 /lib/http
parent901c9803e6f93e0d5ee282f4061309022c46f490 (diff)
downloadpakakeh.go-b921ebfb3e81b367ff24305eb18c5dd073b38635.tar.xz
all: comply with linter recommendations #1
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]
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/callback_error_handler.go10
-rw-r--r--lib/http/client.go16
-rw-r--r--lib/http/client_options.go6
-rw-r--r--lib/http/client_request.go2
-rw-r--r--lib/http/client_test.go2
-rw-r--r--lib/http/endpoint.go4
-rw-r--r--lib/http/endpoint_example_test.go14
-rw-r--r--lib/http/endpoint_request.go4
-rw-r--r--lib/http/endpoint_response_example_test.go4
-rw-r--r--lib/http/example_server_test.go4
-rw-r--r--lib/http/http.go4
-rw-r--r--lib/http/http_test.go10
-rw-r--r--lib/http/server.go8
-rw-r--r--lib/http/server_test.go13
-rw-r--r--lib/http/serveroptions.go2
-rw-r--r--lib/http/sse_conn.go23
-rw-r--r--lib/http/sse_endpoint.go2
-rw-r--r--lib/http/sseclient/sseclient.go10
-rw-r--r--lib/http/sseclient/sseclient_test.go20
19 files changed, 93 insertions, 65 deletions
diff --git a/lib/http/callback_error_handler.go b/lib/http/callback_error_handler.go
index ec0c4a8a..7a1c075d 100644
--- a/lib/http/callback_error_handler.go
+++ b/lib/http/callback_error_handler.go
@@ -44,14 +44,14 @@ func DefaultErrorHandler(epr *EndpointRequest) {
errInternal.Code = http.StatusInternalServerError
}
} else {
- mlog.Errf("%s: %s %s: %s", logp, epr.HttpRequest.Method,
- epr.HttpRequest.URL.Path, epr.Error)
+ mlog.Errf(`%s: %s %s: %s`, logp, epr.HTTPRequest.Method,
+ epr.HTTPRequest.URL.Path, epr.Error)
errInternal = liberrors.Internal(epr.Error)
}
- epr.HttpWriter.Header().Set(HeaderContentType, ContentTypeJSON)
- epr.HttpWriter.WriteHeader(errInternal.Code)
+ epr.HTTPWriter.Header().Set(HeaderContentType, ContentTypeJSON)
+ epr.HTTPWriter.WriteHeader(errInternal.Code)
jsonb, err = json.Marshal(errInternal)
if err != nil {
@@ -59,7 +59,7 @@ func DefaultErrorHandler(epr *EndpointRequest) {
return
}
- _, err = epr.HttpWriter.Write(jsonb)
+ _, err = epr.HTTPWriter.Write(jsonb)
if err != nil {
mlog.Errf("%s: Write: %s", logp, err)
}
diff --git a/lib/http/client.go b/lib/http/client.go
index 24d83a9a..9b59fa6d 100644
--- a/lib/http/client.go
+++ b/lib/http/client.go
@@ -25,11 +25,11 @@ import (
"strings"
"time"
- "git.sr.ht/~shulhan/pakakeh.go"
+ pakakeh "git.sr.ht/~shulhan/pakakeh.go"
)
var (
- defUserAgent = `libhttp/` + share.Version
+ defUserAgent = `libhttp/` + pakakeh.Version
)
// Client is a wrapper for standard [http.Client] with simplified
@@ -174,7 +174,7 @@ out:
return res, err
}
-// GenerateHttpRequest generate [http.Request] from method, rpath,
+// GenerateHTTPRequest generate [http.Request] from method, rpath,
// rtype, hdr, and params.
//
// For HTTP method GET, CONNECT, DELETE, HEAD, OPTIONS, or TRACE; the params
@@ -193,9 +193,7 @@ out:
// body.
// - If rtype is [RequestTypeJSON] and params is not nil, the params
// will be encoded as JSON in body.
-//
-//revive:disable-next-line
-func (client *Client) GenerateHttpRequest(
+func (client *Client) GenerateHTTPRequest(
method RequestMethod,
rpath string,
rtype RequestType,
@@ -203,7 +201,7 @@ func (client *Client) GenerateHttpRequest(
params interface{},
) (req *http.Request, err error) {
var (
- logp = "GenerateHttpRequest"
+ logp = `GenerateHTTPRequest`
paramsAsURLValues url.Values
isParamsURLValues bool
paramsAsJSON []byte
@@ -264,7 +262,7 @@ func (client *Client) GenerateHttpRequest(
}
rpath = path.Join(`/`, rpath)
- fullURL := client.opts.ServerUrl + rpath
+ var fullURL = client.opts.ServerURL + rpath
req, err = http.NewRequest(method.String(), fullURL, body)
if err != nil {
@@ -428,7 +426,7 @@ func (client *Client) doRequest(
res *http.Response, resBody []byte, err error,
) {
rpath = path.Join(`/`, rpath)
- fullURL := client.opts.ServerUrl + rpath
+ var fullURL = client.opts.ServerURL + rpath
httpReq, err := http.NewRequest(httpMethod, fullURL, body)
if err != nil {
diff --git a/lib/http/client_options.go b/lib/http/client_options.go
index 8e573d70..b3cd195e 100644
--- a/lib/http/client_options.go
+++ b/lib/http/client_options.go
@@ -17,11 +17,11 @@ type ClientOptions struct {
// This field is optional.
Headers http.Header
- // ServerUrl define the server address without path, for example
+ // ServerURL define the server address without path, for example
// "https://example.com" or "http://10.148.0.12:8080".
// This value should not changed during call of client's method.
// This field is required.
- ServerUrl string //revive:disable-line
+ ServerURL string
// Timeout affect the http Transport Timeout and TLSHandshakeTimeout.
// This field is optional, if not set it will set to 10 seconds.
@@ -40,5 +40,5 @@ func (opts *ClientOptions) init() {
if opts.Timeout <= 0 {
opts.Timeout = defClientTimeout
}
- opts.ServerUrl = strings.TrimSuffix(opts.ServerUrl, `/`)
+ opts.ServerURL = strings.TrimSuffix(opts.ServerURL, `/`)
}
diff --git a/lib/http/client_request.go b/lib/http/client_request.go
index 635c88da..a1a2d7ec 100644
--- a/lib/http/client_request.go
+++ b/lib/http/client_request.go
@@ -76,7 +76,7 @@ func (creq *ClientRequest) toHTTPRequest(client *Client) (httpReq *http.Request,
)
if client != nil {
- path.WriteString(client.opts.ServerUrl)
+ path.WriteString(client.opts.ServerURL)
}
path.WriteString(creq.Path)
paramsAsURLValues, isParamsURLValues = creq.Params.(url.Values)
diff --git a/lib/http/client_test.go b/lib/http/client_test.go
index 6aa82f44..b92b3b11 100644
--- a/lib/http/client_test.go
+++ b/lib/http/client_test.go
@@ -16,7 +16,7 @@ func TestClient_Download(t *testing.T) {
var (
logp = `Download`
clientOpts = ClientOptions{
- ServerUrl: fmt.Sprintf("http://%s", testServer.Options.Address),
+ ServerURL: `http://` + testServer.Options.Address,
}
client = NewClient(&clientOpts)
diff --git a/lib/http/endpoint.go b/lib/http/endpoint.go
index 570529e4..1d8d4699 100644
--- a/lib/http/endpoint.go
+++ b/lib/http/endpoint.go
@@ -77,8 +77,8 @@ func (ep *Endpoint) call(
logp = "Endpoint.call"
epr = &EndpointRequest{
Endpoint: ep,
- HttpWriter: res,
- HttpRequest: req,
+ HTTPWriter: res,
+ HTTPRequest: req,
}
responseBody []byte
e error
diff --git a/lib/http/endpoint_example_test.go b/lib/http/endpoint_example_test.go
index 231421ce..6cf9b515 100644
--- a/lib/http/endpoint_example_test.go
+++ b/lib/http/endpoint_example_test.go
@@ -26,19 +26,19 @@ func ExampleEndpoint_errorHandler() {
RequestType: RequestTypeQuery,
ResponseType: ResponseTypePlain,
Call: func(epr *EndpointRequest) ([]byte, error) {
- return nil, fmt.Errorf(epr.HttpRequest.Form.Get("error"))
+ return nil, fmt.Errorf(epr.HTTPRequest.Form.Get(`error`))
},
ErrorHandler: func(epr *EndpointRequest) {
- epr.HttpWriter.Header().Set(HeaderContentType, ContentTypePlain)
+ epr.HTTPWriter.Header().Set(HeaderContentType, ContentTypePlain)
codeMsg := strings.Split(epr.Error.Error(), ":")
if len(codeMsg) != 2 {
- epr.HttpWriter.WriteHeader(http.StatusInternalServerError)
- _, _ = epr.HttpWriter.Write([]byte(epr.Error.Error()))
+ epr.HTTPWriter.WriteHeader(http.StatusInternalServerError)
+ _, _ = epr.HTTPWriter.Write([]byte(epr.Error.Error()))
} else {
code, _ := strconv.Atoi(codeMsg[0])
- epr.HttpWriter.WriteHeader(code)
- _, _ = epr.HttpWriter.Write([]byte(codeMsg[1]))
+ epr.HTTPWriter.WriteHeader(code)
+ _, _ = epr.HTTPWriter.Write([]byte(codeMsg[1]))
}
},
}
@@ -53,7 +53,7 @@ func ExampleEndpoint_errorHandler() {
time.Sleep(1 * time.Second)
clientOpts := &ClientOptions{
- ServerUrl: "http://" + serverOpts.Address,
+ ServerURL: `http://` + serverOpts.Address,
}
client := NewClient(clientOpts)
diff --git a/lib/http/endpoint_request.go b/lib/http/endpoint_request.go
index 10c52423..668b57c5 100644
--- a/lib/http/endpoint_request.go
+++ b/lib/http/endpoint_request.go
@@ -14,9 +14,9 @@ import "net/http"
//
// The Error field is used by [CallbackErrorHandler].
type EndpointRequest struct {
- HttpWriter http.ResponseWriter //revive:disable-line
+ HTTPWriter http.ResponseWriter
Error error
Endpoint *Endpoint
- HttpRequest *http.Request //revive:disable-line
+ HTTPRequest *http.Request
RequestBody []byte
}
diff --git a/lib/http/endpoint_response_example_test.go b/lib/http/endpoint_response_example_test.go
index 6dad54d4..1fab11a4 100644
--- a/lib/http/endpoint_response_example_test.go
+++ b/lib/http/endpoint_response_example_test.go
@@ -36,7 +36,7 @@ func ExampleEndpointResponse() {
ResponseType: ResponseTypeJSON,
Call: func(epr *EndpointRequest) ([]byte, error) {
res := &EndpointResponse{}
- id := epr.HttpRequest.Form.Get("id")
+ id := epr.HTTPRequest.Form.Get(`id`)
if len(id) == 0 {
res.E.Code = http.StatusBadRequest
res.E.Message = "empty parameter id"
@@ -68,7 +68,7 @@ func ExampleEndpointResponse() {
time.Sleep(1 * time.Second)
clientOpts := &ClientOptions{
- ServerUrl: "http://127.0.0.1:7016",
+ ServerURL: `http://127.0.0.1:7016`,
}
cl := NewClient(clientOpts)
params := url.Values{}
diff --git a/lib/http/example_server_test.go b/lib/http/example_server_test.go
index 2cf897c0..c9575172 100644
--- a/lib/http/example_server_test.go
+++ b/lib/http/example_server_test.go
@@ -53,7 +53,7 @@ func ExampleServer_customHTTPStatusCode() {
Call: func(epr *EndpointRequest) (
resbody []byte, err error,
) {
- epr.HttpWriter.WriteHeader(exp.Status)
+ epr.HTTPWriter.WriteHeader(exp.Status)
return json.Marshal(exp)
},
}
@@ -67,7 +67,7 @@ func ExampleServer_customHTTPStatusCode() {
time.Sleep(1 * time.Second)
clientOpts := &ClientOptions{
- ServerUrl: "http://127.0.0.1:8123",
+ ServerURL: `http://127.0.0.1:8123`,
}
client := NewClient(clientOpts)
diff --git a/lib/http/http.go b/lib/http/http.go
index 535aefb9..838e5106 100644
--- a/lib/http/http.go
+++ b/lib/http/http.go
@@ -304,7 +304,7 @@ const (
HeaderSetCookie = `Set-Cookie`
HeaderUserAgent = `User-Agent`
HeaderXForwardedFor = `X-Forwarded-For` // https://en.wikipedia.org/wiki/X-Forwarded-For
- HeaderXRealIp = `X-Real-Ip` //revive:disable-line
+ HeaderXRealIP = `X-Real-Ip`
)
var (
@@ -322,7 +322,7 @@ var (
// "X-Real-IP" or "X-Forwarded-For", which ever non-empty first.
// If no headers present, use the default address.
func IPAddressOfRequest(headers http.Header, defAddr string) (addr string) {
- addr = headers.Get(HeaderXRealIp)
+ addr = headers.Get(HeaderXRealIP)
if len(addr) == 0 {
addr, _ = ParseXForwardedFor(headers.Get(HeaderXForwardedFor))
if len(addr) == 0 {
diff --git a/lib/http/http_test.go b/lib/http/http_test.go
index 699ee20d..47c03894 100644
--- a/lib/http/http_test.go
+++ b/lib/http/http_test.go
@@ -33,9 +33,9 @@ var (
}
cbPlain = func(epr *EndpointRequest) (resBody []byte, e error) {
- s := fmt.Sprintf("%s\n", epr.HttpRequest.Form)
- s += fmt.Sprintf("%s\n", epr.HttpRequest.PostForm)
- s += fmt.Sprintf("%v\n", epr.HttpRequest.MultipartForm)
+ var s = fmt.Sprintf("%s\n", epr.HTTPRequest.Form)
+ s += fmt.Sprintf("%s\n", epr.HTTPRequest.PostForm)
+ s += fmt.Sprintf("%v\n", epr.HTTPRequest.MultipartForm)
s += string(epr.RequestBody)
return []byte(s), nil
}
@@ -45,7 +45,7 @@ var (
"form": "%s",
"multipartForm": "%v",
"body": %q
-}`, epr.HttpRequest.Form, epr.HttpRequest.MultipartForm, epr.RequestBody)
+}`, epr.HTTPRequest.Form, epr.HTTPRequest.MultipartForm, epr.RequestBody)
return []byte(s), nil
}
)
@@ -153,7 +153,7 @@ func registerEndpoints() {
Path: "/redirect/download",
ResponseType: ResponseTypePlain,
Call: func(epr *EndpointRequest) ([]byte, error) {
- http.Redirect(epr.HttpWriter, epr.HttpRequest, "/download", http.StatusFound)
+ http.Redirect(epr.HTTPWriter, epr.HTTPRequest, `/download`, http.StatusFound)
return nil, nil
},
})
diff --git a/lib/http/server.go b/lib/http/server.go
index 57f9756a..4d9a627f 100644
--- a/lib/http/server.go
+++ b/lib/http/server.go
@@ -337,8 +337,8 @@ func (srv *Server) Stop(wait time.Duration) (err error) {
// with true will be returned.
//
// If the path is directory and does not contains index.html and
-// EnableIndexHtml is true, server will generate list of content for
-// index.html.
+// [ServerOptions.EnableIndexHTML] is true, server will generate list of
+// content for index.html.
func (srv *Server) getFSNode(reqPath string) (node *memfs.Node, isDir bool) {
var (
nodeIndexHTML *memfs.Node
@@ -375,11 +375,11 @@ func (srv *Server) getFSNode(reqPath string) (node *memfs.Node, isDir bool) {
return nodeIndexHTML, true
}
- if !srv.Options.EnableIndexHtml {
+ if !srv.Options.EnableIndexHTML {
return nil, false
}
- node.GenerateIndexHtml()
+ node.GenerateIndexHTML()
}
return node, false
diff --git a/lib/http/server_test.go b/lib/http/server_test.go
index e1d4d3f7..4d573540 100644
--- a/lib/http/server_test.go
+++ b/lib/http/server_test.go
@@ -910,7 +910,7 @@ func TestServer_Options_HandleFS(t *testing.T) {
func TestServer_handleRange(t *testing.T) {
var (
clOpts = &ClientOptions{
- ServerUrl: testServerURL,
+ ServerURL: testServerURL,
}
cl = NewClient(clOpts)
skipHeaders = []string{HeaderDate, HeaderETag}
@@ -986,7 +986,7 @@ func TestServer_handleRange(t *testing.T) {
func TestServer_handleRange_HEAD(t *testing.T) {
var (
clOpts = &ClientOptions{
- ServerUrl: testServerURL,
+ ServerURL: testServerURL,
}
cl = NewClient(clOpts)
@@ -1055,7 +1055,12 @@ func TestServerHandleRangeBig(t *testing.T) {
)
srv = runServerFS(t, serverAddress, tempDir)
- defer srv.Stop(100 * time.Millisecond)
+ defer func() {
+ var errStop = srv.Stop(100 * time.Millisecond)
+ if errStop != nil {
+ log.Fatal(errStop)
+ }
+ }()
var (
tdata *test.Data
@@ -1069,7 +1074,7 @@ func TestServerHandleRangeBig(t *testing.T) {
var (
clOpts = &ClientOptions{
- ServerUrl: `http://` + serverAddress,
+ ServerURL: `http://` + serverAddress,
}
cl *Client
)
diff --git a/lib/http/serveroptions.go b/lib/http/serveroptions.go
index 8b3e0d79..38da8531 100644
--- a/lib/http/serveroptions.go
+++ b/lib/http/serveroptions.go
@@ -53,7 +53,7 @@ type ServerOptions struct {
// exist in the directory.
// The index.html contains the list of files inside the requested
// path.
- EnableIndexHtml bool //revive:disable-line
+ EnableIndexHTML bool
}
func (opts *ServerOptions) init() {
diff --git a/lib/http/sse_conn.go b/lib/http/sse_conn.go
index c5da3e3c..bb3e4f94 100644
--- a/lib/http/sse_conn.go
+++ b/lib/http/sse_conn.go
@@ -25,7 +25,7 @@ type SSECallback func(sse *SSEConn)
// SSEConn define the connection when the SSE request accepted by server.
type SSEConn struct {
- HttpRequest *http.Request //revive:disable-line
+ HTTPRequest *http.Request
bufrw *bufio.ReadWriter
conn net.Conn
@@ -102,7 +102,7 @@ func (ep *SSEConn) workerKeepAlive(interval time.Duration) {
err error
)
- for _ = range ticker.C {
+ for range ticker.C {
err = ep.WriteRaw(emptyMsg)
if err != nil {
// Write failed, probably connection has been
@@ -134,9 +134,18 @@ func (ep *SSEConn) writeData(buf *bytes.Buffer, data string, id *string) {
// handshake write the last HTTP response to indicate the connection is
// accepted.
func (ep *SSEConn) handshake() {
- ep.bufrw.WriteString("HTTP/1.1 200 OK\r\n")
- ep.bufrw.WriteString("content-type: text/event-stream\r\n")
- ep.bufrw.WriteString("cache-control: no-cache\r\n")
- ep.bufrw.WriteString("\r\n")
- ep.bufrw.Flush()
+ var (
+ bb bytes.Buffer
+ err error
+ )
+
+ bb.WriteString("HTTP/1.1 200 OK\r\n")
+ bb.WriteString("content-type: text/event-stream\r\n")
+ bb.WriteString("cache-control: no-cache\r\n")
+ bb.WriteString("\r\n")
+
+ _, err = ep.bufrw.Write(bb.Bytes())
+ if err == nil {
+ ep.bufrw.Flush()
+ }
}
diff --git a/lib/http/sse_endpoint.go b/lib/http/sse_endpoint.go
index e1979985..c1bef50c 100644
--- a/lib/http/sse_endpoint.go
+++ b/lib/http/sse_endpoint.go
@@ -113,7 +113,7 @@ func (ep *SSEEndpoint) hijack(res http.ResponseWriter, req *http.Request) (sseco
}
sseconn = &SSEConn{
- HttpRequest: req,
+ HTTPRequest: req,
}
sseconn.conn, sseconn.bufrw, err = hijack.Hijack()
diff --git a/lib/http/sseclient/sseclient.go b/lib/http/sseclient/sseclient.go
index afc9ed05..04cd1bbf 100644
--- a/lib/http/sseclient/sseclient.go
+++ b/lib/http/sseclient/sseclient.go
@@ -30,7 +30,7 @@ import (
"strings"
"time"
- "git.sr.ht/~shulhan/pakakeh.go"
+ pakakeh "git.sr.ht/~shulhan/pakakeh.go"
libhttp "git.sr.ht/~shulhan/pakakeh.go/lib/http"
libnet "git.sr.ht/~shulhan/pakakeh.go/lib/net"
)
@@ -180,7 +180,7 @@ func (cl *Client) init(header http.Header) (err error) {
cl.header = http.Header{}
}
cl.header.Set(libhttp.HeaderHost, cl.serverURL.Host)
- cl.header.Set(libhttp.HeaderUserAgent, `libhttp/`+share.Version)
+ cl.header.Set(libhttp.HeaderUserAgent, `libhttp/`+pakakeh.Version)
cl.header.Set(libhttp.HeaderAccept, libhttp.ContentTypeEventStream)
if cl.Timeout <= 0 {
@@ -245,6 +245,7 @@ func (cl *Client) handshake() (packet []byte, err error) {
}
func (cl *Client) handshakeRequest() (err error) {
+ var logp = `handshakeRequest`
var buf bytes.Buffer
fmt.Fprintf(&buf, `GET %s`, cl.serverURL.Path)
@@ -281,7 +282,10 @@ func (cl *Client) handshakeRequest() (err error) {
var deadline = time.Now().Add(cl.Timeout)
- cl.conn.SetWriteDeadline(deadline)
+ err = cl.conn.SetWriteDeadline(deadline)
+ if err != nil {
+ return fmt.Errorf(`%s: %w`, logp, err)
+ }
var (
buflen = buf.Len()
diff --git a/lib/http/sseclient/sseclient_test.go b/lib/http/sseclient/sseclient_test.go
index 7467bbf5..0986efbf 100644
--- a/lib/http/sseclient/sseclient_test.go
+++ b/lib/http/sseclient/sseclient_test.go
@@ -6,6 +6,7 @@ package sseclient
import (
"fmt"
+ "log"
"math/rand"
"sync/atomic"
"testing"
@@ -109,7 +110,9 @@ func TestClient(t *testing.T) {
if err != nil {
t.Fatal(`testRunSSEServer:`, err)
}
- t.Cleanup(func() { srv.Stop(1 * time.Second) })
+ t.Cleanup(func() {
+ _ = srv.Stop(1 * time.Second)
+ })
var cl = Client{
Endpoint: fmt.Sprintf(`http://%s/sse`, srv.Options.Address),
@@ -239,7 +242,9 @@ func TestClient_raw(t *testing.T) {
if err != nil {
t.Fatal(`testRunSSEServer:`, err)
}
- t.Cleanup(func() { srv.Stop(1 * time.Second) })
+ t.Cleanup(func() {
+ _ = srv.Stop(1 * time.Second)
+ })
var cl = Client{
Endpoint: fmt.Sprintf(`http://%s/sse`, srv.Options.Address),
@@ -350,7 +355,9 @@ func TestClientRetry(t *testing.T) {
if err != nil {
t.Fatal(`testRunSSEServer:`, err)
}
- t.Cleanup(func() { srv.Stop(1 * time.Second) })
+ t.Cleanup(func() {
+ _ = srv.Stop(1 * time.Second)
+ })
var cl = Client{
Endpoint: fmt.Sprintf(`http://%s/sse`, srv.Options.Address),
@@ -421,7 +428,12 @@ func testRunSSEServer(t *testing.T, cb libhttp.SSECallback) (srv *libhttp.Server
return nil, err
}
- go srv.Start()
+ go func() {
+ var errStart = srv.Start()
+ if errStart != nil {
+ log.Fatal(errStart)
+ }
+ }()
err = libnet.WaitAlive(`tcp`, address, 1*time.Second)
if err != nil {