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
|
package hg612
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DSLPath = "html/status/xdslStatus.asp"
|
const DSLPath = "html/status/xdslStatus.asp"
|
||||||
@@ -55,7 +58,9 @@ type DSLStats struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c HG612Client) DSLStatus() (*VDSLStatus, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error creating dsl status request")
|
return nil, errors.Wrap(err, "error creating dsl status request")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user