exporting/

directory
v0.0.0-...-7bfcdb5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2015 License: Apache-2.0

README

Exporting

Packages contain the basic unit of compiled code. They define a scope for the indentifiers that are declared within them. Learning how to package our code is vital because exported identifiers become part of the packages API. Stable and useable API's are incredibily important.

Notes

  • Code in go is complied into packages and then linked together.
  • Identifiers are exported (or remain unexported) based on letter-case.
  • We import packages to access exported identifiers.
  • Any package can use a value of an unexported type.

http://blog.golang.org/organizing-go-code

http://www.goinggo.net/2014/03/exportedunexported-identifiers-in-go.html

http://www.goinggo.net/2013/08/organizing-code-to-support-go-get.html

Code Review

Declare and access exported identifiers

Declare unexported identifiers and restrictions

Access values of unexported identifiers

Unexported struct type fields

Unexported embedded types

Exercises

Exercise 1

Part A Create a package named toy with a single exported struct type named Toy. Add the exported fields Name and Weight. Then add two unexported fields named onHand and sold. Declare a factory function called New to create values of type toy and accept parameters for the exported fields. Then declare methods that return and update values for the unexported fields.

Part B Create a program that imports the toy package. Use the New function to create a value of type toy. Then use the methods to set the counts and display the field values of that toy value.

Template | Answer


All material is licensed under the Apache License Version 2.0, January 2004.

Directories

Path Synopsis
Sample program to show how to access an exported identifier.
Sample program to show how to access an exported identifier.
counters
Package counters provides alert counter support.
Package counters provides alert counter support.
Sample program to show how the program can't access an unexported identifier from another package.
Sample program to show how the program can't access an unexported identifier from another package.
counters
Package counters provides alert counter support.
Package counters provides alert counter support.
Sample program to show how the program can access a value of an unexported identifier from another package.
Sample program to show how the program can access a value of an unexported identifier from another package.
counters
Package counters provides alert counter support.
Package counters provides alert counter support.
Sample program to show how unexported fields from an exported struct type can't be accessed directly.
Sample program to show how unexported fields from an exported struct type can't be accessed directly.
users
Package users provides support for user management.
Package users provides support for user management.
Sample program to show how to create values from exported types with embedded unexported types.
Sample program to show how to create values from exported types with embedded unexported types.
users
Package users provides support for user management.
Package users provides support for user management.
exercises
exercise1
Create a package named toy with a single exported struct type named Toy.
Create a package named toy with a single exported struct type named Toy.
exercise1/toy
Package toy contains support for managing toy inventory.
Package toy contains support for managing toy inventory.
template1
Create a package named toy with a single exported struct type named Toy.
Create a package named toy with a single exported struct type named Toy.
template1/toy
Package toy contains support for managing toy inventory.
Package toy contains support for managing toy inventory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL