Skip to content

Commit a39a895

Browse files
author
Valery Piashchynski
committed
Fix sample_1. Add graph.png representing sample_1 graph
1 parent e12a34d commit a39a895

File tree

7 files changed

+58
-47
lines changed

7 files changed

+58
-47
lines changed

examples/sample_1/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
examples_bolt_db

examples/sample_1/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/spiral/endure/examples/db_http_logger
22

3-
go 1.14
3+
go 1.15
44

55
require (
66
github.com/NYTimes/gziphandler v1.1.1
77
github.com/gorilla/mux v1.7.4
88
github.com/rs/cors v1.7.0
9-
github.com/spiral/endure v1.0.0-beta6
9+
github.com/spiral/endure v1.0.0-beta10
1010
go.etcd.io/bbolt v1.3.5
1111
)

examples/sample_1/go.sum

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
44
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
5-
github.com/cenkalti/backoff/v4 v4.0.2 h1:JIufpQLbh4DkbQoii76ItQIUFzevQSqOLZca4eamEDs=
6-
github.com/cenkalti/backoff/v4 v4.0.2/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
5+
github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
6+
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
7+
github.com/corona10/goimagehash v1.0.2 h1:pUfB0LnsJASMPGEZLj7tGY251vF+qLGqOgEP4rUs6kA=
8+
github.com/corona10/goimagehash v1.0.2/go.mod h1:/l9umBhvcHQXVtQO1V6Gp1yD20STawkhRnnX0D1bvVI=
79
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
810
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
911
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1012
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
14+
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
15+
github.com/goccy/go-graphviz v0.0.8 h1:hYQikvj368s8+rmfzFOZeiCXvSocGH7rfAyLTOy/7AM=
16+
github.com/goccy/go-graphviz v0.0.8/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk=
17+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
18+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
1119
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
1220
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
1321
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
22+
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
1423
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
1524
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1625
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
1726
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1827
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
1928
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
29+
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
30+
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
2031
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2132
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
2233
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -25,8 +36,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
2536
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
2637
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
2738
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
28-
github.com/spiral/endure v1.0.0-beta6 h1:Kl8xHM/7sSCfpaBndJnJ1zaHVcEeug05OeiemauczwA=
29-
github.com/spiral/endure v1.0.0-beta6/go.mod h1:ZqOMVUfVNlUKzhO3WpbqTqV4q4fKOJG8qCyqBYvmL6g=
3039
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3140
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
3241
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -41,10 +50,14 @@ go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
4150
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
4251
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
4352
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
44-
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
45-
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
53+
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
54+
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
4655
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4756
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
57+
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
58+
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
59+
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
60+
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
4861
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
4962
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
5063
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
@@ -67,6 +80,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
6780
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
6881
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6982
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
83+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
7084
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
7185
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
7286
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

examples/sample_1/graph.png

26.4 KB
Loading

examples/sample_1/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55
"os/signal"
6+
"syscall"
67

78
"github.com/spiral/endure"
89
"github.com/spiral/endure/examples/db_http_logger/modules/db"
@@ -13,7 +14,7 @@ import (
1314
)
1415

1516
func main() {
16-
container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true))
17+
container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true), endure.PrintGraph(true))
1718
if err != nil {
1819
panic(err)
1920
}
@@ -49,13 +50,13 @@ func main() {
4950
}
5051

5152
// stop by CTRL+C
52-
c := make(chan os.Signal)
53-
signal.Notify(c, os.Interrupt)
53+
c := make(chan os.Signal, 1)
54+
signal.Notify(c, os.Interrupt, syscall.SIGKILL, syscall.SIGINT)
5455

