gins_httpclient.go 691 B

12345678910111213141516171819202122
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gins
  7. import (
  8. "fmt"
  9. "github.com/gogf/gf/v2/internal/instance"
  10. "github.com/gogf/gf/v2/net/gclient"
  11. )
  12. // HttpClient returns an instance of http client with specified name.
  13. func HttpClient(name ...interface{}) *gclient.Client {
  14. var instanceKey = fmt.Sprintf("%s.%v", frameCoreComponentNameHttpClient, name)
  15. return instance.GetOrSetFuncLock(instanceKey, func() interface{} {
  16. return gclient.New()
  17. }).(*gclient.Client)
  18. }