-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (45 loc) · 1.24 KB
/
main.go
File metadata and controls
54 lines (45 loc) · 1.24 KB
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
package main
import (
"encoding/json"
"fmt"
"gorestsocket/cmd/app"
"gorestsocket/cmd/model"
"gorestsocket/cmd/service"
"gorestsocket/cmd/util"
"net/http"
"os"
"path/filepath"
"time"
)
func init() {
if model.Shared != nil {
return
}
basePath, err := os.ReadFile(filepath.Join("configs", "config.json"))
if err != nil {
util.LogError(fmt.Sprintf("Error when read config or '%v'", err))
}
err = json.Unmarshal(basePath, &model.Shared)
if err != nil {
util.LogError(fmt.Sprintf("Error when decode config or '%v'", err))
}
}
func main() {
router := &service.Middleware{}
app.RouterHandler(router)
shared := model.GetConfig()
address := fmt.Sprintf(":%d", shared.Server.Port)
server := &http.Server{
Addr: address,
Handler: router,
ReadTimeout: time.Duration(shared.Server.ReadTimeout) * time.Second,
WriteTimeout: time.Duration(shared.Server.WriteTimeout) * time.Second,
}
util.LogDebug(fmt.Sprintf("⇨ Listening and serving HTTP on %s", address))
util.LogDebug(fmt.Sprintf("Read Timeout : %s", server.ReadTimeout))
util.LogDebug(fmt.Sprintf("Write Timeout : %s", server.WriteTimeout))
err := server.ListenAndServe()
if err != nil {
util.LogError(fmt.Sprintf("Error when start server - %v", err.Error()))
}
}