2021-11-25 16:06:02 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package gins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-12-03 23:32:00 +08:00
|
|
|
"github.com/gogf/gf/v2/net/gclient"
|
2021-11-25 16:06:02 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
frameCoreComponentNameHttpClient = "gf.core.component.httpclient"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HttpClient returns an instance of http client with specified name.
|
2021-12-03 23:32:00 +08:00
|
|
|
func HttpClient(name ...interface{}) *gclient.Client {
|
2022-02-14 11:46:20 +08:00
|
|
|
var instanceKey = fmt.Sprintf("%s.%v", frameCoreComponentNameHttpClient, name)
|
2021-11-25 16:06:02 +08:00
|
|
|
return localInstances.GetOrSetFuncLock(instanceKey, func() interface{} {
|
2021-12-03 23:32:00 +08:00
|
|
|
return gclient.New()
|
|
|
|
}).(*gclient.Client)
|
2021-11-25 16:06:02 +08:00
|
|
|
}
|