OWASP / Go-SCP

Golang Secure Coding Practices guide

Home Page:https://owasp.org/www-project-go-secure-coding-practices-guide/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"init(i int)" is invalid

tebeka opened this issue · comments

In "Error Handling" there's the following example:

func init(i int) {
        ...
	//This is just to deliberately crash the function.
	if i < 2 {
		fmt.Printf("Var %d - initialized\n", i)
	} else {
		//This was never supposed to happen, so we'll terminate our program.
		log.Fatal("Init failure - Terminating.")
	}
}

This code won't compile, the error is:
func init must have no arguments and no return values

Rename it to initialize?

Hi @tebeka,
You're right, because init is a reserved function.

I do agree renaming it initialize.
Would you like to open a Pull Request? I would love to accept it.

BTW, main function is missing the }: can you please fix that as well? ;)

Cheers,
Paulo A. Silva

Done in #80