mirror of
https://github.com/nikdoof/hg612-exporter.git
synced 2025-12-13 18:22:15 +00:00
fix: add context-based timeout to HTTP GET
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package hg612
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const DSLPath = "html/status/xdslStatus.asp"
|
||||
@@ -55,7 +58,9 @@ type DSLStats struct {
|
||||
}
|
||||
|
||||
func (c HG612Client) DSLStatus() (*VDSLStatus, error) {
|
||||
request, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", c.basePath, DSLPath), nil)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/%s", c.basePath, DSLPath), nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error creating dsl status request")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user