moved authentication parsing to seperate file; created struct for authentication tokens

This commit is contained in:
2020-06-06 19:50:55 -05:00
parent aa2b9c796c
commit 545591700a
2 changed files with 61 additions and 16 deletions

51
auth.go Normal file
View File

@@ -0,0 +1,51 @@
/*
Functions and struct for the authentication tokens
*/
package main
import (
"fmt"
"io/ioutil"
"github.com/buger/jsonparser"
)
type Auth struct {
discord string
imgur string
wolfram string
}
// build the auth struct
func buildAuth() {
// read the auth json file
json, err := ioutil.ReadFile("auth.json")
if err != nil {
fmt.Print("Error reading auth.json file, ")
panic(err)
}
// grab the discord token
discord, err := jsonparser.GetString(json, "[0]", "discord")
if err != nil {
fmt.Print("Error parsing discord token, ")
panic(err)
}
auth.discord = discord
// grab the imgur token
imgur, err := jsonparser.GetString(json, "[0]", "imgur")
if err != nil {
fmt.Print("Error parsing imgur token, ")
panic(err)
}
auth.imgur = imgur
// grab the wolfram alpha token
wolfram, err := jsonparser.GetString(json, "[0]", "wolfram")
if err != nil {
fmt.Print("Error parsing wolfram token, ")
panic(err)
}
auth.wolfram = wolfram
}