Skip to content

Commit 725d692

Browse files
author
Marvin
committed
'Changed the default greeting from main.go to Hello Marvin.'
1 parent 83153ba commit 725d692

File tree

2 files changed

+13
-48
lines changed

2 files changed

+13
-48
lines changed

main.go

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
11
package main
22

3-
import (
4-
"errors"
5-
"fmt"
6-
"net/http"
7-
"os"
8-
9-
"github.com/rs/cors"
10-
)
11-
12-
func main() {
13-
mux := http.NewServeMux()
14-
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
15-
fmt.Printf("got / request from %s\n", r.RemoteAddr)
16-
w.Header().Set("Content-Type", "application/json")
17-
_, err := w.Write([]byte(greeting()))
18-
if err != nil {
19-
panic(err)
20-
}
21-
})
22-
23-
c := cors.New(cors.Options{
24-
AllowedOrigins: []string{
25-
"http://greetings.kylepenfound.com",
26-
"https://dagger-demo.netlify.app",
27-
"http://localhost:8081",
28-
"http://localhost:1313",
29-
},
30-
// Enable Debugging for testing, consider disabling in production
31-
Debug: true,
32-
})
33-
handler := c.Handler(mux)
34-
err := http.ListenAndServe(":8080", handler)
35-
if errors.Is(err, http.ErrServerClosed) {
36-
fmt.Printf("server closed\n")
37-
} else if err != nil {
38-
fmt.Printf("error starting server: %s\n", err)
39-
os.Exit(1)
40-
}
41-
}
3+
import "fmt"
424

435
func greeting() string {
44-
greeting := "Greetings Daggernauts!"
45-
return fmt.Sprintf("{\"greeting\":\"%s\"}", greeting)
6+
return "Hello Marvin!"
467
}
8+
9+
func main() {
10+
fmt.Println(greeting())
11+
}

main_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
// main_test.go
12
package main
23

34
import (
45
"testing"
5-
6-
"gotest.tools/v3/assert"
76
)
87

98
func TestGreeting(t *testing.T) {
10-
g := greeting()
11-
should := "{\"greeting\":\"Greetings Daggernauts!\"}"
12-
13-
assert.Equal(t, should, g)
14-
}
9+
got := greeting()
10+
want := "Hello Marvin!"
11+
if got != want {
12+
t.Errorf("greeting() = %q, want %q", got, want)
13+
}
14+
}

0 commit comments

Comments
 (0)