GithubHelp home page GithubHelp logo

golang's Introduction

How to Run

Build Production Mode

go build <name_file>

Run Production Mode

./<exe_file>

Development Mode Fast Build and Run

go run <name_file>

Unit Test

  • have to use last name _test, for example: hello_world_test.go

  • the function firstname is Test.., for Example: TestHelloWorld()

  • add the parameter t *testing.T with no return value.

go test <path>
go test -v <path>   // -v use to show the logs
go test -v -run=<name_function> <path> -count=1   // -count to ignore caching

/*
** Either run all tests with go test -v or specify the source files that your test depends on, e.g.
*/
go test double.go double_test.go

Testing.T

  • Parameter for unit testing

  • Fail() failing the unit test but continue till finish.

  • FailNow() failing the unit test and stoppped at the same time.

  • Error() call Fail() with print an error as a logging.

  • Fatal() call FailNow() with print an error as a logging.

Testing.M

  • Parameter for testing in main

Testing.B

  • Parameter for brenchmarking

Goroutines

  • goroutine is pretty small, it work as concurrency instead of parallel.

channel

  • channel is an alternative to receive data by goroutine. it is being a tunnel to communicate with goroutine function. goroutine will be blocked untill the channel receive the data (blocking). The concept is similar with async await in javascript.
channel := make(chan int)
channel <- 19               // to assign the data
bufferData <- channel       // to give the data
  • channel only buffer one data. If want more, need another goroutine to create

  • please close channel if it's not used due to memory leak.

  • by default, the parameter is parsing the value. It is different with channel. If parsing the channel, it is automatically passing the reference.

  • channel is possible to give a sign in and out while parsing as parameter. chan<- for in and <-chan for out.

  • Buffered Channel use to buffer data whenever didn't available or in some case to handle sender faster than receiver.

channel := make(chan string, 3)   // create channel with 3 buffer long.

golang's People

Contributors

ramamimu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.