Skip to content

Instantly share code, notes, and snippets.

@joshuaaguilar20
Last active September 4, 2019 15:31
Show Gist options
  • Save joshuaaguilar20/36f201fbc3a2434842d351f345516b1e to your computer and use it in GitHub Desktop.
Save joshuaaguilar20/36f201fbc3a2434842d351f345516b1e to your computer and use it in GitHub Desktop.
Deep D Week 3 Go Lang
#1 Understand the Native Modules Provided
#2 Go is based on using native modules as opposed to using NPM
Link To Documents
https://golang.org/pkg/
Tuff Concepts
-Concurrency
-Syntax
-Pointers
-Structs
Starter Concepts
--Function in GO Syntax
//Every Go Project Starts With Package Main
//Must Have Package Main and then Main Function*
package main
import "fmt"
//Ways to Define variables Inside of GO
func main(){
//Type long form method
//var card string = "Some Random String"
//Alternative Way must be creating variable
card := "Ace of Spades"
newCard:= newCard();
fmt.println(card)
}
func newCard() string {
return "Five of Diamonds"
}
//Slice and Arr
//Every Element in Slice Must be the Same Type*
cards := [] string{newCard(),"some Other Card" }
//To Add Onto Slice
cards = append(cards, "Six of Diamonds");
//How to Loop Over Slice of Cards
for i, card := range cards {
fmt.println(card)
func main(){
//Type long form method
//var card string = "Some Random String"
//Alternative Way must be creating variable
cardGen := newCard();
fmt.Print(cardGen);
getInput()
//Slice and Arr
//Every Element in Slice Must be the Same Type*
cards := [] string{newCard(),"some Other Card" }
//To Add Onto Slice
cards = append(cards, "Six of Diamonds");
//How to Loop Over Slice of Cards
for i, card := range cards {
fmt.Println(card[i])
}
}
func newCard() string {
return "Five of Diamonds"
}
func getInput(){
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text, _ := reader.ReadString('\n')
fmt.Println(text)
}
@joshuaaguilar20
Copy link
Author

goDiagram

@joshuaaguilar20
Copy link
Author

How Every Go Project Will Start
flow

@joshuaaguilar20
Copy link
Author

Project
cards

@joshuaaguilar20
Copy link
Author

joshuaaguilar20 commented Sep 4, 2019

//Every Go Project Starts With Package Main
//Must Have Package Main and then Main Function*
package main
import (
"fmt"
"bufio"
"os"
"strings"
)
//Ways to Define variables Inside of GO

//Get an Input from the user and check to see if its a prime number or not.

func main(){
getInput()
}

func getInput(){
reader:= bufio.NewReader(os.Stdin)
fmt.Print("What's Your First Name:")
text, _ := reader.ReadString('\n')

name:= text
fmt.Print(name)
if strings.TrimRight(text, "\n") == "Deep" {
fmt.Print("Welcome Deep")
} else {
fmt.Println(text)
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment