-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (54 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"context"
"dogovor.alif.tj/routes"
"dogovor.alif.tj/utils"
"errors"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"sync"
)
var storagePathPtr = flag.String("storage", "exel-reports", "folder for storing files")
func main() {
r := routes.Router()
createStorageFolder()
svc := http.Server{
Handler: utils.AddCors(r),
Addr: ":3949",
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
exitCh := make(chan os.Signal, 1)
signal.Notify(exitCh, os.Interrupt, os.Kill)
<-exitCh
err := svc.Shutdown(context.Background())
if err != nil {
log.Println("ERROR server shutdown: ", err)
}
close(exitCh)
}()
fmt.Println("Server is start to listening on port: ", svc.Addr)
err := svc.ListenAndServe()
if err != nil {
if !errors.Is(err, http.ErrServerClosed) {
fmt.Println(err)
log.Fatal("ERROR in running process server: ", err)
}
}
wg.Wait()
fmt.Println("Server gracefully shut downed")
}
func createStorageFolder() {
err := os.Mkdir(*storagePathPtr, 0666)
if err != nil {
if !os.IsExist(err) {
log.Fatalf("ERROR can't create directory: %s", err)
}
}
}