mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 13:57:26 -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.
|
// component library.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Download(fontPath string) ([]byte, error) {
|
func Download(fontPath string) ([]byte, error) {
|
||||||
|
@ -35,9 +37,14 @@ func isZipFile(data []byte) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRemoteFile(location string) (data []byte, err error) {
|
func getRemoteFile(location string) (data []byte, err error) {
|
||||||
var client = http.Client{}
|
client := &http.Client{}
|
||||||
|
ctx, cancelF := context.WithTimeout(context.Background(), time.Second*time.Duration(60))
|
||||||
resp, err := client.Get(location)
|
defer cancelF()
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "GET", location, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package font
|
package font
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type release struct {
|
type release struct {
|
||||||
|
@ -21,7 +23,9 @@ func (a Asset) FilterValue() string { return a.Name }
|
||||||
|
|
||||||
func Nerds() ([]*Asset, error) {
|
func Nerds() ([]*Asset, error) {
|
||||||
client := &http.Client{}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue