mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-15 13:17:53 -08:00
parent
7d5a6b881e
commit
edf93c3883
|
@ -6,6 +6,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
)
|
)
|
||||||
|
|
||||||
type codePoints map[int]int
|
type codePoints map[int]int
|
||||||
|
@ -13,7 +15,6 @@ type codePoints map[int]int
|
||||||
func getGlyphCodePoints() (codePoints, error) {
|
func getGlyphCodePoints() (codePoints, error) {
|
||||||
var codePoints = make(codePoints)
|
var codePoints = make(codePoints)
|
||||||
|
|
||||||
client := &http.Client{}
|
|
||||||
ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(5000))
|
ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(5000))
|
||||||
defer cncl()
|
defer cncl()
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ func getGlyphCodePoints() (codePoints, error) {
|
||||||
return codePoints, &ConnectionError{reason: err.Error()}
|
return codePoints, &ConnectionError{reason: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := client.Do(request)
|
response, err := platform.Client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return codePoints, err
|
return codePoints, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Download(fontPath string) ([]byte, error) {
|
func Download(fontPath string) ([]byte, error) {
|
||||||
|
@ -38,20 +38,11 @@ func isZipFile(data []byte) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRemoteFile(location string) (data []byte, err error) {
|
func getRemoteFile(location string) (data []byte, err error) {
|
||||||
client := &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
Dial: (&net.Dialer{
|
|
||||||
Timeout: 10 * time.Second,
|
|
||||||
}).Dial,
|
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
|
||||||
ResponseHeaderTimeout: 10 * time.Second,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
req, err := http.NewRequestWithContext(context.Background(), "GET", location, nil)
|
req, err := http.NewRequestWithContext(context.Background(), "GET", location, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp, err := client.Do(req)
|
resp, err := platform.Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
)
|
)
|
||||||
|
|
||||||
type release struct {
|
type release struct {
|
||||||
|
@ -22,7 +24,6 @@ type Asset struct {
|
||||||
func (a Asset) FilterValue() string { return a.Name }
|
func (a Asset) FilterValue() string { return a.Name }
|
||||||
|
|
||||||
func Nerds() ([]*Asset, error) {
|
func Nerds() ([]*Asset, error) {
|
||||||
client := &http.Client{}
|
|
||||||
ctx, cancelF := context.WithTimeout(context.Background(), time.Second*time.Duration(20))
|
ctx, cancelF := context.WithTimeout(context.Background(), time.Second*time.Duration(20))
|
||||||
defer cancelF()
|
defer cancelF()
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest", nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest", nil)
|
||||||
|
@ -30,7 +31,7 @@ func Nerds() ([]*Asset, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Add("Accept", "application/vnd.github.v3+json")
|
req.Header.Add("Accept", "application/vnd.github.v3+json")
|
||||||
response, err := client.Do(req)
|
response, err := platform.Client.Do(req)
|
||||||
if err != nil || response.StatusCode != http.StatusOK {
|
if err != nil || response.StatusCode != http.StatusOK {
|
||||||
return nil, errors.New("failed to get nerd fonts release")
|
return nil, errors.New("failed to get nerd fonts release")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Inspired by: https://www.thegreatcodeadventure.com/mocking-http-requests-in-golang/
|
// Inspired by: https://www.thegreatcodeadventure.com/mocking-http-requests-in-golang/
|
||||||
|
@ -11,5 +13,13 @@ type httpClient interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
client httpClient = &http.Client{}
|
defaultTransport http.RoundTripper = &http.Transport{
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
Dial: (&net.Dialer{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
}).Dial,
|
||||||
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
|
ResponseHeaderTimeout: 10 * time.Second,
|
||||||
|
}
|
||||||
|
Client httpClient = &http.Client{Transport: defaultTransport}
|
||||||
)
|
)
|
||||||
|
|
|
@ -688,7 +688,7 @@ func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, req
|
||||||
dump, _ := httputil.DumpRequestOut(request, true)
|
dump, _ := httputil.DumpRequestOut(request, true)
|
||||||
env.Debug(string(dump))
|
env.Debug(string(dump))
|
||||||
}
|
}
|
||||||
response, err := client.Do(request)
|
response, err := Client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
env.Error(err)
|
env.Error(err)
|
||||||
return nil, env.unWrapError(err)
|
return nil, env.unWrapError(err)
|
||||||
|
|
Loading…
Reference in a new issue