티스토리 뷰

Technology/Golang

Get Started to be a Gopher~!

캡틴테크 2017. 5. 20. 15:26
반응형

Have you heard about 'Go'?, I don't mean you have to go out haha. 'Go' is kind a name of language which makes me feel happy in these-day. Go is made by 'Goolge' and a kind of compile language. Literally, Go has strong points like garbage collection and concurrency. A number of Developers have been struggling to handle memory and Java developers are getting increase due to this reason. However Go is familiar with C developers I guess. Anyway Go project is started since 2007 in Google and 1.8 version was released in Feb, 2017. Briefly, I would like explain What is the purpose.

# Purpose of Go

Go tries to take an advantage of static compiler language like efficiency and easiness of dynamic language. Software market is getting bigger and bigger and requiring the people who are able to developer software program because of fast growing in technologies area.

There is 4 parts of purpose officially.

  • Safety : Type and memory safety.
  • Concurrency and prominent libraries of communication. 
  • Effective garbage collection
  • Compile time 
I am used to develop with C language because I am in change of developing with hardware targets like mobile, printer, watch etc. When I developed with javascript I thought It's pretty simple but has abundant resources. If I make the same functionalities with C language, It would have put tremendous effort. 

# Let's see more
Detailed, I will point out a few things about Go programming. In order to provide concurrency in the code, provides 'go' and 'select' keywords. Plus map, array slice, channel for threading communication.  

Well, What are you going to do if you read till it?, Yes, make a code like 'Hello World'.

package main
 
import "fmt"
 
func main() {
        fmt.Println("Hello, World")
}

What strikes me out when I made a code is 'is it java?' But it is the just start. We can see more about Go's favor and can't forget it if we use it once.

# Understanding environment

Go developers are used to maintain their codes in single workspace. Each repository includes one more package and each package consists of several go source files. The path of packages will make a decision where we should import. Here is structure of workspace.

  • src : Location of go sources
  • pkg : Object of packages
  • bin : execution files like commands.
If we build with go tool, go toll will install the pkg and bin in each directory. 
bin/
    hello                      # command 실행 프로그램
    outyet                     # command 실행 프로그램
pkg/
    linux_amd64/
        github.com/golang/example/
            stringutil.a       # 패키지 객체
src/
    github.com/golang/example/
        .git/                      # Git 저장소 메타 데이터
    hello/
        hello.go               # command 소스
    outyet/
        main.go                # command 소스
        main_test.go           # 테스트 소스
    stringutil/
        reverse.go             # 패키지 소스
        reverse_test.go        # 테스트 소스
    golang.org/x/image/
        .git/                      # Git 저장소 메타 데이터
    bmp/
        reader.go              # 패키지 소스
        writer.go              # 패키지 소스 

Assume, you install Go compiler in you PC and set up the path for GOROOT. You can see the result if you type 'go env' in everywhere in you PC.

$ go env

set GOARCH=amd64

set GOBIN=

set GOEXE=.exe

set GOHOSTARCH=amd64

set GOHOSTOS=windows

set GOOS=windows

set GOPATH=C:\Users\Administrator\source\goproject

set GORACE=

set GOROOT=C:\Go

set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64

set CC=gcc

set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0

set CXX=g++

set CGO_ENABLED=1

but you have to set up the GOPATH for taking reference with library packages. Make the folder that you want to work with Go and set up the path like below.

$ mkdir $HOME/work 

$ export GOPATH=$HOME/work

You code will be a main program other wise library package to refer from other main program. Also you can take some library from github which is updated from somebody.

# To be Gopher~!

Gopher

Do you know what it is? It's is kind a rat but pretty cute. Go is able to build based arm. So you can utilize it in arm target though. Don't you feel exciting? If you are developer based on linux, you can use syscall api easier than other languages. Not sure how much better the language than others, but Go is marvelous language. I hope that I will be a gopher !!!

# Reference

https://golang.org

https://en.wikipedia.org/wiki/Go_(programming_language)

반응형
댓글