consts_gen_ctrl_template_sdk.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright GoFrame gf 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 consts
  7. const TemplateGenCtrlSdkPkgNew = `
  8. // =================================================================================
  9. // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
  10. // =================================================================================
  11. package {PkgName}
  12. import (
  13. "fmt"
  14. "github.com/gogf/gf/contrib/sdk/httpclient/v2"
  15. "github.com/gogf/gf/v2/frame/g"
  16. "github.com/gogf/gf/v2/text/gstr"
  17. )
  18. type implementer struct {
  19. config httpclient.Config
  20. }
  21. func New(config httpclient.Config) iClient {
  22. if !gstr.HasPrefix(config.URL, "http") {
  23. config.URL = fmt.Sprintf("http://%s", config.URL)
  24. }
  25. if config.Logger == nil {
  26. config.Logger = g.Log()
  27. }
  28. return &implementer{
  29. config: config,
  30. }
  31. }
  32. `
  33. const TemplateGenCtrlSdkIClient = `
  34. // =================================================================================
  35. // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
  36. // =================================================================================
  37. package {PkgName}
  38. import (
  39. )
  40. type iClient interface {
  41. }
  42. `
  43. const TemplateGenCtrlSdkImplementer = `
  44. // =================================================================================
  45. // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
  46. // =================================================================================
  47. package {PkgName}
  48. import (
  49. "context"
  50. "github.com/gogf/gf/contrib/sdk/httpclient/v2"
  51. "github.com/gogf/gf/v2/text/gstr"
  52. {ImportPaths}
  53. )
  54. type implementer{ImplementerName} struct {
  55. *httpclient.Client
  56. }
  57. `
  58. const TemplateGenCtrlSdkImplementerNew = `
  59. func (i *implementer) {ImplementerName}() {Module}.I{ImplementerName} {
  60. var (
  61. client = httpclient.New(i.config)
  62. prefix = gstr.TrimRight(i.config.URL, "/") + "{VersionPrefix}"
  63. )
  64. client.Client = client.Prefix(prefix)
  65. return &implementer{ImplementerName}{client}
  66. }
  67. `
  68. const TemplateGenCtrlSdkImplementerFunc = `
  69. func (i *implementer{ImplementerName}) {MethodName}(ctx context.Context, req *{Version}.{MethodName}Req) (res *{Version}.{MethodName}Res, err error) {
  70. err = i.Request(ctx, req, &res)
  71. return
  72. }
  73. `