literal
just means the grammar or the way to compose source code, i.e., construct a value of a certain type following the literal meaning of its source code.
int/string literal
happens to construct a constant value that is the same as the literal meaning of the source code.
from go spec
Composite literals construct new composite values each time they are evaluated.
from their definition, it's syntactic sugar to construct value for the composite type. It's not the fixed value referred by literal wiki page.
cited from gopl 4.4.1 for struct literal
:
A value of a struct type can be written using a struct literal that specifies values for its fields.
type Point struct{ X, Y int }
p := Point{1, 2}
Both string literals
and struct literals
are source codes to guide the compiler to construct value in memory. struct literals
can be non-constant at compile time, i.e., only known at runtime.
there's also another type of literal: type literal:
A type may also be specified using a type literal, which composes a type from existing types.
which just means a fixed value in the source code for the type system.
struct{}
struct{ foo int32 }