84,685 matches across 25 files for func main
snippet_mode: auto · sorted by relevance
5// Package testing provides support for automated testing of Go packages.
6// It is intended to be used in concert with the "go test" command, which automates
7▶// execution of any function of the form
8//
9// func TestXxx(*testing.T)
· · ·
9▶// func TestXxx(*testing.T)
10//
11// where Xxx does not start with a lowercase letter. The function name
· · ·
11▶// where Xxx does not start with a lowercase letter. The function name
12// serves to identify the test routine.
13//
· · ·
14▶// Within these functions, use [T.Error], [T.Fail] or related methods to signal failure.
15//
16// To write a new test suite, create a file that
· · ·
17▶// contains the TestXxx functions as described here,
18// and give that file a name ending in "_test.go".
19// The file will be excluded from regular
+ 284 more matches in this file
26// The scheduler's job is to distribute ready-to-run goroutines over worker threads.
27//
28▶// The main concepts are:
29// G - goroutine.
30// M - worker thread, or machine.
· · ·
84// utilization.
85//
86▶// The main implementation complication is that we need to be very careful
87// during spinning->non-spinning thread transition. This transition can race
88// with submission of new work, and either one part or another needs to unpark
· · ·
129var runtime_inittasks []*initTask
130
131▶// mainInitDone is a signal used by cgocallbackg that initialization
132// has been completed. If this is false, wait on mainInitDoneChan.
133var mainInitDone atomic.Bool
· · ·
132▶// has been completed. If this is false, wait on mainInitDoneChan.
133var mainInitDone atomic.Bool
134
· · ·
133▶var mainInitDone atomic.Bool
134
135// mainInitDoneChan is closed after initialization has been completed.
+ 390 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶// Package modload provides module and package loading functionality.
6package modload
7
· · ·
40// TODO(#40775): See if these can be plumbed as explicit parameters.
41var (
42▶ // ExplicitWriteGoMod prevents LoadPackages, ListModules, and other functions
43 // from updating go.mod and go.sum or reporting errors when updates are
44 // needed. A package should set this if it would cause go.mod to be written
· · ·
56)
57
58▶// EnterModule resets MainModules and requirements to refer to just this one module.
59func EnterModule(ld *Loader, ctx context.Context, enterModroot string) {
60 ld.MainModules = nil // reset MainModules
· · ·
59▶func EnterModule(ld *Loader, ctx context.Context, enterModroot string) {
60 ld.MainModules = nil // reset MainModules
61 ld.requirements = nil
· · ·
60▶ ld.MainModules = nil // reset MainModules
61 ld.requirements = nil
62 ld.workFilePath = "" // Force module mode
+ 215 more matches in this file
28)
29
30▶func (b branch) String() string {
31 switch b {
32 case unknown:
· · ·
74}
75
76▶func (r relation) String() string {
77 if r < relation(len(relationStrings)) {
78 return relationStrings[r]
· · ·
81}
82
83▶// domain represents the domain of a variable pair in which a set
84// of relations is known. For example, relations learned for unsigned
85// pairs cannot be transferred to signed pairs because the same bit
· · ·
86// representation can mean something else.
87▶type domain uint
88
89const (
· · ·
90▶ signed domain = 1 << iota
91 unsigned
92 pointer
+ 166 more matches in this file
38// We have two different ways of doing defers. The older way involves creating a
39// defer record at the time that a defer statement is executing and adding it to a
40▶// defer chain. This chain is inspected by the deferreturn call at all function
41// exits in order to run the appropriate defer calls. A cheaper way (which we call
42// open-coded defers) is used for functions in which no defer statements occur in
· · ·
42▶// open-coded defers) is used for functions in which no defer statements occur in
43// loops. In that case, we simply store the defer function/arg information into
44// specific stack slots at the point of each defer statement, as well as setting a
· · ·
43▶// loops. In that case, we simply store the defer function/arg information into
44// specific stack slots at the point of each defer statement, as well as setting a
45// bit in a bitmask. At each function exit, we add inline code to directly make
· · ·
45▶// bit in a bitmask. At each function exit, we add inline code to directly make
46// the appropriate defer calls based on the bitmask and fn/arg information stored
47// on the stack. During panic/Goexit processing, the appropriate defer calls are
· · ·
48▶// made using extra funcdata info that indicates the exact stack slots that
49// contain the bitmask and defer fn/args.
50
+ 182 more matches in this file
69// from newer pre-release or development versions.
70//
71▶// The allowed function (which may be nil) is used to filter out unsuitable
72// versions (see AllowedFunc documentation for details). If the query refers to
73// a specific revision (for example, "master"; see IsRevisionQuery), and the
· · ·
72▶// versions (see AllowedFunc documentation for details). If the query refers to
73// a specific revision (for example, "master"; see IsRevisionQuery), and the
74// revision is disallowed by allowed, Query returns the error. If the query
· · ·
76// acts as if versions disallowed by allowed do not exist.
77//
78▶// If path is the path of the main module and the query is "latest",
79// Query returns Target.Version as the version.
80//
· · ·
81// Query often returns a non-nil *RevInfo with a non-nil error,
82// to provide an info.Origin that can allow the error to be cached.
83▶func Query(ld *Loader, ctx context.Context, path, query, current string, allowed AllowedFunc) (*modfetch.RevInfo, error) {
84 ctx, span := trace.StartSpan(ctx, "modload.Query "+path)
85 defer span.Done()
· · ·
90// queryReuse is like Query but also takes a map of module info that can be reused
91// if the validation criteria in Origin are met.
92▶func queryReuse(ld *Loader, ctx context.Context, path, query, current string, allowed AllowedFunc, reuse map[module.Version]*modinfo.ModulePublic) (*modfetch.RevInfo, error) {
93 var info *modfetch.RevInfo
94 err := modfetch.TryProxies(func(proxy string) (err error) {
+ 141 more matches in this file
6
7// This file contains the module-mode package loader, as well as some accessory
8▶// functions pertaining to the package import graph.
9//
10// There are two exported entry points into package loading — LoadPackages and
· · ·
12// manipulates an instance of the loader struct.
13//
14▶// Although most of the loading state is maintained in the loader struct,
15// one key piece - the build list - is a global, so that it can be modified
16// separate from the loading operation, such as during "go get"
· · ·
28// computed from the package import graph, and therefore cannot be an initial
29// input to loading that graph. Instead, the root packages for the "all" pattern
30▶// are those contained in the main module, and allPatternIsRoot parameter to the
31// loader instructs it to dynamically expand those roots to the full "all"
32// pattern as loading progresses.
· · ·
35// package is known to match the "all" meta-pattern.
36// A package matches the "all" pattern if:
37▶// - it is in the main module, or
38// - it is imported by any test in the main module, or
39// - it is imported by a tool of the main module, or
· · ·
38▶// - it is imported by any test in the main module, or
39// - it is imported by a tool of the main module, or
40// - it is imported by another package in "all", or
+ 136 more matches in this file
85 Incomplete bool `json:",omitempty"` // was there an error loading this package or dependencies?
86
87▶ DefaultGODEBUG string `json:",omitempty"` // default GODEBUG setting (only for Name=="main")
88
89 // Stale and StaleReason remain here *only* for the list command.
· · ·
89▶ // Stale and StaleReason remain here *only* for the list command.
90 // They are only initialized in preparation for list execution.
91 // The regular build determines staleness on the fly during action execution.
· · ·
152// The go/build package filtered others out (like foo_wrongGOARCH.s)
153// and that's OK.
154▶func (p *Package) AllFiles() []string {
155 files := str.StringList(
156 p.GoFiles,
· · ·
196
197// Desc returns the package "description", for use in b.showOutput.
198▶func (p *Package) Desc() string {
199 if p.ForTest != "" {
200 return p.ImportPath + " [" + p.ForTest + ".test]"
· · ·
201 }
202▶ if p.Internal.ForMain != "" {
203 return p.ImportPath + " [" + p.Internal.ForMain + "]"
204 }
+ 221 more matches in this file
136 Long: `
137The go command can run version control commands like git
138▶to download imported code. This functionality is critical to the decentralized
139Go package ecosystem, in which code can be imported from any server,
140but it is also a potential security problem, if a malicious server finds a
· · ·
141way to cause the invoked version control command to run unintended code.
142
143▶To balance the functionality and security concerns, the go command
144by default will only use git and hg to download code from public servers.
145But it will use any known version control system (fossil, git, hg, svn)
· · ·
227}
228
229▶func (*upgradeFlag) IsBoolFlag() bool { return true } // allow -u
230
231func (v *upgradeFlag) Set(s string) error {
· · ·
231▶func (v *upgradeFlag) Set(s string) error {
232 if s == "false" {
233 v.version = ""
· · ·
243}
244
245▶func (v *upgradeFlag) String() string { return "" }
246
247// dFlag is a custom flag.Value for the deprecated -d flag
+ 135 more matches in this file
74// Hook points used for testing.
75// Outside of tests, t.transportTestHooks is nil and these all have minimal implementations.
76▶// Inside tests, see the testSyncHooks function docs.
77
78type transportTestHooks struct {
· · ·
79▶ newclientconn func(*ClientConn)
80}
81
· · ·
82▶func (t *Transport) maxHeaderListSize() uint32 {
83 n := t.t1.MaxHeaderListSize()
84 if b := t.t1.MaxResponseHeaderBytes(); b != 0 {
· · ·
97}
98
99▶func (t *Transport) disableCompression() bool {
100 return t.t1 != nil && t.t1.DisableCompression()
101}
· · ·
102
103▶func NewTransport(t1 TransportConfig) *Transport {
104 connPool := new(clientConnPool)
105 t2 := &Transport{
+ 178 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶package main
6
7import (
· · ·
43 go tool cover -html=c.out -o coverage.html
44
45▶Display coverage percentages to stdout for each function:
46 go tool cover -func=c.out
47
· · ·
46▶ go tool cover -func=c.out
47
48Finally, to generate modified source code with coverage annotations
· · ·
59`
60
61▶func usage() {
62 fmt.Fprint(os.Stderr, usageMessage)
63 fmt.Fprintln(os.Stderr, "\nFlags:")
· · ·
64 flag.PrintDefaults()
65▶ fmt.Fprintln(os.Stderr, "\n Only one of -html, -func, or -mode may be set.")
66 os.Exit(2)
67}
+ 115 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶package main
6
7import (
· · ·
32
33var (
34▶ // main operation modes
35 list = flag.Bool("l", false, "list files whose formatting differs from gofmt's")
36 write = flag.Bool("w", false, "write result to (source) file instead of stdout")
· · ·
70
71var (
72▶ rewrite func(*token.FileSet, *ast.File) *ast.File
73 parserMode parser.Mode
74)
· · ·
75
76▶func usage() {
77 fmt.Fprintf(os.Stderr, "usage: gofmt [flags] [path ...]\n")
78 flag.PrintDefaults()
· · ·
79}
80
81▶func initParserMode() {
82 parserMode = parser.ParseComments | parser.SkipObjectResolution
83 if *allErrors {
+ 32 more matches in this file
5// This program can be used as go_ios_$GOARCH_exec by the Go tool. It executes
6// binaries on the iOS Simulator using the XCode toolchain.
7▶package main
8
9import (
· · ·
36var lock *os.File
37
38▶func main() {
39 log.SetFlags(0)
40 log.SetPrefix("go_ios_exec: ")
· · ·
49 bundleID = "golang.gotest"
50
51▶ exitCode, err := runMain()
52 if err != nil {
53 log.Fatalf("%v\n", err)
· · ·
56}
57
58▶func runMain() (int, error) {
59 var err error
60 tmpdir, err = os.MkdirTemp("", "go_ios_exec_")
· · ·
95}
96
97▶func runOnSimulator(appdir string) error {
98 if err := installSimulator(appdir); err != nil {
99 return err
+ 9 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶package main
6
7import (
· · ·
15)
16
17▶func init() {
18 common.X *= 5
19}
· · ·
21// testUnnamed tests that two plugins built with .go files passed on
22// the command line do not have overlapping symbols. That is,
23▶// unnamed1.so/FuncInt and unnamed2.so/FuncInt should be distinct functions.
24func testUnnamed() {
25 p, err := plugin.Open("unnamed1.so")
· · ·
24▶func testUnnamed() {
25 p, err := plugin.Open("unnamed1.so")
26 if err != nil {
· · ·
27 log.Fatalf(`plugin.Open("unnamed1.so"): %v`, err)
28 }
29▶ fn, err := p.Lookup("FuncInt")
30 if err != nil {
31 log.Fatalf(`unnamed1.so: Lookup("FuncInt") failed: %v`, err)
+ 21 more matches in this file
8// upstreaming any modifications to these packages.
9
10▶package main
11
12import (
· · ·
33)
34
35▶func main() {
36 counter.Open()
37 counter.Inc("pprof/invocations")
· · ·
52}
53
54▶func (f *fetcher) Fetch(src string, duration, timeout time.Duration) (*profile.Profile, string, error) {
55 // Firstly, determine if the src is an existing file on the disk.
56 // If it is a file, let regular pprof open it.
· · ·
76}
77
78▶func getProfile(source string, timeout time.Duration) (*profile.Profile, error) {
79 url, err := url.Parse(source)
80 if err != nil {
· · ·
109}
110
111▶func statusCodeError(resp *http.Response) error {
112 if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
113 // error is from pprof endpoint
+ 22 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶package main
6
7import (
· · ·
10)
11
12▶func main() {
13 ss, sa := shared(23)
14 ps, pa := private(23)
· · ·
24}
25
26▶func experiment(x int) (int, int) {
27 sum := 0
28 var is []*int
· · ·
53}
54
55▶func private(x int) (int, int) {
56 sum := 0
57 var is []*int
· · ·
86}
87
88▶func shared(x int) (int, int) {
89 sum := 0
90 var is []*int
146 // If WriteHeader is not called explicitly, the first call to Write
147 // will trigger an implicit WriteHeader(http.StatusOK).
148▶ // Thus explicit calls to WriteHeader are mainly used to
149 // send error codes or 1xx informational responses.
150 //
· · ·
202 //
203 // After a call to Hijack, the original Request.Body must not
204▶ // be used. The original Request's Context remains valid and
205 // is not canceled until the Request's ServeHTTP method
206 // returns.
· · ·
259
260 // cancelCtx cancels the connection-level context.
261▶ cancelCtx context.CancelFunc
262
263 // rwc is the underlying network connection.
· · ·
283 // r is bufr's read source. It's a wrapper around rwc that provides
284 // io.LimitedReader-style limiting (while reading request headers)
285▶ // and functionality to support CloseNotifier. See *connReader docs.
286 r *connReader
287
· · ·
309}
310
311▶func (c *conn) hijacked() bool {
312 c.mu.Lock()
313 defer c.mu.Unlock()
+ 241 more matches in this file
45 // rootModules is the set of root modules of the graph, sorted and capped to
46 // length. It may contain duplicates, and may contain multiple versions for a
47▶ // given module path. The root modules of the graph are the set of main
48 // modules in workspace mode, and the main module's direct requirements
49 // outside workspace mode.
· · ·
48▶ // modules in workspace mode, and the main module's direct requirements
49 // outside workspace mode.
50 //
· · ·
55
56 // direct is the set of module paths for which we believe the module provides
57▶ // a package directly imported by a package or test in the main module.
58 //
59 // The "direct" map controls which modules are annotated with "// indirect"
· · ·
69 //
70 // The direct map is keyed by module paths, not module versions. When a
71▶ // module's selected version changes, we assume that it remains direct if the
72 // previous version was a direct dependency. That assumption might not hold in
73 // rare cases (such as if a dependency splits out a nested module, or merges a
· · ·
86}
87
88▶func mustHaveGoRoot(roots []module.Version) {
89 for _, m := range roots {
90 if m.Path == "go" {
+ 110 more matches in this file
8// go run mknode.go
9
10▶package main
11
12import (
· · ·
40// implementsNode reports whether the type t is one which represents a Node
41// in the AST.
42▶func implementsNode(t ast.Expr) bool {
43 id, ok := t.(*ast.Ident)
44 if !ok {
· · ·
58}
59
60▶func isMini(t ast.Expr) bool {
61 id, ok := t.(*ast.Ident)
62 return ok && mini[id.Name] != nil
· · ·
63}
64
65▶func isNamedType(t ast.Expr, name string) bool {
66 if id, ok := t.(*ast.Ident); ok {
67 if id.Name == name {
· · ·
72}
73
74▶func main() {
75 fmt.Fprintln(&buf, "// Code generated by mknode.go. DO NOT EDIT.")
76 fmt.Fprintln(&buf)
+ 17 more matches in this file
34// isPrintable reports whether the given b is in the ASN.1 PrintableString set.
35// This is a simplified version of encoding/asn1.isPrintable.
36▶func isPrintable(b byte) bool {
37 return 'a' <= b && b <= 'z' ||
38 'A' <= b && b <= 'Z' ||
· · ·
59// from the respective encoding/asn1.parse... methods, rather than just
60// increasing the API surface of that package.
61▶func parseASN1String(tag cryptobyte_asn1.Tag, value []byte) (string, error) {
62 switch tag {
63 case cryptobyte_asn1.T61String:
· · ·
64▶ // T.61 is a defunct ITU 8-bit character encoding which preceded Unicode.
65 // T.61 uses a code page layout that _almost_ exactly maps to the code
66 // page layout of the ISO 8859-1 (Latin-1) character encoding, with the
· · ·
90 return string(value), nil
91 case cryptobyte_asn1.Tag(asn1.TagBMPString):
92▶ // BMPString uses the defunct UCS-2 16-bit character encoding, which
93 // covers the Basic Multilingual Plane (BMP). UTF-16 was an extension of
94 // UCS-2, containing all of the same code points, but also including
· · ·
141
142// readASN1Any parses types documented at [pkix.AttributeTypeAndValue].
143▶func readASN1Any(der *cryptobyte.String) (any, error) {
144 var fullValue cryptobyte.String
145 var valueTag cryptobyte_asn1.Tag
+ 48 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶package main
6
7import (
· · ·
25 go doc cmd/pack`
26
27▶func usage() {
28 fmt.Fprintln(os.Stderr, usageMessage)
29 os.Exit(2)
· · ·
30}
31
32▶func main() {
33 log.SetFlags(0)
34 log.SetPrefix("pack: ")
· · ·
82
83// setOp parses the operation string (first argument).
84▶func setOp(arg string) {
85 // Recognize 'go tool pack grc' because that was the
86 // formerly canonical way to build a new archive
· · ·
125
126// archive opens (and if necessary creates) the named archive.
127▶func openArchive(name string, mode int, files []string) *Archive {
128 f, err := os.OpenFile(name, mode, 0666)
129 if err != nil {
+ 12 more matches in this file
30// ReadModFile reads and parses the mod file at gomod. ReadModFile properly applies the
31// overlay, locks the file while reading, and applies fix, if applicable.
32▶func ReadModFile(gomod string, fix modfile.VersionFixer) (data []byte, f *modfile.File, err error) {
33 if fsys.Replaced(gomod) {
34 // Don't lock go.mod if it's part of the overlay.
· · ·
76}
77
78▶func shortPathErrorList(err error) error {
79 if el, ok := errors.AsType[modfile.ErrorList](err); ok {
80 for i := range el {
· · ·
114)
115
116▶func (p modPruning) String() string {
117 switch p {
118 case pruned:
· · ·
127}
128
129▶func pruningForGoVersion(goVersion string) modPruning {
130 if gover.Compare(goVersion, gover.ExplicitIndirectVersion) < 0 {
131 // The go.mod file does not duplicate relevant information about transitive
· · ·
137
138// CheckAllowed returns an error equivalent to ErrDisallowed if m is excluded by
139▶// the main module's go.mod or retracted by its author. Most version queries use
140// this to filter out versions that should not be used.
141func (ld *Loader) CheckAllowed(ctx context.Context, m module.Version) error {
+ 62 more matches in this file
72//
73// This kind of key is commonly encoded in PEM blocks of type "PUBLIC KEY".
74▶func ParsePKIXPublicKey(derBytes []byte) (pub any, err error) {
75 var pki publicKeyInfo
76 if rest, err := asn1.Unmarshal(derBytes, &pki); err != nil {
· · ·
85}
86
87▶func marshalPublicKey(pub any) (publicKeyBytes []byte, publicKeyAlgorithm pkix.AlgorithmIdentifier, err error) {
88 switch pub := pub.(type) {
89 case *rsa.PublicKey:
· · ·
158//
159// This kind of key is commonly encoded in PEM blocks of type "PUBLIC KEY".
160▶func MarshalPKIXPublicKey(pub any) ([]byte, error) {
161 var publicKeyBytes []byte
162 var publicKeyAlgorithm pkix.AlgorithmIdentifier
· · ·
246)
247
248▶func (algo SignatureAlgorithm) isRSAPSS() bool {
249 for _, details := range signatureAlgorithmDetails {
250 if details.algo == algo {
· · ·
255}
256
257▶func (algo SignatureAlgorithm) hashFunc() crypto.Hash {
258 for _, details := range signatureAlgorithmDetails {
259 if details.algo == algo {
+ 106 more matches in this file
45// Typical usage should look like:
46//
47▶// func main() {
48// filename := "" // Set to enable per-phase pprof file output.
49// bench := benchmark.New(benchmark.GC, filename)
· · ·
59// code like:
60//
61▶// func main() {
62// enableBenchmarking := flag.Bool("enable", true, "enables benchmarking")
63// flag.Parse()
· · ·
69// // etc.
70// }
71▶func New(gc Flags, filebase string) *Metrics {
72 if gc == GC {
73 runtime.GC()
· · ·
78// Report reports the metrics.
79// Closes the currently Start(ed) range, and writes the report to the given io.Writer.
80▶func (m *Metrics) Report(w io.Writer) {
81 if m == nil {
82 return
· · ·
109// Start marks the beginning of a new measurement phase.
110// Once a metric is started, it continues until either a Report is issued, or another Start is called.
111▶func (m *Metrics) Start(name string) {
112 if m == nil {
113 return
+ 4 more matches in this file
18)
19
20▶// lostProfileEvent is the function to which lost profiling
21// events are attributed.
22// (The name shows up in the pprof graphs.)
· · ·
23▶func lostProfileEvent() { lostProfileEvent() }
24
25// A profileBuilder writes a profile incrementally from a
· · ·
39 stringMap map[string]int
40 locs map[uintptr]locInfo // list of locInfo starting with the given PC.
41▶ funcs map[string]int // Package path-qualified function name to Function.ID
42 mem []memMap
43 deck pcDeck
· · ·
52 buildID string // A string that uniquely identifies a particular program version with high probability.
53
54▶ funcs symbolizeFlag
55 fake bool // map entry was faked; /proc/self/maps wasn't available
56}
· · ·
74 tagProfile_Mapping = 3 // repeated Mapping
75 tagProfile_Location = 4 // repeated Location
76▶ tagProfile_Function = 5 // repeated Function
77 tagProfile_StringTable = 6 // repeated string
78 tagProfile_DropFrames = 7 // int64 (string table index)
+ 91 more matches in this file