Change your test package function from :
var secret = []byte(os.Getenv("SECRET"))
func Init() {
fmt.Println(secret)
}
to
func Init() {
var secret = []byte(os.Getenv("SECRET"))
fmt.Println(secret)
}
In the first code snippet, the variable secret is declared outside the Init function, which means it is a package-level variable and can be accessed by any function in the same package. When Init is called, it simply prints the value of secret that was previously assigned outside the function.
In the second code snippet, the variable secret is declared inside the Init function, which means it is a local variable and can only be accessed within the Init function itself. When Init is called, it assigns the value of os.Getenv("SECRET")
to the secret variable and then prints it.
So, the main difference between these two code snippets is the scope of the secret variable. If you only need to use secret within the Init function, it's better to declare it inside the function to avoid cluttering the package-level scope with unnecessary variables. On the other hand, if you need to use secret in multiple functions within the same package, it may make sense to declare it as a package-level variable.
Output
: [83 84 65 67 75 79 86 69 82 70 76 79 87]