Go (golang) Tutorials - Packages and Commands

Published: 11 March 2018
on channel: Ambasoft Java
352
12

#golang #go #packages

Packages and Commands
-----------------------------

Concepts
--------

1.Dynamic Languages and Static Languages
Static :- C,C++, Go
Dynamic :- Javascript
2.Type system - Composition
relationship Has-a and Is-a
Go - 1.Vehicle (has) four wheels - Composition
2.Car (is a) Vehicle - Inheritance
3. From abov, 1+2 = Car (has) four wheels - Composition


Demonstration
----------------
1. Initialization - default values for int and string
int default "0"
string default ""
2. Commands - Executable Programs within main package
3. Packages
a) Main package and main method - Important and mandatory to create a go command (binary executable)
Code belongs to package main must have func main() declared on its body
b) strings package
4. Remote Imports - importing packages from remote locations
Bitbucket,github,etc
5. Named Imports - Alias declaration during import

Package - 1. Not necessarily needs to be a part of main package and no needs for this to contain a main method can't be executed on their own.
2. Using commands packages can be executed as supportive code
3. On Compilation, no binaries will be generated if there is no main() method found inside a go program
Command - 1. main Package with main() where the binary can be executed on its own

Code
------
mynewdemo.go
--------------
package main

import ("fmt"
str "strings" //Named Imports with Alias
)

func main(){
fmt.Println(str.ToUpper("Welcome to Show")) //try To Lower
fmt.Println(str.ToLower("CONVERT ME TO LOWER CASE"))
}


declarationdemo.go
-------------------
package main
import "fmt"
func main(){
var a int
var name string
fmt.Printf("Value of a is %d\n",a)
fmt.Printf("My name is %s .\n",name)
}

initdemo.go
-----------
package main

import "fmt"

func main(){
a:=10
b:=20
name:="Go Programming"
fmt.Printf("The output value is %d,%d\n",a,b)
fmt.Printf("My Name is %s\n",name)
}

Next : Custom Packages


Watch video Go (golang) Tutorials - Packages and Commands online, duration hours minute second in high quality that is uploaded to the channel Ambasoft Java 11 March 2018. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 352 times and liked it 12 visitors.