How-Tos

1 min read


Let's do Kubernetes

I’m taking a small detour today, to a topic that’s not strictly Go-related, but which I get asked about a lot: Docker and Kubernetes. Starting on Monday, in what is likely to become a 2- or 3-week series, I’m going to be deploying a small Go app I wrote, to Kubernetes on Google Cloud. I’ve done this before, but it’s been a few years, so I’m a bit rusty. And Kubernetes has changed (as it always does), so there are sure to be some educational bumps along the way.

How-Tos

24 min watch


Resume advice for a first-time job seeker

I review the résumé/CV of a first-time job seeker, looking for a Go-related job.


Method values

As I promised yesterday, today we’re looking at method values, a concept with some similarties to the previous concept of method expressions, but with a bit more utility. Method values If the expression x has static type T and M is in the method set of type T, x.M is called a method value. The method value x.M is a function value that is callable with the same arguments as a method call of x.


Method expressions, conclusion

Today we’ll finish our discussoin of method expression from Monday and Tuesday. Method expressions … Function values derived from methods are called with function call syntax; the receiver is provided as the first argument to the call. That is, given f := T.Mv, f is invoked as f(t, 7) not t.f(7). We’ve already seen examples of this, the last two days. But to be honest, you’re unlikely to use these types of functions very frequently.


Method expressions, part 2

Today I’ll continue where I left off yesterday, talking about… Method expressions … Similarly, the expression (*T).Mp yields a function value representing Mp with signature func(tp *T, f float32) float32 The key difference to notice between this example and yesterday’s is that the first argument (that of the receiver) is a pointer here, but was not a pointer in the previous example: func(tv T, a int) int // First argument of type T, not a pointer func(tp *T, f float32) float32 // First argument of type *T, a pointer For a method with a value receiver, one can derive a function with an explicit pointer receiver, so


Method expressions

There was no livestream today, as I was a bit under the weather. I intend to be back live streaming next Monday as usual Method expressions If M is in the method set of type T, T.M is a function that is callable as a regular function with the same arguments as M prefixed by an additional argument that is the receiver of the method. MethodExpr = ReceiverType "." MethodName .


Illegal selectors

We’ll cover the last 3 rules of selectors in one go today, since they’re all about illegal selectors. Selectors … In all other cases, x.f is illegal. Simple enough. The cases mentioned in rules 1-3 ar ethe only valid uses of x.f. All others are illegal. var x int x.chicken // illegal! If x is of pointer type and has the value nil and x.f denotes a struct field, assigning to or evaluating x.

Subscribe to Boldly Go: Daily

Every day I'll send you advice to improve your understanding of Go. Don't miss out! I will respect your inbox, and honor my privacy policy.

Unsure? Browse the archive.


Third rule of selectors

Selectors … As an exception, if the type of x is a defined pointer type and (*x).f is a valid selector expression denoting a field (but not a method), x.f is shorthand for (*x).f. I find this wording to be confusing. That probably means some of you do, too. So here goes my best attempt at explaining it. “if the type of x is a defined pointer type” refers to something like this:

How-Tos

8 min watch


Don't mock slog

Don't mock slog! This video shows you the super simple alternative


Second rule of Selectors

Selectors … For a value x of type I where I is an interface type, x.f denotes the actual method with name f of the dynamic value of x. If there is no method with name f in the method set of I, the selector expression is illegal. type I interface { Greet() } type Person struct { Name string } func (p *Person) Greet() { fmt.Printf("Hello, %s", p.Name) } var I x x = &Person{} x.


The first rule of Selectors

Today I’m live streaming again at the regular time, and I’ll be reviewing your Go code!. I have already received a few submissions, but there’s still time to send yours! And, of course, [join me for the live stream!](https://www.youtube.com/watch?v=pgfyrmWiUCk We're going to talk about Selectors. The spec lays out 6 rules. We’ll start at the beginning, and discuss the first one. Selectors … The following rules apply to selectors: For a value x of type T or *T where T is not a pointer or interface type, x.