Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 55266b1

Browse files
author
Rajeev Kumar Singh
committed
code reorganization
1 parent f530491 commit 55266b1

File tree

54 files changed

+45
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+45
-23
lines changed

‎07-packages/app/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/callicoder/golang-tutorials/07-packages/numbers"
6+
"github.com/callicoder/golang-tutorials/07-packages/strings"
7+
"github.com/callicoder/golang-tutorials/07-packages/strings/greetings" // Importing a nested package
8+
str "strings" // Package Alias
9+
)
10+
11+
func main() {
12+
fmt.Println(numbers.IsPrime(19))
13+
14+
fmt.Println(greetings.WelcomeText)
15+
16+
fmt.Println(strings.Reverse("callicoder"))
17+
18+
fmt.Println(str.Count("Go is Awesome. I love Go", "Go"))
19+
}
File renamed without changes.

‎07-packages/strings/greetings/texts.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Nested Package
2+
package greetings
3+
4+
// Exported
5+
const WelcomeText = "Hello, World to Golang"
6+
const MorningText = "Good Morning"
7+
const EveningText = "Good Evening"
8+
9+
// Not exported (only visible inside the `greetings` package)
10+
var loremIpsumText = `Lorem ipsum dolor sit amet, consectetur adipiscing elit,
11+
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
12+
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
13+
commodo consequat.`

‎12-packages/strings/reverse.go renamed to ‎07-packages/strings/reverse.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ package strings
66
perform the reverse operation on that, and then re-cast to a string.
77
*/
88
func Reverse(s string) string {
9-
chars := []rune(s)
10-
for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
11-
chars[i], chars[j] = chars[j], chars[i]
12-
}
13-
return string(chars)
9+
runes := []rune(s)
10+
reversedRunes := reverseRunes(runes)
11+
return string(reversedRunes)
1412
}

‎07-packages/strings/reverse_runes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package strings
2+
3+
// Reverses an array of runes
4+
// This function is not exported (It is only visible inside the `strings` package)
5+
func reverseRunes(r []rune) []rune {
6+
for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
7+
r[i], r[j] = r[j], r[i]
8+
}
9+
return r
10+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /