MCPcopy Create free account

hub / github.com/mmcgrana/gobyexample / functions

Functions190 in github.com/mmcgrana/gobyexample

↓ 15 callersFunctioncheck
(err error)
tools/generate.go:32
↓ 13 callersFunctiont
(t,e)
public/site.js:7
↓ 13 callersFunctiont
(t,e)
templates/site.js:7
↓ 11 callersFunctioncheck
Reading files requires checking most calls for errors. This helper will streamline our error checks below.
examples/reading-files/reading-files.go:17
↓ 9 callersFunctioni
(t,e,n)
public/site.js:7
↓ 9 callersFunctioni
(t,e,n)
templates/site.js:7
↓ 8 callersMethodString
()
examples/xml/xml.go:25
↓ 8 callersFunctioncheck
(e error)
examples/directories/directories.go:13
↓ 7 callersFunctionmustReadFile
(path string)
tools/generate.go:62
↓ 7 callersFunctionr
(c,a)
public/site.js:7
↓ 7 callersFunctionr
(c,a)
templates/site.js:7
↓ 6 callersMethodPush
We can define methods on generic types just like we do on regular types, but we have to keep the type parameters in place. The type is `List[T]`, not
examples/generics/generics.go:40
↓ 5 callersFunctioncheck
(e error)
examples/writing-files/writing-files.go:13
↓ 5 callersFunctioncopyFile
(src, dst string)
tools/generate.go:48
↓ 5 callersFunctionl
(t,e)
public/site.js:7
↓ 5 callersFunctionl
(t,e)
templates/site.js:7
↓ 5 callersFunctionverbose
()
tools/generate.go:28
↓ 4 callersFunctioncheck
(e error)
examples/temporary-files-and-directories/temporary-files-and-directories.go:15
↓ 4 callersFunctione
(n,o)
public/site.js:7
↓ 4 callersFunctione
(n,o)
templates/site.js:7
↓ 3 callersFunctionIntMin
We'll be testing this simple implementation of an integer minimum. Typically, the code we're testing would be in a source file named something like `i
examples/testing-and-benchmarking/main_test.go:21
↓ 3 callersMethodPush
(v T)
examples/range-over-iterators/range-over-iterators.go:28
↓ 3 callersFunctionc
(t,e,n)
public/site.js:7
↓ 3 callersFunctionc
(t,e,n)
templates/site.js:7
↓ 3 callersFunctiondebug
(msg string)
tools/generate.go:92
↓ 3 callersFunctionreadLines
(path string)
tools/generate.go:72
↓ 3 callersFunctionsum
Here's a function that will take an arbitrary number of `int`s as arguments.
examples/variadic-functions/variadic-functions.go:12
↓ 2 callersMethodAll
All returns an _iterator_, which in Go is a function with a [special signature](https://pkg.go.dev/iter#Seq).
examples/range-over-iterators/range-over-iterators.go:40
↓ 2 callersMethodError
Adding this `Error` method makes `argError` implement the `error` interface.
examples/custom-errors/custom-errors.go:21
↓ 2 callersFunctionSlicesIndex
As an example of a generic function, `SlicesIndex` takes a slice of any `comparable` type and an element of that type and returns the index of the fir
examples/generics/generics.go:17
↓ 2 callersMethodarea
()
examples/interfaces/interfaces.go:13
↓ 2 callersFunctioncheck
(err error)
tools/measure.go:12
↓ 2 callersMethoddescribe
()
examples/struct-embedding/struct-embedding.go:53
↓ 2 callersFunctiondetectCircle
Sometimes it's useful to know the runtime type of an interface value. One option is using a *type assertion* as shown here; another is a [type `switch
examples/interfaces/interfaces.go:57
↓ 2 callersFunctionf
(from string)
examples/goroutines/goroutines.go:10
↓ 2 callersFunctionintSeq
This function `intSeq` returns another function, which we define anonymously in the body of `intSeq`. The returned function _closes over_ the variable
examples/closures/closures.go:14
↓ 2 callersFunctionmeasure
If a variable has an interface type, then we can call methods that are in the named interface. Here's a generic `measure` function taking advantage of
examples/interfaces/interfaces.go:48
↓ 2 callersFunctiono
(t,e,n)
public/site.js:7
↓ 2 callersFunctiono
(t,e,n)
templates/site.js:7
↓ 2 callersMethodperim
()
examples/interfaces/interfaces.go:14
↓ 2 callersFunctiontransition
transition emulates a state transition for a server; it takes the existing state and returns a new state.
examples/enums/enums.go:60
↓ 2 callersFunctionvals
The `(int, int)` in this function signature shows that the function returns 2 `int`s.
examples/multiple-return-values/multiple-return-values.go:11
↓ 1 callersMethodAllElements
AllElements returns all the List elements as a slice. In the next example we'll see a more idiomatic way of iterating over all elements of custom type
examples/generics/generics.go:53
↓ 1 callersFunctiona
(t,e)
public/site.js:7
↓ 1 callersFunctiona
(t,e)
templates/site.js:7
↓ 1 callersMethodarea
This `area` method has a _receiver type_ of `*rect`.
examples/methods/methods.go:12
↓ 1 callersFunctionchromaFormat
(code, filePath string)
tools/generate.go:196
↓ 1 callersFunctioncloseFile
(f *os.File)
examples/defer/defer.go:44
↓ 1 callersFunctioncreateFile
(p string)
examples/defer/defer.go:30
↓ 1 callersFunctionensureDir
(dir string)
tools/generate.go:43
↓ 1 callersFunctionexamineRune
(r rune)
examples/strings-and-runes/strings-and-runes.go:65
↓ 1 callersFunctionf
(arg int)
examples/custom-errors/custom-errors.go:25
↓ 1 callersFunctionf
By convention, errors are the last return value and have type `error`, a built-in interface.
examples/errors/errors.go:23
↓ 1 callersFunctionfact
This `fact` function calls itself until it reaches the base case of `fact(0)`.
examples/recursion/recursion.go:11
↓ 1 callersFunctiongenFib
Iteration doesn't require an underlying data structure, and doesn't even have to be finite! Here's a function returning an iterator over Fibonacci num
examples/range-over-iterators/range-over-iterators.go:59
↓ 1 callersFunctionguessContentType
guessContentType guesses the HTTP content type appropriate for the given filename.
tools/upload.go:22
↓ 1 callersFunctionhandleConnection
`handleConnection` handles a single client connection, reading one line of text from the client and returning a response.
examples/tcp-server/tcp-server.go:44
↓ 1 callersMethodinc
(name string)
examples/mutexes/mutexes.go:24
↓ 1 callersFunctionisDir
(path string)
tools/generate.go:38
↓ 1 callersFunctionisDir
(path string)
tools/measure.go:24
↓ 1 callersFunctionmakeTea
(arg int)
examples/errors/errors.go:40
↓ 1 callersFunctionmarkdown
(src string)
tools/generate.go:68
↓ 1 callersFunctionmayPanic
This function panics.
examples/recover/recover.go:18
↓ 1 callersFunctionmustGlob
(glob string)
tools/generate.go:77
↓ 1 callersFunctionn
(t)
public/site.js:7
↓ 1 callersFunctionn
(t)
templates/site.js:7
↓ 1 callersFunctionnewPerson
`newPerson` constructs a new person struct with the given name.
examples/structs/structs.go:16
↓ 1 callersFunctionparseAndRenderSegs
(sourcePath string)
tools/generate.go:221
↓ 1 callersFunctionparseExamples
()
tools/generate.go:244
↓ 1 callersFunctionparseHashFile
(sourcePath string)
tools/generate.go:117
↓ 1 callersFunctionparseSegs
(sourcePath string)
tools/generate.go:138
↓ 1 callersMethodperim
Methods can be defined for either pointer or value receiver types. Here's an example of a value receiver.
examples/methods/methods.go:18
↓ 1 callersFunctionping
This `ping` function only accepts a channel for sending values. It would be a compile-time error to try to receive on this channel.
examples/channel-directions/channel-directions.go:13
↓ 1 callersFunctionplus
Here's a function that takes two `int`s and returns their sum as an `int`.
examples/functions/functions.go:10
↓ 1 callersFunctionplusPlus
When you have multiple consecutive parameters of the same type, you may omit the type name for the like-typed parameters up to the final parameter tha
examples/functions/functions.go:22
↓ 1 callersFunctionpong
The `pong` function accepts one channel for receives (`pings`) and a second for sends (`pongs`).
examples/channel-directions/channel-directions.go:19
↓ 1 callersFunctionreadLines
(path string)
tools/measure.go:18
↓ 1 callersFunctionrender404
()
tools/generate.go:323
↓ 1 callersFunctionrenderExamples
(examples []*Example)
tools/generate.go:308
↓ 1 callersFunctionrenderIndex
(examples []*Example)
tools/generate.go:295
↓ 1 callersFunctionresetURLHashFile
(codehash, code, sourcePath string)
tools/generate.go:122
↓ 1 callersFunctionsha1Sum
(s string)
tools/generate.go:55
↓ 1 callersFunctionwhichLexer
(path string)
tools/generate.go:83
↓ 1 callersFunctionworker
Here's the worker, of which we'll run several concurrent instances. These workers will receive work on the `jobs` channel and send the corresponding r
examples/worker-pools/worker-pools.go:16
↓ 1 callersFunctionworker
This is the function we'll run in every goroutine.
examples/waitgroups/waitgroups.go:13
↓ 1 callersFunctionworker
This is the function we'll run in a goroutine. The `done` channel will be used to notify another goroutine that this function's work is done.
examples/channel-synchronization/channel-synchronization.go:17
↓ 1 callersFunctionwriteFile
(f *os.File)
examples/defer/defer.go:39
↓ 1 callersFunctionzeroptr
`zeroptr` in contrast has an `*int` parameter, meaning that it takes an `int` pointer. The `*iptr` code in the function body then _dereferences_ the p
examples/pointers/pointers.go:24
↓ 1 callersFunctionzeroval
We'll show how pointers work in contrast to values with 2 functions: `zeroval` and `zeroptr`. `zeroval` has an `int` parameter, so arguments will be p
examples/pointers/pointers.go:14
FunctionBenchmarkIntMin
Benchmark tests typically go in `_test.go` files and are named beginning with `Benchmark`. Any code that's required for the benchmark to run but shoul
examples/testing-and-benchmarking/main_test.go:74
MethodString
()
examples/enums/enums.go:42
FunctionTestIntMinBasic
A test is created by writing a function with a name beginning with `Test`.
examples/testing-and-benchmarking/main_test.go:30
FunctionTestIntMinTableDriven
Writing tests can be repetitive, so it's idiomatic to use a *table-driven style*, where test inputs and expected outputs are listed in a table and a s
examples/testing-and-benchmarking/main_test.go:44
Methodarea
To implement an interface in Go, we just need to implement all the methods in the interface. Here we implement `geometry` on `rect`s.
examples/interfaces/interfaces.go:29
Methodarea
The implementation for `circle`s.
examples/interfaces/interfaces.go:37
Methoddescribe
()
examples/struct-embedding/struct-embedding.go:15
Functionheaders
(w http.ResponseWriter, req *http.Request)
examples/http-server/http-server.go:25
Functionhello
A fundamental concept in `net/http` servers is *handlers*. A handler is an object implementing the `http.Handler` interface. A common way to write a h
examples/http-server/http-server.go:15
Functionhello
(w http.ResponseWriter, req *http.Request)
examples/context/context.go:15
Functionmain
()
tools/upload.go:35
next →1–100 of 190, ranked by callers