This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Go · Archive · Week 5 · Jan 26 – Feb 1, 2026

go/scanner: add (*Scanner).End()

Worth knowingstdlib

What changed
The go/scanner package now has an End() method that returns the position immediately after the last scanned token, or token.NoPos if Scan has not been called.
Production impact
The source does not say.
Try it
Initialize a scanner.Scanner, call Scan() a few times, then call s.End() to get the end position.
Source
github.com/golang/go/issues/74958

Understand it, then run it

Run it now

Todaygo
// This program demonstrates the new (*Scanner).End() method.
// It scans a simple Go source string and prints the position after the last token.
package main

import (
	"fmt"
	"go/scanner"
	"go/token"
)

func main() {
	src := []byte("package main\nfunc main() {}")
	fset := token.NewFileSet()
	file := fset.AddFile("", fset.Base(), len(src))

	var s scanner.Scanner
	s.Init(file, src, nil, scanner.ScanComments)

	// Scan all tokens.
	for {
		pos, tok, lit := s.Scan()
		if tok == token.EOF {
			break
		}
		fmt.Printf("token: %s, pos: %v, lit: %q\n", tok, pos, lit)
	}

	// After scanning, End() gives the position after the last token.
	endPos := s.End()
	fmt.Printf("End position: %v (offset %d)\n", endPos, file.Offset(endPos))
}

What it printed when we ran it on Go 1.27.1

token: package, pos: 1, lit: "package"
token: IDENT, pos: 9, lit: "main"
token: ;, pos: 13, lit: "\n"
token: func, pos: 14, lit: "func"
token: IDENT, pos: 19, lit: "main"
token: (, pos: 23, lit: ""
token: ), pos: 24, lit: ""
token: {, pos: 26, lit: ""
token: }, pos: 27, lit: ""
token: ;, pos: 28, lit: "\n"
End position: 28 (offset 27)

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed