-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
86 lines (75 loc) · 2.63 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"context"
"encoding/xml"
"fmt"
"github.com/getsentry/sentry-go"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/remizovm/geonames"
"github.com/remizovm/geonames/models"
"log"
"net/http"
"os"
"time"
)
var (
pool *pgxpool.Pool
geonameCities map[int]*models.Feature
config *Config
)
func checkError(err error) {
if err != nil {
log.Fatalf("Demae Dominos server has encountered an error! Reason: %v\n", err)
}
}
func main() {
rawConfig, err := os.ReadFile("./config.xml")
checkError(err)
config = &Config{}
err = xml.Unmarshal(rawConfig, config)
checkError(err)
// Before we do anything, init Sentry to capture all errors.
err = sentry.Init(sentry.ClientOptions{
Dsn: config.SentryDSN,
Debug: true,
TracesSampleRate: 1.0,
})
checkError(err)
defer sentry.Flush(2 * time.Second)
// Initialize database
dbString := fmt.Sprintf("postgres://%s:%s@%s/%s", config.SQLUser, config.SQLPass, config.SQLAddress, config.SQLDB)
dbConf, err := pgxpool.ParseConfig(dbString)
checkError(err)
pool, err = pgxpool.ConnectConfig(context.Background(), dbConf)
checkError(err)
// Ensure this Postgresql connection is valid.
defer pool.Close()
// Initialize Geonames cities array.
client := geonames.Client{}
geonameCities, err = client.Cities15000()
checkError(err)
// Finally, initialize the HTTP server
fmt.Printf("Starting HTTP connection (%s)...\nNot using the usual port for HTTP?\nBe sure to use a proxy, otherwise the Wii can't connect!\n", config.Address)
r := NewRoute()
nwapi := r.HandleGroup("nwapi.php")
{
nwapi.NormalResponse("webApi_document_template", documentTemplate)
nwapi.NormalResponse("webApi_area_list", areaList)
nwapi.MultipleRootNodes("webApi_category_list", categoryList)
nwapi.MultipleRootNodes("webApi_area_shopinfo", shopInfo)
nwapi.NormalResponse("webApi_shop_list", categoryList)
nwapi.MultipleRootNodes("webApi_shop_one", shopOne)
nwapi.MultipleRootNodes("webApi_menu_list", menuList)
nwapi.MultipleRootNodes("webApi_item_list", itemList)
nwapi.MultipleRootNodes("webApi_item_one", itemOne)
nwapi.MultipleRootNodes("webApi_Authkey", authKey)
nwapi.MultipleRootNodes("webApi_basket_delete", basketDelete)
nwapi.MultipleRootNodes("webApi_basket_reset", basketReset)
nwapi.MultipleRootNodes("webApi_basket_add", basketAdd)
nwapi.MultipleRootNodes("webApi_basket_list", basketList)
nwapi.MultipleRootNodes("webApi_validate_condition", func(r *Response) {})
nwapi.NormalResponse("webApi_order_done", orderDone)
nwapi.NormalResponse("webApi_inquiry_done", inquiryDone)
}
log.Fatal(http.ListenAndServe(config.Address, r.Handle()))
}