gins_httpclient.go 732 B

12345678910111213141516171819202122232425
  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/net/gclient"
  10. )
  11. const (
  12. frameCoreComponentNameHttpClient = "gf.core.component.httpclient"
  13. )
  14. // HttpClient returns an instance of http client with specified name.
  15. func HttpClient(name ...interface{}) *gclient.Client {
  16. var instanceKey = fmt.Sprintf("%s.%v", frameCoreComponentNameHttpClient, name)
  17. return localInstances.GetOrSetFuncLock(instanceKey, func() interface{} {
  18. return gclient.New()
  19. }).(*gclient.Client)
  20. }