-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (62 loc) · 1.39 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
63
64
65
66
67
68
69
70
71
72
package main
import (
"activityregister/auth"
"activityregister/db"
"activityregister/handle"
"fmt"
"io/ioutil"
"log"
"os"
"time"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
)
var s handle.Send
var msg = make(chan string, 20)
func sendMsg(content string) (err error) {
err = s.SendMessage(content)
return
}
func main() {
ioutil.WriteFile("server.pid", []byte(fmt.Sprintf("%d", os.Getpid())), 0666)
go func() {
for {
list, err := db.GetMessage()
if err != nil {
log.Println(err)
}
for _, v := range list {
msg <- v
}
time.Sleep(30000)
}
}()
go func() {
for m := range msg {
err := s.SendMessage(m)
if err != nil {
log.Println(err)
}
}
}()
e := echo.New()
e.SetHTTPErrorHandler(func(err error, c echo.Context) {
log.Println(err)
r := &struct {
Ret int
Msg string
}{-1, err.Error()}
c.JSON(200, r)
return
})
e.POST("/login", handle.SaveUserInfo())
api := e.Group("/api", auth.Auth)
api.POST("/createactivtty", handle.CreateActivity())
api.POST("/cancelactivity", handle.CancelActivity())
api.POST("/getcreateactivity", handle.GetCreateActivity())
api.POST("/joinactivity", handle.JoinActivity())
api.POST("/canceljoinactivity", handle.CancelJoinActivity())
api.POST("/getjoinactivity", handle.GetJoinActivity())
api.POST("/getactivitybyid", handle.GetActivityByID())
e.Run(standard.New(":7701"))
}