mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 04:50:14 +09:00
feat: support max timeout env (#175)
Co-Authored-By: Minghan Zhang <112773885+zmh-program@users.noreply.github.com>
This commit is contained in:
parent
3dffa7fdab
commit
afb13dd545
@ -3,6 +3,7 @@ package globals
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -10,6 +11,8 @@ import (
|
||||
const ChatMaxThread = 5
|
||||
const AnonymousMaxThread = 1
|
||||
|
||||
var HttpMaxTimeout = 30 * time.Minute
|
||||
|
||||
var AllowedOrigins []string
|
||||
|
||||
var DebugMode bool
|
||||
|
@ -3,10 +3,12 @@ package utils
|
||||
import (
|
||||
"chat/globals"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/viper"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var configFile = "config/config.yaml"
|
||||
@ -34,6 +36,11 @@ func ReadConf() {
|
||||
|
||||
viper.AutomaticEnv()
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
|
||||
if timeout := viper.GetInt("max_timeout"); timeout > 0 {
|
||||
globals.HttpMaxTimeout = time.Second * time.Duration(timeout)
|
||||
globals.Debug(fmt.Sprintf("[service] http client timeout set to %ds from env", timeout))
|
||||
}
|
||||
}
|
||||
|
||||
func NewEngine() *gin.Engine {
|
||||
|
10
utils/net.go
10
utils/net.go
@ -6,22 +6,20 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/goccy/go-json"
|
||||
"golang.org/x/net/proxy"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var maxTimeout = 30 * time.Minute
|
||||
"github.com/goccy/go-json"
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
|
||||
func newClient(c []globals.ProxyConfig) *http.Client {
|
||||
client := &http.Client{
|
||||
Timeout: maxTimeout,
|
||||
Timeout: globals.HttpMaxTimeout,
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user