Skip to content

Go Lang code and scripts, mostly for my education and practice

Notifications You must be signed in to change notification settings

acbrandao/GoLang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoLang

Go Lang code and scripts. Mostly for my learning and educational purposes. [Go - aka GoLan] is a compiled programming language developed at Google and popular for server side applications. The language is cross-platform and features a number of modern capabilities over traditional languages like C/C++ or Java. It's primarily intended to be run on server side applications, which makes its typical use case on par with languages like Java, C++ and Python.

Go is a programming language created at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson. Go is a statically typed compiled language in the tradition of C, with memory safety, garbage collection, structural typing, and CSP-style concurrent programming features added. The compiler, tools and source code are all free and open source (source Wikipedia)

learning code in src/ folder

Most of the files in the src/ folder are for learning pruposes, small snippets that allow me to learn a specific funciton of the language

Sample Golang program

Below is the simplest Go lang program , saved as hello.go

package main
import "fmt"

func main() {
        fmt.Printf("Hello\n")
}

In order to test run this command issue:

go run hello.go

If there are no syntax issues it shoudl run cleanly

Compiling in Windows or Linux

To create a windows executable (.exe) issue th ecommand below

> GOOS=windows GOARCH=386 go build -o hello.exe hello.go

For linux

GOOS=linux go build -o hello hello.go

Reduce Go binary sizes

Go binaries tend to be large , even for smallish source apps, this is primarily because Go applications contain a runtime which provides garbage collection, reflection and many other features (which your program might not really use, but it's there). And the implementation of the fmt package which you used to print the "Hello World" text (plus its dependencies). So most binaries start off in the 2MB to 6MB in size depending on what import (packages you include).

Some approaches to reduce binary size (mostly Linux) use the -s and -w linker flags to strip the debugging information like , reduces about 28% of binary size go build -ldflags "-s -w" -o hello hello.go

Next run upx a Linux Ultimate Packer for eXecutables utilitity , which essentially zips the executable into a running format, this should yield another 15% reduction in size.

go build -ldflags "-s -w" -o hello hello.go
upx --brute hello

For comparison on go version go1.10.4 linux/amd64

Program (Source) Adjustment File Type Size (MB)
hello.go none source code 87 bytes
hello none executable 2.0 MB
hello -ldflags "-s -w" execuable 1.2 MB
hello upx --brute executable 350kb

Go References web sites and links

About

Go Lang code and scripts, mostly for my education and practice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published