Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/mmcgrana/gobyexample
/ functions
Functions
190 in github.com/mmcgrana/gobyexample
⨍
Functions
190
◇
Types & classes
25
↓ 15 callers
Function
check
(err error)
tools/generate.go:32
↓ 13 callers
Function
t
(t,e)
public/site.js:7
↓ 13 callers
Function
t
(t,e)
templates/site.js:7
↓ 11 callers
Function
check
Reading files requires checking most calls for errors. This helper will streamline our error checks below.
examples/reading-files/reading-files.go:17
↓ 9 callers
Function
i
(t,e,n)
public/site.js:7
↓ 9 callers
Function
i
(t,e,n)
templates/site.js:7
↓ 8 callers
Method
String
()
examples/xml/xml.go:25
↓ 8 callers
Function
check
(e error)
examples/directories/directories.go:13
↓ 7 callers
Function
mustReadFile
(path string)
tools/generate.go:62
↓ 7 callers
Function
r
(c,a)
public/site.js:7
↓ 7 callers
Function
r
(c,a)
templates/site.js:7
↓ 6 callers
Method
Push
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 callers
Function
check
(e error)
examples/writing-files/writing-files.go:13
↓ 5 callers
Function
copyFile
(src, dst string)
tools/generate.go:48
↓ 5 callers
Function
l
(t,e)
public/site.js:7
↓ 5 callers
Function
l
(t,e)
templates/site.js:7
↓ 5 callers
Function
verbose
()
tools/generate.go:28
↓ 4 callers
Function
check
(e error)
examples/temporary-files-and-directories/temporary-files-and-directories.go:15
↓ 4 callers
Function
e
(n,o)
public/site.js:7
↓ 4 callers
Function
e
(n,o)
templates/site.js:7
↓ 3 callers
Function
IntMin
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 callers
Method
Push
(v T)
examples/range-over-iterators/range-over-iterators.go:28
↓ 3 callers
Function
c
(t,e,n)
public/site.js:7
↓ 3 callers
Function
c
(t,e,n)
templates/site.js:7
↓ 3 callers
Function
debug
(msg string)
tools/generate.go:92
↓ 3 callers
Function
readLines
(path string)
tools/generate.go:72
↓ 3 callers
Function
sum
Here's a function that will take an arbitrary number of `int`s as arguments.
examples/variadic-functions/variadic-functions.go:12
↓ 2 callers
Method
All
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 callers
Method
Error
Adding this `Error` method makes `argError` implement the `error` interface.
examples/custom-errors/custom-errors.go:21
↓ 2 callers
Function
SlicesIndex
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 callers
Method
area
()
examples/interfaces/interfaces.go:13
↓ 2 callers
Function
check
(err error)
tools/measure.go:12
↓ 2 callers
Method
describe
()
examples/struct-embedding/struct-embedding.go:53
↓ 2 callers
Function
detectCircle
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 callers
Function
f
(from string)
examples/goroutines/goroutines.go:10
↓ 2 callers
Function
intSeq
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 callers
Function
measure
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 callers
Function
o
(t,e,n)
public/site.js:7
↓ 2 callers
Function
o
(t,e,n)
templates/site.js:7
↓ 2 callers
Method
perim
()
examples/interfaces/interfaces.go:14
↓ 2 callers
Function
transition
transition emulates a state transition for a server; it takes the existing state and returns a new state.
examples/enums/enums.go:60
↓ 2 callers
Function
vals
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 callers
Method
AllElements
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 callers
Function
a
(t,e)
public/site.js:7
↓ 1 callers
Function
a
(t,e)
templates/site.js:7
↓ 1 callers
Method
area
This `area` method has a _receiver type_ of `*rect`.
examples/methods/methods.go:12
↓ 1 callers
Function
chromaFormat
(code, filePath string)
tools/generate.go:196
↓ 1 callers
Function
closeFile
(f *os.File)
examples/defer/defer.go:44
↓ 1 callers
Function
createFile
(p string)
examples/defer/defer.go:30
↓ 1 callers
Function
ensureDir
(dir string)
tools/generate.go:43
↓ 1 callers
Function
examineRune
(r rune)
examples/strings-and-runes/strings-and-runes.go:65
↓ 1 callers
Function
f
(arg int)
examples/custom-errors/custom-errors.go:25
↓ 1 callers
Function
f
By convention, errors are the last return value and have type `error`, a built-in interface.
examples/errors/errors.go:23
↓ 1 callers
Function
fact
This `fact` function calls itself until it reaches the base case of `fact(0)`.
examples/recursion/recursion.go:11
↓ 1 callers
Function
genFib
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 callers
Function
guessContentType
guessContentType guesses the HTTP content type appropriate for the given filename.
tools/upload.go:22
↓ 1 callers
Function
handleConnection
`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 callers
Method
inc
(name string)
examples/mutexes/mutexes.go:24
↓ 1 callers
Function
isDir
(path string)
tools/generate.go:38
↓ 1 callers
Function
isDir
(path string)
tools/measure.go:24
↓ 1 callers
Function
makeTea
(arg int)
examples/errors/errors.go:40
↓ 1 callers
Function
markdown
(src string)
tools/generate.go:68
↓ 1 callers
Function
mayPanic
This function panics.
examples/recover/recover.go:18
↓ 1 callers
Function
mustGlob
(glob string)
tools/generate.go:77
↓ 1 callers
Function
n
(t)
public/site.js:7
↓ 1 callers
Function
n
(t)
templates/site.js:7
↓ 1 callers
Function
newPerson
`newPerson` constructs a new person struct with the given name.
examples/structs/structs.go:16
↓ 1 callers
Function
parseAndRenderSegs
(sourcePath string)
tools/generate.go:221
↓ 1 callers
Function
parseExamples
()
tools/generate.go:244
↓ 1 callers
Function
parseHashFile
(sourcePath string)
tools/generate.go:117
↓ 1 callers
Function
parseSegs
(sourcePath string)
tools/generate.go:138
↓ 1 callers
Method
perim
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 callers
Function
ping
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 callers
Function
plus
Here's a function that takes two `int`s and returns their sum as an `int`.
examples/functions/functions.go:10
↓ 1 callers
Function
plusPlus
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 callers
Function
pong
The `pong` function accepts one channel for receives (`pings`) and a second for sends (`pongs`).
examples/channel-directions/channel-directions.go:19
↓ 1 callers
Function
readLines
(path string)
tools/measure.go:18
↓ 1 callers
Function
render404
()
tools/generate.go:323
↓ 1 callers
Function
renderExamples
(examples []*Example)
tools/generate.go:308
↓ 1 callers
Function
renderIndex
(examples []*Example)
tools/generate.go:295
↓ 1 callers
Function
resetURLHashFile
(codehash, code, sourcePath string)
tools/generate.go:122
↓ 1 callers
Function
sha1Sum
(s string)
tools/generate.go:55
↓ 1 callers
Function
whichLexer
(path string)
tools/generate.go:83
↓ 1 callers
Function
worker
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 callers
Function
worker
This is the function we'll run in every goroutine.
examples/waitgroups/waitgroups.go:13
↓ 1 callers
Function
worker
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 callers
Function
writeFile
(f *os.File)
examples/defer/defer.go:39
↓ 1 callers
Function
zeroptr
`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 callers
Function
zeroval
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
Function
BenchmarkIntMin
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
Method
String
()
examples/enums/enums.go:42
Function
TestIntMinBasic
A test is created by writing a function with a name beginning with `Test`.
examples/testing-and-benchmarking/main_test.go:30
Function
TestIntMinTableDriven
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
Method
area
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
Method
area
The implementation for `circle`s.
examples/interfaces/interfaces.go:37
Method
describe
()
examples/struct-embedding/struct-embedding.go:15
Function
headers
(w http.ResponseWriter, req *http.Request)
examples/http-server/http-server.go:25
Function
hello
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
Function
hello
(w http.ResponseWriter, req *http.Request)
examples/context/context.go:15
Function
main
()
tools/upload.go:35
next →
1–100 of 190, ranked by callers