go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why lock udBeforeRequestLock and udBeforeRequestLock in execute

valiner opened this issue · comments

func (c *Client) execute(req *Request) (*Response, error) {
	// Lock the user-defined pre-request hooks.
	c.udBeforeRequestLock.RLock()
	defer c.udBeforeRequestLock.RUnlock()

	// Lock the post-request hooks.
	c.afterResponseLock.RLock()
	defer c.afterResponseLock.RUnlock()

This looks very inefficient.

func (c *Client) OnAfterResponse(m ResponseMiddleware) *Client {
	c.afterResponseLock.Lock()
	defer c.afterResponseLock.Unlock()

	c.afterResponse = append(c.afterResponse, m)

	return c
}

OnAfterResponse is generally not used in http execute.

@valiner This PR would provide an insight #597

@valiner Also if you have a suggestion to improve, please mention it.