-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
54 lines (41 loc) · 1.24 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
package main
import (
"fmt"
. "github.com/HEUDavid/auto-receive-crypto-pay/internal"
"github.com/HEUDavid/go-fsm/pkg/util"
"github.com/gin-gonic/gin"
"io"
"log"
"os"
"path/filepath"
)
func init() {
gin.SetMode(GetConfig().Global.Mode)
logPath := filepath.Join(util.FindProjectRoot(), GetConfig().Global.LogPath)
if err := os.MkdirAll(filepath.Dir(logPath), os.ModePerm); err != nil {
panic(fmt.Sprintf("Failed to create log directory: %v", err))
}
f, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
panic(fmt.Sprintf("Failed to open or create log file: %v", err))
}
mw := io.MultiWriter(os.Stdout, f)
gin.DefaultWriter = mw
log.SetOutput(mw)
}
func main() {
r := gin.Default()
r.POST(Router("webhook"), Webhook)
r.GET(Router("query_task"), QueryTask)
r.GET(Router("pay"), Index)
r.GET(Router("query_invoice"), QueryInvoice)
r.GET(Router("invoice_details"), InvoiceDetails)
r.Static(Router("src"), Source("static/src"))
r.LoadHTMLGlob(Source("static/templates/*"))
Worker.DoInit()
Adapter.DoInit()
Worker.Run()
log.Println("[FSM] Worker started...")
log.Printf("[SERVICE] Listening on %s%s", GetConfig().Global.Addr, GetConfig().Global.HostRoot)
_ = r.Run(GetConfig().Global.Addr)
}