@@ -40,7 +40,7 @@ type Client struct {
4040func NewClient (opts ... ClientOption ) * Client {
4141 client := & Client {
4242 httpClient : & http.Client {
43- Timeout : 30 * time .Second ,
43+ Timeout : 60 * time .Second , // Increased timeout to 60 seconds
4444 },
4545 baseURL : BaseURL ,
4646 }
@@ -111,11 +111,11 @@ type Range struct {
111111
112112// Affected represents a package affected by a vulnerability
113113type Affected struct {
114- Package Package `json:"package"`
115- Ranges []Range `json:"ranges,omitempty"`
116- Versions []string `json:"versions,omitempty"`
117- EcosystemSpecific map [string ]string `json:"ecosystem_specific,omitempty"`
118- DatabaseSpecific map [string ]string `json:"database_specific,omitempty"`
114+ Package Package `json:"package"`
115+ Ranges []Range `json:"ranges,omitempty"`
116+ Versions []string `json:"versions,omitempty"`
117+ EcosystemSpecific map [string ]interface {} `json:"ecosystem_specific,omitempty"`
118+ DatabaseSpecific map [string ]interface {} `json:"database_specific,omitempty"`
119119}
120120
121121// Vulnerability represents a vulnerability in the OSV API
@@ -159,7 +159,11 @@ func (c *Client) Query(ctx context.Context, req QueryRequest) (*QueryResponse, e
159159 return nil , fmt .Errorf ("failed to marshal request: %w" , err )
160160 }
161161
162- httpReq , err := http .NewRequestWithContext (ctx , http .MethodPost , url , bytes .NewReader (reqBody ))
162+ // Create a new context with a 30-second timeout
163+ reqCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
164+ defer cancel ()
165+
166+ httpReq , err := http .NewRequestWithContext (reqCtx , http .MethodPost , url , bytes .NewReader (reqBody ))
163167 if err != nil {
164168 return nil , fmt .Errorf ("failed to create request: %w" , err )
165169 }
@@ -198,7 +202,11 @@ func (c *Client) QueryBatch(ctx context.Context, req QueryBatchRequest) (*QueryB
198202 return nil , fmt .Errorf ("failed to marshal request: %w" , err )
199203 }
200204
201- httpReq , err := http .NewRequestWithContext (ctx , http .MethodPost , url , bytes .NewReader (reqBody ))
205+ // Create a new context with a 30-second timeout
206+ reqCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
207+ defer cancel ()
208+
209+ httpReq , err := http .NewRequestWithContext (reqCtx , http .MethodPost , url , bytes .NewReader (reqBody ))
202210 if err != nil {
203211 return nil , fmt .Errorf ("failed to create request: %w" , err )
204212 }
@@ -232,7 +240,11 @@ func (c *Client) QueryBatch(ctx context.Context, req QueryBatchRequest) (*QueryB
232240func (c * Client ) GetVulnerability (ctx context.Context , id string ) (* Vulnerability , error ) {
233241 url := fmt .Sprintf ("%s%s/%s" , c .baseURL , VulnEndpoint , id )
234242
235- httpReq , err := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
243+ // Create a new context with a 30-second timeout
244+ reqCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
245+ defer cancel ()
246+
247+ httpReq , err := http .NewRequestWithContext (reqCtx , http .MethodGet , url , nil )
236248 if err != nil {
237249 return nil , fmt .Errorf ("failed to create request: %w" , err )
238250 }
0 commit comments