Are the brackets after the slice?

I recently began to study, and then through a textbook . In the tutorial there is a line:

p1 := &Page{Title: "TestPage", Body: []byte("This is a sample Page.")}

They have a slice with a given bracket:

[]byte("This is a sample Page.")

However, from all the documents that I read, I did not see parentheses after the fragment. I saw only the format:

b := []byte{'g', 'o', 'l', 'a', 'n', 'g'}

Using curly braces. What is the role of parentheses?

+4
source share
1 answer

From spec;

Converting a string type value to a byte type chunk gives a slice whose subsequent elements are string bytes.

[]byte("hellø")   // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}
[]byte("")        // []byte{}

MyBytes("hellø")  // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}

Check out the full conversion rules here; https://golang.org/ref/spec#Conversions

, , . []byte{'l', 'o', 'l'} , . , , . , constuctor ( ), .

+3

All Articles