5556
for {
5657
select {
5758
case e := <-errCh:
58-
println(e.Error.Err.Error())
59+
println(e.Error.Error())
5960
er := container.Stop()
6061
if er != nil {
6162
panic(er)

examples/sample_1/modules/db/db_layer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Repository interface {
2121
func (db *DB) Init(logger logger.SuperLogger) error {
2222
logger.SuperLogToStdOut("initializing DB")
2323
db.logger = logger
24-
db.path = "./examples"
24+
db.path = "./examples_bolt_db"
2525
bdb, err := bolt.Open(db.path, 0666, nil)
2626
if err != nil {
2727
return err

examples/sample_1/modules/http/http_layer.go

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ func (h *Http) Init(db db.Repository, logger logger.SuperLogger) error {
3838
h.client = client
3939
h.db = db
4040
h.logger = logger
41+
42+
h.logger.SuperLogToStdOut("configuring http")
43+
r := mux.NewRouter()
44+
45+
c := cors.New(cors.Options{
46+
AllowedOrigins: []string{"*"},
47+
AllowCredentials: true,
48+
AllowedMethods: []string{"GET", "HEAD", "POST", "PUT", "OPTIONS"},
49+
AllowedHeaders: []string{"*"},
50+
})
51+
52+
r.Methods("POST").HandlerFunc(h.update).Path("/update")
53+
r.Methods("POST").HandlerFunc(h.ddelete).Path("/delete")
54+
r.Methods("GET").HandlerFunc(h.sselect).Path("/select")
55+
r.Methods("POST").HandlerFunc(h.insert).Path("/insert")
56+
57+
// just as sample, we put server here
58+
server := &http.Server{
59+
Addr: ":8080",
60+
Handler: c.Handler(r),
61+
ReadTimeout: 10 * time.Second,
62+
WriteTimeout: 10 * time.Second,
63+
MaxHeaderBytes: 1 << 20,
64+
}
65+
66+
h.server = server
67+
4168
return nil
4269
}
4370

@@ -73,36 +100,6 @@ func (h *Http) Stop() error {
73100
return nil
74101
}
75102

76-
func (h *Http) Configure() error {
77-
h.logger.SuperLogToStdOut("configuring http")
78-
r := mux.NewRouter()
79-
80-
c := cors.New(cors.Options{
81-
AllowedOrigins: []string{"*"},
82-
AllowCredentials: true,
83-
AllowedMethods: []string{"GET", "HEAD", "POST", "PUT", "OPTIONS"},
84-
AllowedHeaders: []string{"*"},
85-
})
86-
87-
r.Methods("POST").HandlerFunc(h.update).Path("/update")
88-
r.Methods("POST").HandlerFunc(h.ddelete).Path("/delete")
89-
r.Methods("GET").HandlerFunc(h.sselect).Path("/select")
90-
r.Methods("POST").HandlerFunc(h.insert).Path("/insert")
91-
92-
// just as sample, we put server here
93-
server := &http.Server{
94-
Addr: ":8080",
95-
Handler: c.Handler(r),
96-
ReadTimeout: 10 * time.Second,
97-
WriteTimeout: 10 * time.Second,
98-
MaxHeaderBytes: 1 << 20,
99-
}
100-
101-
h.server = server
102-
103-
return nil
104-
}
105-
106103
func (h *Http) Depends() []interface{} {
107104
return []interface{}{
108105
h.AddMiddleware,
@@ -114,9 +111,6 @@ func (h *Http) AddMiddleware(m Middleware) error {
114111
return nil
115112
}
116113

117-
func (h *Http) Close() error {
118-
return nil
119-
}
120114

121115
///////////////// INFRA HANDLERS //////////////////////////////
122116

@@ -137,7 +131,7 @@ func (h *Http) sselect(writer http.ResponseWriter, request *http.Request) {
137131
writer.WriteHeader(http.StatusOK)
138132

139133
for i := 0; i < 10000; i++ {
140-
writer.Write([]byte("TEST_GZIP_HEADERS"))
134+
_, _ = writer.Write([]byte("TEST_GZIP_HEADERS"))
141135
}
142136

143137
}

0 commit comments

Comments
 (0)