-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (42 loc) · 1.23 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
package main
import (
"context"
"github.com/disgoorg/disgo/webhook"
"github.com/go-chi/chi/v5"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"log"
"net/http"
"os"
)
var GlobalWebhookClient webhook.Client
func main() {
if len(os.Args) < 3 {
log.Fatal("You didn't set an api key and webhook url.")
}
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI("mongodb://localhost:27017"))
if err != nil {
panic(err)
}
if err = mongoClient.Ping(context.TODO(), readpref.Primary()); err != nil {
panic(err)
}
defer mongoClient.Disconnect(context.TODO())
GlobalWebhookClient, err = webhook.NewWithURL(os.Args[2])
if err != nil {
panic(err)
}
collection := mongoClient.Database("default").Collection("licenses")
handlerContext := HandlerContext{apiKey: os.Args[1], collection: collection}
router := chi.NewRouter()
router.Get("/validate/{key}/{hwid}", handlerContext.validateKey)
// Requires API key
router.Post("/create", handlerContext.registerKey)
router.Post("/all", handlerContext.allKeys)
router.Post("/unused", handlerContext.allUnusedKeys)
err = http.ListenAndServe(":3000", router)
if err != nil {
return
}
}