Skip to content

Commit

Permalink
code linted through dir 22_go-routines
Browse files Browse the repository at this point in the history
  • Loading branch information
GoesToEleven committed Nov 26, 2015
1 parent 0ca46d6 commit 4262dbc
Show file tree
Hide file tree
Showing 43 changed files with 188 additions and 231 deletions.
2 changes: 1 addition & 1 deletion 08_pointers/01_referencing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
fmt.Println(a)
fmt.Println(&a)

var b *int = &a
var b = &a

fmt.Println(b)

Expand Down
2 changes: 1 addition & 1 deletion 08_pointers/02_dereferencing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func main() {
fmt.Println(a) // 43
fmt.Println(&a) // 0x20818a220

var b *int = &a
var b = &a
fmt.Println(b) // 0x20818a220
fmt.Println(*b) // 43

Expand Down
2 changes: 1 addition & 1 deletion 08_pointers/03_using-pointers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func main() {
fmt.Println(a) // 43
fmt.Println(&a) // 0x20818a220

var b *int = &a
var b = &a
fmt.Println(b) // 0x20818a220
fmt.Println(*b) // 43

Expand Down
7 changes: 4 additions & 3 deletions 11_switch-statements/05_on-type/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import "fmt"
// -- normally we switch on value of variable
// -- go allows you to switch on type of variable

type Contact struct {
type contact struct {
greeting string
name string
}

// SwitchOnType works with interfaces
// we'll learn more about interfaces later
func SwitchOnType(x interface{}) {
switch x.(type) { // this is an assert; asserting, "x is of this type"
case int:
fmt.Println("int")
case string:
fmt.Println("string")
case Contact:
case contact:
fmt.Println("contact")
default:
fmt.Println("unknown")
Expand All @@ -29,7 +30,7 @@ func SwitchOnType(x interface{}) {
func main() {
SwitchOnType(7)
SwitchOnType("McLeod")
var t = Contact{"Good to see you,", "Tim"}
var t = contact{"Good to see you,", "Tim"}
SwitchOnType(t)
SwitchOnType(t.greeting)
SwitchOnType(t.name)
Expand Down
6 changes: 3 additions & 3 deletions 14_functions/15_passing-by-value/07_struct-pointer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package main

import "fmt"

type Customer struct {
type customer struct {
name string
age int
}

func main() {
c1 := Customer{"Todd", 44}
c1 := customer{"Todd", 44}
fmt.Println(&c1.name) // 0x8201e4120

changeMe(&c1)
Expand All @@ -17,7 +17,7 @@ func main() {
fmt.Println(&c1.name) // 0x8201e4120
}

func changeMe(z *Customer) {
func changeMe(z *customer) {
fmt.Println(z) // &{Todd 44}
fmt.Println(&z.name) // 0x8201e4120
z.name = "Rocky"
Expand Down
16 changes: 15 additions & 1 deletion 18_slice/05_slicing-a-slice/01/main.go
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
package _1
package main

import "fmt"

func main() {

var results []int
fmt.Println(results)

mySlice := []string{"a", "b", "c", "g", "m", "z"}
fmt.Println(mySlice)
fmt.Println(mySlice[2:4]) // slicing a slice
fmt.Println(mySlice[2]) // index access; accessing by index
fmt.Println("myString"[2]) // index access; accessing by index
}
26 changes: 18 additions & 8 deletions 18_slice/05_slicing-a-slice/02/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import "fmt"

func main() {

var results []int
fmt.Println(results)

mySlice := []string{"a", "b", "c", "g", "m", "z"}
fmt.Println(mySlice)
fmt.Println(mySlice[2:4]) // slicing a slice
fmt.Println(mySlice[2]) // index access; accessing by index
fmt.Println("myString"[2]) // index access; accessing by index
greeting := []string{
"Good morning!",
"Bonjour!",
"dias!",
"Bongiorno!",
"Ohayo!",
"Selamat pagi!",
"Gutten morgen!",
}

fmt.Print("[1:2] ")
fmt.Println(greeting[1:2])
fmt.Print("[:2] ")
fmt.Println(greeting[:2])
fmt.Print("[5:] ")
fmt.Println(greeting[5:])
fmt.Print("[:] ")
fmt.Println(greeting[:])
}
25 changes: 0 additions & 25 deletions 18_slice/05_slicing-a-slice/03/main.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func main() {
records := make([][]string, 0)
var records [][]string
// student 1
student1 := make([]string, 4)
student1[0] = "Foster"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func main() {
transactions := make([][]int, 0, 3)

for i := 0; i < 3; i++ {
transaction := make([]int, 0)
transaction := make([]int, 0, 4)
for j := 0; j < 4; j++ {
transaction = append(transaction, j)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import "fmt"

func main() {
n := HashBucket("Go", 12)
n := hashBucket("Go", 12)
fmt.Println(n)
}

func HashBucket(word string, buckets int) int {
func hashBucket(word string, buckets int) int {
letter := int(word[0])
bucket := letter % buckets
return bucket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
buckets := make([]int, 200)
// Loop over the words
for scanner.Scan() {
n := HashBucket(scanner.Text())
n := hashBucket(scanner.Text())
buckets[n]++
}
fmt.Println(buckets[65:123])
Expand All @@ -33,6 +33,6 @@ func main() {
// }
}

func HashBucket(word string) int {
func hashBucket(word string) int {
return int(word[0])
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func main() {
buckets := make([]int, 12)
// Loop over the words
for scanner.Scan() {
n := HashBucket(scanner.Text(), 12)
n := hashBucket(scanner.Text(), 12)
buckets[n]++
}
fmt.Println(buckets)
}

func HashBucket(word string, buckets int) int {
func hashBucket(word string, buckets int) int {
letter := int(word[0])
bucket := letter % buckets
return bucket
Expand Down
4 changes: 2 additions & 2 deletions 19_map/14_hash-table/02_even-dstribution-hash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func main() {
buckets := make([]int, 12)
// Loop over the words
for scanner.Scan() {
n := HashBucket(scanner.Text(), 12)
n := hashBucket(scanner.Text(), 12)
buckets[n]++
}
fmt.Println(buckets)
}

func HashBucket(word string, buckets int) int {
func hashBucket(word string, buckets int) int {
var sum int
for _, v := range word {
sum += int(v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
// Loop over the words
for scanner.Scan() {
word := scanner.Text()
n := HashBucket(word, 12)
n := hashBucket(word, 12)
buckets[n] = append(buckets[n], word)
}
// Print len of each bucket
Expand All @@ -39,7 +39,7 @@ func main() {
// fmt.Println(buckets[6])
}

func HashBucket(word string, buckets int) int {
func hashBucket(word string, buckets int) int {
var sum int
for _, v := range word {
sum += int(v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
// Loop over the words
for scanner.Scan() {
word := scanner.Text()
n := HashBucket(word, 12)
n := hashBucket(word, 12)
buckets[n][word]++
}
// Print words in a bucket
Expand All @@ -40,7 +40,7 @@ func main() {
}
}

func HashBucket(word string, buckets int) int {
func hashBucket(word string, buckets int) int {
var sum int
for _, v := range word {
sum += int(v)
Expand Down
2 changes: 1 addition & 1 deletion 19_map/14_hash-table/04_english-alphabet/02/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
}

i := 0
for k, _ := range words {
for k := range words {
fmt.Println(k)
if i == 200 {
break
Expand Down
14 changes: 7 additions & 7 deletions 20_struct/04_embedded-types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import (
"fmt"
)

type Person struct {
type person struct {
First string
Last string
Age int
}

type DoubleZero struct {
Person
type doubleZero struct {
person
LicenseToKill bool
}

func main() {
p1 := DoubleZero{
Person: Person{
p1 := doubleZero{
person: person{
First: "James",
Last: "Bond",
Age: 20,
},
LicenseToKill: true,
}

p2 := DoubleZero{
Person: Person{
p2 := doubleZero{
person: person{
First: "Miss",
Last: "MoneyPenny",
Age: 19,
Expand Down
18 changes: 9 additions & 9 deletions 20_struct/05_promotion/01_overriding-fields/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"fmt"
)

type Person struct {
type person struct {
First string
Last string
Age int
}

type DoubleZero struct {
Person
type doubleZero struct {
person
First string
LicenseToKill bool
}

func main() {
p1 := DoubleZero{
Person: Person{
p1 := doubleZero{
person: person{
First: "James",
Last: "Bond",
Age: 20,
Expand All @@ -27,8 +27,8 @@ func main() {
LicenseToKill: true,
}

p2 := DoubleZero{
Person: Person{
p2 := doubleZero{
person: person{
First: "Miss",
Last: "MoneyPenny",
Age: 19,
Expand All @@ -38,6 +38,6 @@ func main() {
}

// fields and methods of the inner-type are promoted to the outer-type
fmt.Println(p1.First, p1.Person.First)
fmt.Println(p2.First, p2.Person.First)
fmt.Println(p1.First, p1.person.First)
fmt.Println(p2.First, p2.person.First)
}
Loading

0 comments on commit 4262dbc

Please sign in to comment.