Star parameter - beginner

(Savio Barros) #1

Hi everyone,
What is the star symbol (*) that appears before some func parameters? Ex.: request *http.Request

Kind regards


(Pritesh Ugrankar) #2

I’m a beginner too. All that I know as of now is that it’s a pointer. So it accesses the value at the address (memory location) of the variable.

For example:
a := 10
b := &a
Then you can print the value of a by either saying
fmt.Printf("%v\n", a)
Or you can say
fmt.Printf("%v\n", *b)
But if you type
fmt.Printf("%v\n", b) (note the missing * before b)
You’ll get the memory address of variable a.
So in your case, I think the variable “request” is set to access the value pointed to by the http.Request.

(Savio Barros) #3

Hi Pritesh,
Thanks for replying!