mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
chore(font): execute HTTP requests with context
This commit is contained in:
parent
47265b1bc1
commit
d678265607
|
@ -4,11 +4,13 @@ package font
|
|||
// component library.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Download(fontPath string) ([]byte, error) {
|
||||
|
@ -35,9 +37,14 @@ func isZipFile(data []byte) bool {
|
|||
}
|
||||
|
||||
func getRemoteFile(location string) (data []byte, err error) {
|
||||
var client = http.Client{}
|
||||
|
||||
resp, err := client.Get(location)
|
||||
client := &http.Client{}
|
||||
ctx, cancelF := context.WithTimeout(context.Background(), time.Second*time.Duration(60))
|
||||
defer cancelF()
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", location, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package font
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type release struct {
|
||||
|
@ -21,7 +23,9 @@ func (a Asset) FilterValue() string { return a.Name }
|
|||
|
||||
func Nerds() ([]*Asset, error) {
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest", nil)
|
||||
ctx, cancelF := context.WithTimeout(context.Background(), time.Second*time.Duration(20))
|
||||
defer cancelF()
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue