-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (48 loc) · 1.59 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
package main
import (
"fmt"
"log"
"syscall"
"github.com/stevenlee87/go-gin-example/models"
"github.com/stevenlee87/go-gin-example/pkg/gredis"
"github.com/stevenlee87/go-gin-example/pkg/logging"
"github.com/fvbock/endless"
"github.com/stevenlee87/go-gin-example/pkg/setting"
"github.com/stevenlee87/go-gin-example/routers"
)
func main() {
//router := routers.InitRouter()
//
//s := &http.Server{
// Addr: fmt.Sprintf(":%d", setting.HTTPPort),
// Handler: router,
// ReadTimeout: setting.ReadTimeout,
// WriteTimeout: setting.WriteTimeout,
// MaxHeaderBytes: 1 << 20,
//}
//
//s.ListenAndServe()
setting.Setup()
models.Setup()
logging.Setup()
gredis.Setup()
endless.DefaultReadTimeOut = setting.ServerSetting.ReadTimeout
endless.DefaultWriteTimeOut = setting.ServerSetting.WriteTimeout
endless.DefaultMaxHeaderBytes = 1 << 20
endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort)
server := endless.NewServer(endPoint, routers.InitRouter())
server.BeforeBegin = func(add string) {
log.Printf("Actual pid is %d", syscall.Getpid())
}
err := server.ListenAndServe()
if err != nil {
log.Printf("Server err: %v", err)
}
}
/*
POST:http://127.0.0.1:8000/api/v1/articles?tag_id=1&title=test1&desc=test-desc&content=test-content&created_by=test-created&state=1
GET:http://127.0.0.1:8000/api/v1/articles
GET:http://127.0.0.1:8000/api/v1/articles/1
PUT:http://127.0.0.1:8000/api/v1/articles/1?tag_id=1&title=test-edit1&desc=test-desc-edit&content=test-content-edit&modified_by=test-created-edit&state=0
DELETE:http://127.0.0.1:8000/api/v1/articles/1
*/