Skip to content

Commit 30b65c4

Browse files
committed
A bit refactored
1 parent efc9c6c commit 30b65c4

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ Generate artifacts(binary files and configs)
9696
make build
9797
```
9898

99+
Set APP_WD if you start to use html templates or path to ssh keys or run `make test`
100+
101+
```$xslt
102+
export APP_WD=go_path to project_path/resources or project_path/artifacts
103+
```
104+
99105
## Docker environment
100106

101107

@@ -153,13 +159,20 @@ Start health-check service
153159

154160
## Start in docker
155161

162+
#### Run this commands
156163
```$xslt
157164
docker-compose rm # Remove previous containers
158165
GOOS=linux GOARCH=amd64 make build # Generate binary file
159166
REMOVE_CONTAINERS=on DOCKER_IMAGE=golang-example-app TAG=development make docker-image # Generate new docker image
160167
docker-compose up
161168
```
162169

170+
#### or run script
171+
172+
```$xslt
173+
./scripts/docker-compose-start.sh
174+
```
175+
163176
# Getting Started
164177

165178
## Jaeger
@@ -250,7 +263,5 @@ mutation createUser {
250263

251264
# Testing
252265
```
253-
Set APP_WD for load templates as example if you use html pages in a project
254-
export APP_WD=go_path to project_path/resources or project_path/artifacts
255266
➜ make test
256267
```

app/db/domain/product.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package domain
22

33
type Product struct {
4-
ID int `gorm:"column:id"`
5-
Name string `gorm:"column:email"`
4+
ID int
5+
Name string
66
productItems []ProductItem
77
}

app/http_routers/products-router/router.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,32 @@ func (router *Router) GetProductsNats(w http.ResponseWriter, r *http.Request) {
6565
nc, err := nats.Connect(router.cfg.NatsURL)
6666
if err != nil {
6767
router.logger.Error(err.Error())
68+
http.Error(w, err.Error(), http.StatusInternalServerError)
69+
return
6870
}
6971
defer nc.Close()
7072

7173
sc, err := stan.Connect("test-cluster", "stan-pub", stan.NatsConn(nc))
74+
if err != nil {
75+
router.logger.Error(err.Error())
76+
http.Error(w, err.Error(), http.StatusInternalServerError)
77+
return
78+
}
79+
// Close connection
80+
defer sc.Close()
81+
7282
message := "Hello"
7383
router.logger.Printf("[NATS] send %s", message)
7484
err = sc.Publish(router.cfg.Subject, []byte(message))
85+
7586
if err != nil {
7687
router.logger.Printf("[ERROR] %s", err.Error())
88+
http.Error(w, err.Error(), http.StatusInternalServerError)
89+
return
7790
}
7891

79-
// Close connection
80-
sc.Close()
81-
8292
e := json.NewEncoder(w)
83-
e.Encode("")
93+
e.Encode("done")
8494
}
8595

8696
func (router *Router) GetProductsSlowly(w http.ResponseWriter, r *http.Request) {
File renamed without changes.

0 commit comments

Comments
 (0)