Go basic operation

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Read the knowledge of go for a period of time, originally was directed at it is the system level language to go, at the same time have Java's appearance. After looking at this for a long time, I found this language is very good, the grammar is concise, has C's heredity. On the object-oriented, there is a bit of Java style. When it comes to writing the web, this style is so much like the Nodejs.

----------------------------------------------------------------

Well, let's start with the basics.

When the go language set environment variables, there is a very tangled thing: Gopath.

Gopath was the path to the project, and I felt it was too tangled at the beginning. If you switch the project path every time, do not set the environment variable. There's nothing to do with that. Always use idea to write go, today written, ready to compile, only to start looking at the problem again.

First put the environment variable memo:

Goroot=/usr/share/gopath=/usr/bin/go: $PATH

In fact, in the environment variable configuration, you do not need to set Gopath.

Raise a chestnut, start from scratch, and build a catalogue.

CD ~mkdir  myprocexport gopath=~/myproc

In this way, the MyProc is currently set to the project path. After the go get to the thing, it is in this directory.

MyProc to follow the structure, the following sub-three directories: Bin,src,pkg.

Here's an example directory layout:

Gopath=/home/user/gocode

/home/user/gocode/
src/
foo/
bar/(go code in package bar)
X.go
quux/(go code in package main)
Y.go
bin/
Quux (Installed command)
pkg/
linux_amd64/
foo/
BAR.A (Installed package object)

That's what the authorities say about these structures.

SRC put the source code, after writing, go build a bit better.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.