|
@@ -12,12 +12,14 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+
|
|
|
type Application struct {
|
|
|
Name, AccessToken, Sid, BaseURL, AuthString string
|
|
|
Languages map[string]string
|
|
|
Delay time.Duration
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func (app *Application) SetBaseURL(url string) {
|
|
|
if !strings.HasSuffix(url, "/") {
|
|
|
url += "/"
|
|
@@ -25,27 +27,29 @@ func (app *Application) SetBaseURL(url string) {
|
|
|
app.BaseURL = url
|
|
|
}
|
|
|
|
|
|
-func JsonDecoder(data io.ReadCloser, target interface{}) {
|
|
|
+
|
|
|
+func JSONDecoder(data io.ReadCloser, target interface{}) {
|
|
|
decoder := json.NewDecoder(data)
|
|
|
|
|
|
err := decoder.Decode(target)
|
|
|
if err != nil {
|
|
|
- log.Printf("error reading json: %v", err)
|
|
|
+ log.Printf("Error reading json: %v", err)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func (app *Application) LoadLanguages() {
|
|
|
data, err := os.Open("./html/languages.json")
|
|
|
defer data.Close()
|
|
|
if err != nil {
|
|
|
- log.Printf("error reading languages: %v", err)
|
|
|
- return
|
|
|
+ log.Fatalf("Error reading languages: %v", err)
|
|
|
}
|
|
|
|
|
|
app.Languages = make(map[string]string)
|
|
|
- JsonDecoder(data, &app.Languages)
|
|
|
+ JSONDecoder(data, &app.Languages)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func (app Application) CheckLanguage(language string) bool {
|
|
|
_, ok := app.Languages[language]
|
|
|
if !ok {
|
|
@@ -55,10 +59,11 @@ func (app Application) CheckLanguage(language string) bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func (app *Application) Login() {
|
|
|
credentials, err := ioutil.ReadFile("./secrets.json")
|
|
|
if err != nil {
|
|
|
- log.Printf("Error reading credentials: %v", err)
|
|
|
+ log.Fatalf("Error reading credentials: %v", err)
|
|
|
}
|
|
|
|
|
|
loginURL := app.BaseURL + "auth/login"
|
|
@@ -69,11 +74,11 @@ func (app *Application) Login() {
|
|
|
client := &http.Client{}
|
|
|
resp, err := client.Do(req)
|
|
|
if err != nil {
|
|
|
- log.Printf("error logging in: %v", err)
|
|
|
+ log.Fatalf("Error logging in: %v", err)
|
|
|
}
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- JsonDecoder(resp.Body, &app)
|
|
|
+ JSONDecoder(resp.Body, &app)
|
|
|
|
|
|
app.AuthString = "?authToken=" + app.AccessToken
|
|
|
log.Println(app.AuthString, resp.Status)
|