How to shorten this code
access_log, err := os.OpenFile("log/access.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660);
w.access_log = access_log
To something like this
w.access_log, err := os.OpenFile("log/access.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660);
You need to assign (=
), not declare (:=
):
var error
w.access_log, err = os.OpenFile("log/access.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660);
:=
is for Short Variable declaration, and w.access_log
is already declared (in w
struct)
It is discussed in issue 6842.