[go] how can i pass a variable to another function

Sorry for noob question…

I have global variable

proxy []string

and func

func check(pr proxy??) { // how do I correctly specify a global variable so that it is passed to the function

var proxystr = strings.Split(":", proxy)


how can i pass a variable proxy to check function?

Hi. Alll global variables is available everywhere in the same package. The exception is if they are shadowed by a local variable with the same name. If a global variable is exported, begins with capital letter is it also visible in all packages importing the package.


Hi, thanks for answer .But how can I pass not the value of a variable but the variable itself? This is my difficulty (

You do not need to pass the variable, you can just use it.

1 Like

Links below are two different examples of what you are looking to do. The first one will be if you are looking to pass in the slice into a function. The second one is if you are building structs and assigning the function as a method.

Either way, I would try to follow an excellent restricted variable scope to prevent code confusion and overlap. Good luck.

Passing in the variable:

Using a struck and method solution:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.