File tree 5 files changed +56
-5
lines changed
cmd/golang-docker-build-tutorial
5 files changed +56
-5
lines changed Original file line number Diff line number Diff line change @@ -6,17 +6,23 @@ import (
6
6
"net/http"
7
7
8
8
"github.com/gorilla/mux"
9
+
10
+ internal "github.com/miguno/golang-docker-build-tutorial/internal/pkg"
9
11
)
10
12
11
- // Response is just a very basic example.
13
+ // Response is just a basic example.
12
14
type Response struct {
13
15
Status string `json:"status,omitempty"`
14
16
}
15
17
16
- // GetStatus returns always the same response.
17
18
func GetStatus (w http.ResponseWriter , _ * http.Request ) {
18
- b := Response {Status : "idle" }
19
- json .NewEncoder (w ).Encode (b )
19
+ var response Response
20
+ if internal .IsIdleToyFunction () {
21
+ response = Response {Status : "idle" }
22
+ } else {
23
+ response = Response {Status : "busy" }
24
+ }
25
+ json .NewEncoder (w ).Encode (response )
20
26
}
21
27
22
28
func main () {
Original file line number Diff line number Diff line change @@ -2,4 +2,14 @@ module github.com/miguno/golang-docker-build-tutorial
2
2
3
3
go 1.19
4
4
5
- require github.com/gorilla/mux v1.8.0
5
+ require (
6
+ github.com/gorilla/mux v1.8.0
7
+ github.com/stretchr/testify v1.8.1
8
+ )
9
+
10
+ require (
11
+ github.com/davecgh/go-spew v1.1.1 // indirect
12
+ github.com/pmezard/go-difflib v1.0.0 // indirect
13
+ github.com/stretchr/objx v0.5.0 // indirect
14
+ gopkg.in/yaml.v3 v3.0.1 // indirect
15
+ )
Original file line number Diff line number Diff line change
1
+ github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
2
+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
3
+ github.com/davecgh/go-spew v1.1.1 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
1
4
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI =
2
5
github.com/gorilla/mux v1.8.0 /go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So =
6
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
7
+ github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
8
+ github.com/stretchr/objx v0.1.0 /go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME =
9
+ github.com/stretchr/objx v0.4.0 /go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw =
10
+ github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c =
11
+ github.com/stretchr/objx v0.5.0 /go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo =
12
+ github.com/stretchr/testify v1.7.1 /go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg =
13
+ github.com/stretchr/testify v1.8.0 /go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU =
14
+ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk =
15
+ github.com/stretchr/testify v1.8.1 /go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4 =
16
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
17
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
18
+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
19
+ gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
Original file line number Diff line number Diff line change
1
+ package internal
2
+
3
+ // To demonstrate having some code that can be unit-tested.
4
+ func IsIdleToyFunction () bool {
5
+ return true
6
+ }
Original file line number Diff line number Diff line change
1
+ package internal
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ // To demonstrate how to integrate unit testing in a project.
10
+ func TestIsIdleToyFunction (t * testing.T ) {
11
+ assert .True (t , IsIdleToyFunction ())
12
+ }
You can’t perform that action at this time.
0 commit comments