Movatterモバイル変換


[0]ホーム

URL:


godebug

packagestandard library
go1.25.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:5Imported by:0

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package godebug makes the settings in the $GODEBUG environment variableavailable to other packages. These settings are often used for compatibilitytweaks, when we need to change a default behavior but want to let usersopt back in to the original. For example GODEBUG=http2server=0 disablesHTTP/2 support in the net/http server.

In typical usage, code should declare a Setting as a globaland then call Value each time the current setting value is needed:

var http2server = godebug.New("http2server")func ServeConn(c net.Conn) {if http2server.Value() == "0" {disallow HTTP/2...}...}

Each time a non-default setting causes a change in program behavior,code must callSetting.IncNonDefault to increment a counter that canbe reported byruntime/metrics.Read. The call must only happen whenthe program executes a non-default behavior, not just when the settingis set to a non-default value. This is occasionally (but very rarely)infeasible, in which case the internal/godebugs table entry must setOpaque: true, and the documentation in doc/godebug.md shouldmention that metrics are unavailable.

Conventionally, the global variable representing a godebug is namedfor the godebug itself, with no case changes:

var gotypesalias = godebug.New("gotypesalias") // thisvar goTypesAlias = godebug.New("gotypesalias") // NOT THIS

The test in internal/godebugs that checks for use of IncNonDefaultrequires the use of this convention.

Note that counters used with IncNonDefault must be added tovarious tables in other packages. See theSetting.IncNonDefaultdocumentation for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

typeSettingadded ingo1.20

type Setting struct {// contains filtered or unexported fields}

A Setting is a single setting in the $GODEBUG environment variable.

funcNewadded ingo1.20

func New(namestring) *Setting

New returns a new Setting for the $GODEBUG setting with the given name.

GODEBUGs meant for use by end users must be listed in ../godebugs/table.go,which is used for generating and checking various documentation.If the name is not listed in that table, New will succeed but calling Valueon the returned Setting will panic.To disable that panic for access to an undocumented setting,prefix the name with a #, as in godebug.New("#gofsystrace").The # is a signal to New but not part of the key used in $GODEBUG.

Note that almost all settings should arrange to call [IncNonDefault] preciselywhen program behavior is changing from the default due to the setting(not just when the setting is different, but when program behavior changes).See theinternal/godebug package comment for more.

func (*Setting)IncNonDefaultadded ingo1.21.0

func (s *Setting) IncNonDefault()

IncNonDefault increments the non-default behavior counterassociated with the given setting.This counter is exposed in the runtime/metrics value/godebug/non-default-behavior/<name>:events.

Note that Value must be called at least once before IncNonDefault.

func (*Setting)Nameadded ingo1.20

func (s *Setting) Name()string

Name returns the name of the setting.

func (*Setting)Stringadded ingo1.20

func (s *Setting) String()string

String returns a printable form for the setting: name=value.

func (*Setting)Undocumentedadded ingo1.21.0

func (s *Setting) Undocumented()bool

Undocumented reports whether this is an undocumented setting.

func (*Setting)Valueadded ingo1.20

func (s *Setting) Value()string

Value returns the current value for the GODEBUG setting s.

Value maintains an internal cache that is synchronizedwith changes to the $GODEBUG environment variable,making Value efficient to call as frequently as needed.Clients should therefore typically not attempt their owncaching of Value's result.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp