Standard library / go/token

go/token.IsKeyword()

Checks whether a string is a reserved Go keyword. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func IsKeyword(name string) bool

Parameters & Attributes

NameTypeDescription
namestringIdentifier spelling to classify.

Return Value

bool

Checks whether a string is a reserved Go keyword.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/token")
func main() { fmt.Println(token.IsKeyword("return"), token.IsKeyword("len")) }
Go Reference