mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-16 21:23:44 +08:00
✨ feat: support configuration file (#117)
* ♻️ refactor: move file directory * ♻️ refactor: move file directory * ♻️ refactor: support multiple config methods * 🔥 del: remove unused code * 💩 refactor: Refactor channel management and synchronization * 💄 improve: add channel website * ✨ feat: allow recording 0 consumption
This commit is contained in:
@@ -39,7 +39,7 @@ func proxyFunc(req *http.Request) (*url.URL, error) {
|
||||
func socks5ProxyFunc(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
// 设置TCP超时
|
||||
dialer := &net.Dialer{
|
||||
Timeout: time.Duration(common.ConnectTimeout) * time.Second,
|
||||
Timeout: time.Duration(common.GetOrDefault("CONNECT_TIMEOUT", 5)) * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func socks5ProxyFunc(ctx context.Context, network, addr string) (net.Conn, error
|
||||
|
||||
var HTTPClient *http.Client
|
||||
|
||||
func init() {
|
||||
func InitHttpClient() {
|
||||
trans := &http.Transport{
|
||||
DialContext: socks5ProxyFunc,
|
||||
Proxy: proxyFunc,
|
||||
@@ -74,7 +74,8 @@ func init() {
|
||||
Transport: trans,
|
||||
}
|
||||
|
||||
if common.RelayTimeout != 0 {
|
||||
HTTPClient.Timeout = time.Duration(common.RelayTimeout) * time.Second
|
||||
relayTimeout := common.GetOrDefault("RELAY_TIMEOUT", 600)
|
||||
if relayTimeout != 0 {
|
||||
HTTPClient.Timeout = time.Duration(relayTimeout) * time.Second
|
||||
}
|
||||
}
|
||||
|
||||
15
common/requester/marshaller.go
Normal file
15
common/requester/marshaller.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package requester
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Marshaller interface {
|
||||
Marshal(value any) ([]byte, error)
|
||||
}
|
||||
|
||||
type JSONMarshaller struct{}
|
||||
|
||||
func (jm *JSONMarshaller) Marshal(value any) ([]byte, error) {
|
||||
return json.Marshal(value)
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"one-api/common"
|
||||
)
|
||||
|
||||
type RequestBuilder interface {
|
||||
@@ -13,12 +12,12 @@ type RequestBuilder interface {
|
||||
}
|
||||
|
||||
type HTTPRequestBuilder struct {
|
||||
marshaller common.Marshaller
|
||||
marshaller Marshaller
|
||||
}
|
||||
|
||||
func NewRequestBuilder() *HTTPRequestBuilder {
|
||||
return &HTTPRequestBuilder{
|
||||
marshaller: &common.JSONMarshaller{},
|
||||
marshaller: &JSONMarshaller{},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user