github.com/sandwich-go/boost@v1.3.29/xdebug/internal/template2/dependency_template.go (about) 1 package template2 2 3 import "sort" 4 5 type DependencyConfig struct { 6 Name string 7 Path string 8 RequireVersion string 9 WarnString string 10 } 11 12 func GetDependencyTPLArgs() interface{} { 13 var dependencyConfigs = make([]DependencyConfig, 0) 14 dependencyConfigs = append(dependencyConfigs, DependencyConfig{ 15 Name: "automaxprocs", 16 Path: "go.uber.org/automaxprocs", 17 RequireVersion: "v1.5.1", 18 WarnString: "fmt.Sprintf(`for the best performance, please blank import the package '%s@%s'`, d.GetPath(), d.GetRequireVersion())", 19 }) 20 sort.Slice(dependencyConfigs, func(i, j int) bool { 21 return dependencyConfigs[i].Name < dependencyConfigs[j].Name 22 }) 23 return map[string]interface{}{"DependencyConfigs": dependencyConfigs} 24 } 25 26 const DependencyTPL = `// Code generated by tools. DO NOT EDIT. 27 package xdebug 28 29 import "fmt" 30 31 func init() { 32 {{- range $dependencyConfig := .DependencyConfigs }} 33 registerDependency({{ $dependencyConfig.Name }}{}) 34 {{- end }} 35 } 36 37 {{ range $dependencyConfig := .DependencyConfigs }} 38 type {{ $dependencyConfig.Name }} struct{} 39 40 func (d {{ $dependencyConfig.Name }}) GetPath() string { return "{{ $dependencyConfig.Path }}" } 41 func (d {{ $dependencyConfig.Name }}) GetRequireVersion() string { return "{{ $dependencyConfig.RequireVersion }}" } 42 func (d {{ $dependencyConfig.Name }}) WarnString() string { return {{ $dependencyConfig.WarnString | Unescaped }}} 43 {{ end }} 44 `