Skip to content

Commit aa7c90d

Browse files
committed
fix path problem
1 parent 565b9c6 commit aa7c90d

File tree

5 files changed

+88
-87
lines changed

5 files changed

+88
-87
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A gopher-friendly velib proxy
55
## Creating a module
66

77
```
8-
$ go mod init github.com/fagossa/golang-rest-api
8+
$ go mod init github.com/GolangParis/veligroxy
99
```
1010

1111

cmd/api/main.go

+83-83
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11
package main
22

33
import (
4-
"context"
5-
"net"
6-
"net/http"
7-
"os"
8-
"os/signal"
9-
"syscall"
10-
"time"
11-
12-
"github.com/sirupsen/logrus"
13-
14-
"github.com/fagossa/golang-rest-api/internal/routes"
15-
"github.com/fagossa/golang-rest-api/internal/version"
4+
"context"
5+
"net"
6+
"net/http"
7+
"os"
8+
"os/signal"
9+
"syscall"
10+
"time"
11+
12+
"github.com/sirupsen/logrus"
13+
14+
"github.com/GolangParis/veligroxy/internal/routes"
15+
"github.com/GolangParis/veligroxy/internal/version"
1616
)
1717

1818
func main() {
19-
logger := logrus.New().WithField("Version", version.Version).WithField("Commit", version.Commit)
20-
logger.Info("application is starting...")
21-
22-
// reading ports
23-
port := os.Getenv("PORT")
24-
if port == "" {
25-
logger.Fatal("Running port is not specified")
26-
}
27-
diagPort := os.Getenv("DIAG_PORT")
28-
if diagPort == "" {
29-
logger.Fatal("Diagnostic port is not specified")
30-
}
31-
32-
r := routes.BusinessRoutes()
33-
server := http.Server{
34-
Addr: net.JoinHostPort("", port),
35-
Handler: r,
36-
}
37-
38-
// diag routes
39-
diagRouter := routes.DiagnosticsRoutes()
40-
diag := http.Server{
41-
Addr: net.JoinHostPort("", diagPort),
42-
Handler: diagRouter,
43-
}
44-
45-
// error channel
46-
shutdown := make(chan error, 2)
47-
48-
// async start
49-
go func() {
50-
logger.Info("Business server is preparing...")
51-
err := server.ListenAndServe()
52-
if err != nil && err != http.ErrServerClosed {
53-
shutdown <- err
54-
}
55-
}()
56-
57-
go func() {
58-
logger.Info("Diagnostics server is preparing...")
59-
diag.ListenAndServe()
60-
err := server.ListenAndServe()
61-
if err != nil && err != http.ErrServerClosed {
62-
shutdown <- err
63-
}
64-
}()
65-
66-
// graceful shutdown
67-
interrupt := make(chan os.Signal, 1)
68-
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
69-
70-
select {
71-
case x := <-interrupt:
72-
logger.Warnf("Received `%v`. Application stopped.", x)
73-
74-
case err := <- shutdown:
75-
logger.Warnf("Received shudown message: `%v`", err)
76-
}
77-
78-
timeout, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
79-
defer cancelFunc()
80-
81-
err := server.Shutdown(timeout)
82-
if err != nil {
83-
logger.Error(err)
84-
}
85-
86-
errDiag := diag.Shutdown(timeout)
87-
if err != nil {
88-
logger.Error(errDiag)
89-
}
19+
logger := logrus.New().WithField("Version", version.Version).WithField("Commit", version.Commit)
20+
logger.Info("application is starting...")
21+
22+
// reading ports
23+
port := os.Getenv("PORT")
24+
if port == "" {
25+
logger.Fatal("Running port is not specified")
26+
}
27+
diagPort := os.Getenv("DIAG_PORT")
28+
if diagPort == "" {
29+
logger.Fatal("Diagnostic port is not specified")
30+
}
31+
32+
r := routes.BusinessRoutes()
33+
server := http.Server{
34+
Addr: net.JoinHostPort("", port),
35+
Handler: r,
36+
}
37+
38+
// diag routes
39+
diagRouter := routes.DiagnosticsRoutes()
40+
diag := http.Server{
41+
Addr: net.JoinHostPort("", diagPort),
42+
Handler: diagRouter,
43+
}
44+
45+
// error channel
46+
shutdown := make(chan error, 2)
47+
48+
// async start
49+
go func() {
50+
logger.Info("Business server is preparing...")
51+
err := server.ListenAndServe()
52+
if err != nil && err != http.ErrServerClosed {
53+
shutdown <- err
54+
}
55+
}()
56+
57+
go func() {
58+
logger.Info("Diagnostics server is preparing...")
59+
diag.ListenAndServe()
60+
err := server.ListenAndServe()
61+
if err != nil && err != http.ErrServerClosed {
62+
shutdown <- err
63+
}
64+
}()
65+
66+
// graceful shutdown
67+
interrupt := make(chan os.Signal, 1)
68+
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
69+
70+
select {
71+
case x := <-interrupt:
72+
logger.Warnf("Received `%v`. Application stopped.", x)
73+
74+
case err := <-shutdown:
75+
logger.Warnf("Received shudown message: `%v`", err)
76+
}
77+
78+
timeout, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
79+
defer cancelFunc()
80+
81+
err := server.Shutdown(timeout)
82+
if err != nil {
83+
logger.Error(err)
84+
}
85+
86+
errDiag := diag.Shutdown(timeout)
87+
if err != nil {
88+
logger.Error(errDiag)
89+
}
9090

9191
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/fagossa/golang-rest-api
1+
module github.com/GolangParis/veligroxy
22

33
go 1.13
44

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github.com/GolangParis/veligroxy v0.0.0-20191003190835-ae2c3446fa4e h1:WmNGqTe9ZeRTnTnXpdEG7nIKq3m/j8LM9dk39mSQebY=
12
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
23
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
34
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=

internal/routes/routes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package routes
22

33
import (
4-
"github.com/fagossa/golang-rest-api/internal/controllers"
5-
"github.com/fagossa/golang-rest-api/internal/diagnostics"
4+
"github.com/GolangParis/veligroxy/internal/controllers"
5+
"github.com/GolangParis/veligroxy/internal/diagnostics"
66
"github.com/gorilla/mux"
77
)
88

0 commit comments

Comments
 (0)