Browse Source

增加工具函数

pull/47/head
Sydonian 1 year ago
parent
commit
5334f543e9
2 changed files with 8 additions and 11 deletions
  1. +1
    -11
      utils/http/http.go
  2. +7
    -0
      utils/lo2/lo.go

+ 1
- 11
utils/http/http.go View File

@@ -6,13 +6,11 @@ import (
"io" "io"
"mime" "mime"
"mime/multipart" "mime/multipart"
"net"
"net/http" "net/http"
"net/textproto" "net/textproto"
ul "net/url" ul "net/url"
"reflect" "reflect"
"strings" "strings"
"time"


"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"gitlink.org.cn/cloudream/common/pkgs/iterator" "gitlink.org.cn/cloudream/common/pkgs/iterator"
@@ -28,15 +26,7 @@ const (
ContentTypeOctetStream = "application/octet-stream" ContentTypeOctetStream = "application/octet-stream"
) )


var defaultClient = http.Client{
Timeout: time.Second * 5,
Transport: &http.Transport{
DialContext: (&net.Dialer{
Timeout: time.Second * 5,
KeepAlive: 0, // 修改为 0 可以生效
}).DialContext,
},
}
var defaultClient = http.DefaultClient


type RequestParam struct { type RequestParam struct {
Header any Header any


+ 7
- 0
utils/lo2/lo.go View File

@@ -22,3 +22,10 @@ func RemoveAt[T any](arr []T, index int) []T {
func ArrayClone[T any](arr []T) []T { func ArrayClone[T any](arr []T) []T {
return append([]T{}, arr...) return append([]T{}, arr...)
} }

func Insert[T any](arr []T, index int, item T) []T {
arr = append(arr, item)
copy(arr[index+1:], arr[index:])
arr[index] = item
return arr
}

Loading…
Cancel
Save