Check out a free preview of the full Basics of Go course

The "Visibility" Lesson is part of the full, Basics of Go course featured in this preview video. Here's what you'd learn in this lesson:

Maximiliano gives a concise overview of visibility in Go, explaining the concepts of defining public or private elements and discussing the various scoping options for variables and lambda functions.

Preview
Close

Transcript from the "Visibility" Lesson

[00:00:00]
>> So, to summarize the Visibility part. So, what we write in a module in a package, if it's camelCase, camelCase, it starts with lowercase. So lower case c, it means it's private to the package for example. If it's TitleCase, it's public and exported, right? So, variables and lambda functions, lambda functions, what's that?

[00:00:30]
Gimmie a sec. They can be module scoped, function scoped, or block scoped. Something that we already mentioned. So, lambda functions are just functions. Sometimes we name the functions as we did so far, such as the main functions, and also we have a way to treat functions as a special kind of variable.

[00:00:53]
So maybe we can create a function that has no name, but we can attach a link to the function that's a variable, that's kind of a function anyway. So for example, here, notExported, it's private to the package. It can only be used in the package. Remember, that means it can be used from other go files in the same package, but not from other packages.

[00:01:20]
And if it's TitleCase, it's public and exported to other packages. That's the only thing you need to remember. Simple, right?

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now