@@ -165,6 +165,45 @@ func GetCallInfo(n ast.Node, ctx *Context) (string, string, error) {
165
165
return "" , "" , fmt .Errorf ("unable to determine call info" )
166
166
}
167
167
168
+ // GetCallStringArgsValues returns the values of strings arguments if they can be resolved
169
+ func GetCallStringArgsValues (n ast.Node , ctx * Context ) []string {
170
+ values := []string {}
171
+ switch node := n .(type ) {
172
+ case * ast.CallExpr :
173
+ for _ , arg := range node .Args {
174
+ switch param := arg .(type ) {
175
+ case * ast.BasicLit :
176
+ value , err := GetString (param )
177
+ if err == nil {
178
+ values = append (values , value )
179
+ }
180
+ case * ast.Ident :
181
+ obj := param .Obj
182
+ if obj != nil {
183
+ switch decl := obj .Decl .(type ) {
184
+ case * ast.ValueSpec :
185
+ for _ , v := range decl .Values {
186
+ value , err := GetString (v )
187
+ if err == nil {
188
+ values = append (values , value )
189
+ }
190
+ }
191
+ case * ast.AssignStmt :
192
+ for _ , v := range decl .Rhs {
193
+ value , err := GetString (v )
194
+ if err == nil {
195
+ values = append (values , value )
196
+ }
197
+ }
198
+ }
199
+
200
+ }
201
+ }
202
+ }
203
+ }
204
+ return values
205
+ }
206
+
168
207
// GetImportedName returns the name used for the package within the
169
208
// code. It will resolve aliases and ignores initialization only imports.
170
209
func GetImportedName (path string , ctx * Context ) (string , bool ) {
0 commit comments