@@ -599,6 +599,7 @@ func (g *Generator) generate(typeName string) {
599599 g .importPackage ("encoding/json" )
600600 g .importPackage ("regexp" )
601601 g .importPackage ("reflect" )
602+ g .importPackage ("sync" )
602603
603604 if g .apiClientField != nil && (* apiUrlStr != "" || * useDynamicPath ) {
604605 g .importPackage ("net/url" )
@@ -1220,9 +1221,21 @@ func ({{- $recv }} * {{- typeString .StructType -}} ) GetSlugParameters() (map[s
12201221 return params, nil
12211222}
12221223
1224+ var {{ typeString .StructType }}SlugReCache sync.Map
1225+
1226+ {{- $slugReCache := print (typeString .StructType) "SlugReCache" }}
1227+
12231228func ({{- $recv }} * {{- typeString .StructType -}} ) applySlugsToUrl(url string, slugs map[string]string) string {
12241229 for _k, _v := range slugs {
1225- needleRE := regexp.MustCompile(":" + _k + "\\b")
1230+ var needleRE *regexp.Regexp
1231+
1232+ if cached, ok := {{ $slugReCache }}.Load(_k) ; ok {
1233+ needleRE = cached.(*regexp.Regexp)
1234+ } else {
1235+ needleRE = regexp.MustCompile(":" + _k + "\\b")
1236+ {{ $slugReCache }}.Store(_k, needleRE)
1237+ }
1238+
12261239 url = needleRE.ReplaceAllString(url, _v)
12271240 }
12281241
@@ -1562,6 +1575,10 @@ func locateObject(ts *requestgen.TypeSelector, selectedPkgs []*packages.Package)
15621575 log .Debugf ("found response type def: %+v -> %+v type:%+v import:%s" , ident .Name , obj , obj .Type (), obj .Pkg ().Path ())
15631576 return obj , nil
15641577
1578+ case * types.Alias :
1579+ log .Debugf ("found alias type: %+v" , t )
1580+ return obj , nil
1581+
15651582 case * types.Struct :
15661583 log .Infof ("found struct type: %+v" , t )
15671584 log .Debugf ("found response type def: %+v -> %+v type:%+v import:%s" , ident .Name , obj , obj .Type (), obj .Pkg ().Path ())
0 commit comments