Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run go formatter and name packages #6790

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/src/counter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package greetings
package golang_examples

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion go/src/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module example/hello
module factory/golang-examples

go 1.22.5
41 changes: 20 additions & 21 deletions go/src/hello.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package greetings
package golang_examples

import (
"errors"
"fmt"
"math/rand"
"errors"
"fmt"
"math/rand"
)


// Hello returns a greeting for the named person.
func Hello(name string) (string, error) {
// If no name was given, return an error with a message.
if name == "" {
return name, errors.New("empty name")
}
// Create a message using a random format.
message := fmt.Sprintf(randomFormat(), name)
return message, nil
// If no name was given, return an error with a message.
if name == "" {
return name, errors.New("empty name")
}
// Create a message using a random format.
message := fmt.Sprintf(randomFormat(), name)
return message, nil
}

func main() {
fmt.Println("Hello, World!")
fmt.Println("Hello, World!")
}

// randomFormat returns one of a set of greeting messages. The returned
// message is selected at random.
func randomFormat() string {
// A slice of message formats.
formats := []string{
"Hi, %v. Welcome!",
"Great to see you, %v!",
"Hail, %v! Well met!",
}
// A slice of message formats.
formats := []string{
"Hi, %v. Welcome!",
"Great to see you, %v!",
"Hail, %v! Well met!",
}

// Return one of the message formats selected at random.
return formats[rand.Intn(len(formats))]
// Return one of the message formats selected at random.
return formats[rand.Intn(len(formats))]
}
21 changes: 8 additions & 13 deletions go/src/hello_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package greetings
package golang_examples

import (
"testing"
"time"
"testing"
"time"
)



// passes if the current minute is divisible by 2
func TestCurrentMinute(t *testing.T) {

currentTime := time.Now()
minute := currentTime.Minute()

currentTime := time.Now()
minute := currentTime.Minute()

if minute % 2 != 0 {
t.Errorf("Minute is not divisible by two.")
}
if minute%2 != 0 {
t.Errorf("Minute is not divisible by two.")
}
}


Loading