Last active
January 10, 2017 03:53
-
-
Save phpdave/632469ad1355a2e3a99366c2d4446109 to your computer and use it in GitHub Desktop.
Hello World Go Lang. Youtube https://www.youtube.com/watch?v=XCsL89YtqCs Docs https://golang.org/doc/code.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#WorkSpace | |
export GOPATH=$HOME/work | |
#Binaries produced by GO | |
export PATH=$PATH:$GOPATH/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── bin | |
│ └── hello | |
├── pkg | |
│ └── darwin_amd64 | |
│ └── github.com | |
│ └── phpdave | |
│ └── string.a | |
└── src | |
└── github.com | |
└── phpdave | |
├── hello | |
│ └── hello.go | |
└── string | |
├── string.go | |
└── string_test.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/phpdave/string" | |
) | |
func main() { | |
fmt.Printf(string.Reverse("\nHello I'm writing some go code\n")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package string | |
func Reverse(s string) string{ | |
//b:= []bytes(s) | |
//rune(s) used instead of byte(s) so UTF 8 characters work properly | |
b:= []rune(s) | |
for i := 0 ; i < len(b)/2; i++{ | |
j:= len(b)-i-1 | |
b[i], b[j] = b[j], b[i] | |
} | |
return string(b) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package string | |
import "testing" | |
func Test(t *testing.T) { | |
var tests = []struct { | |
s, want string | |
}{ | |
{"Backward","drawkcaB"}, | |
{"Hello You!", "!uoY olleH"}, | |
{"Hi क़","क़ iH"}, | |
} | |
for _, c := range tests { | |
got := Reverse(c.s) | |
if got != c.want { | |
t.Errorf("Reverse(%q) == %q, want %q", c.s, got, c.want) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment