File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "os"
66 "path/filepath"
77 "strings"
8+ "sync"
89
910 "github.com/hashicorp/go-version"
1011 "github.com/spf13/pflag"
@@ -262,23 +263,27 @@ func (c *Config) SwaggerDir() string {
262263 return filepath .Join ("desc" , "swagger" )
263264}
264265
265- func (c * Config ) GoctlVersion () * version.Version {
266- goctlVersionResp , err := execx .Run ("goctl -v" , "" )
267- if err != nil {
268- panic (err )
269- }
266+ var (
267+ once sync.Once
268+ goctlVersion * version.Version
269+ )
270270
271- logx .Debugf ("goctl version: %s" , goctlVersionResp )
272- versionInfo := strings .Split (goctlVersionResp , " " )
273- var goctlVersion * version.Version
274- if len (versionInfo ) >= 3 {
275- goctlVersion , err = version .NewVersion (versionInfo [2 ])
271+ func (c * Config ) GoctlVersion () * version.Version {
272+ once .Do (func () {
273+ goctlVersionResp , err := execx .Run ("goctl -v" , "" )
276274 if err != nil {
277275 panic (err )
278276 }
279- } else {
280- panic ("unknown goctl version" )
281- }
277+
278+ logx .Debugf ("goctl version: %s" , goctlVersionResp )
279+ versionInfo := strings .Split (goctlVersionResp , " " )
280+ if len (versionInfo ) >= 3 {
281+ goctlVersion , err = version .NewVersion (versionInfo [2 ])
282+ if err != nil {
283+ panic (err )
284+ }
285+ }
286+ })
282287
283288 return goctlVersion
284289}
You can’t perform that action at this time.
0 commit comments