Go - Package (Import)

Card Puncher Data Processing

About

Package in Go.

Go treats files in a single directory as belonging to one package as long as they all have the same name in their package declarations.

Go code is organized into packages (similar to libraries or modules).

Package names are always in lower case.

Properties

Name

The first statement in a Go source file must be

package name

Go's convention is that the package name is the last element of the import path. See below.

Executable commands must always use package main.

Import Path (Package Id)

An import path is a string that uniquely identifies a package.

A package's import path corresponds to its location:

  • inside a workspace
  • or in a remote repository

The packages from the standard library are given short import paths such as “fmt” and “net/http”.

import (
	"fmt"
	"base-path/package-name/go-source-file"
)

The import statement tell the compiler what packages are needed by the source file.

Base Path

The base path is the root path of (custom|user) package (not standard library or other external libraries)

Description

By convention, each package is described in a comment immediately preceding its package declaration.

Management

Dependency Manager

Dependency manager

  • godep
  • glide
  • govendor
  • gopm
  • gb

Installation

go get base_path/package-name

where:

Search / Analytics





Discover More
Card Puncher Data Processing
Go

has: garbage collection, a package system, first-class functions, lexical scope, a system call interface, and immutable strings in which text is generally encoded in UTF-8. But it has...
Card Puncher Data Processing
Go - (Package) main

in Go. Package main is special. It defines a standalone executable program, not a library. Reprint the argument. Os.Args is an array 0134190440Donovan, Alan, Kernighan, Brian W. - The...
Card Puncher Data Processing
Go - Base Path (Package Root)

The base path is the root path of (custom|user) package (ie not go standard library or other external libraries) For example: if you have a GitHub account at github.com/user, you can choose it as...
Card Puncher Data Processing
Go - Formatting

The Go source script has a standard format defined by the Go team. Why ? Because : it eliminates a lot of pointless debate trivia and, more importantly, enables a variety of automated source code...
Card Puncher Data Processing
Go - Grammar Parsing

Go Script structure: The import declarations must follow the package declaration. The declarations of functions, variables, constants, and types (introduced by the keywords func, var, const, and...
Card Puncher Data Processing
Go - Testing

Go has a lightweight test framework composed of: the go test command and the testing package. Create a file myGoFile_test.go in the same directory that the file to test myGoFile To add a setup...
Card Puncher Data Processing
Go - go (The Go tool)

The go tool builds source packages and installs the resulting binaries to the pkg and bin directories of the workspace The go tool will only print output when an error occurs....



Share this page:
Follow us:
Task Runner