64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func gambo() {
|
|
b, err := os.ReadFile(config.Log)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Strip carriage returns because Windows is retarded
|
|
b = bytes.ReplaceAll(b, []byte("\r"), []byte(""))
|
|
|
|
lines := strings.Split(string(b), "\n")
|
|
|
|
games, err := parseGames(lines)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
for _, game := range games {
|
|
//err = uploadGambo(game, "https://forcek.in/game")
|
|
err = uploadGamboTest(game)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func uploadGambo(game Game, endpoint string) error {
|
|
marshalled, err := json.Marshal(game)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(marshalled))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req.Header.Set("X-API-KEY", config.Apikey)
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(resp.Status)
|
|
return nil
|
|
}
|
|
|
|
func uploadGamboTest(game Game) error {
|
|
return uploadGambo(game, "http://localhost:3000/game")
|
|
}
|