-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (53 loc) · 1.47 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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/common-nighthawk/go-figure"
"github.com/gorilla/mux"
)
var authtokens = []string{}
var weebToken string
var port = "28785"
// Config struct for auth tokens
type Config struct {
Tokens []string `json:"tokens"`
WeebshToken string `json:"weebshToken"`
}
func main() {
// Read the config file
configFile, err := os.Open("config.json")
// Check if the config file was read successfully
if err != nil {
fmt.Println(err)
}
// Defer closing the file until parsed
defer configFile.Close()
// Read the config file
byteValue, _ := ioutil.ReadAll(configFile)
var tokens Config
json.Unmarshal(byteValue, &tokens)
// Append each auth token to the global auth token slice
for i := 0; i < len(tokens.Tokens); i++ {
authtokens = append(authtokens, tokens.Tokens[i])
}
// Set weeb.sh config token
weebToken = tokens.WeebshToken
// Instantiate new mux router
r := mux.NewRouter()
// Handle a simple test route
r.HandleFunc("/test/{one}/{two}", TestHandler).Methods("GET")
// Handle weeb.sh API
r.HandleFunc("/weebsh/{type}", WeebshHandler).Methods("GET")
// Boot up logo & information
bootLogo := figure.NewFigure("kirAPI", "speed", true)
bootLogo.Print()
fmt.Println("\nNow running on port " + port)
// Authenticate with weeb.sh
WeebAuth()
// Start listening for incoming request and logging if something is wrong
log.Fatal(http.ListenAndServe(":"+port, r))
}