first commit

This commit is contained in:
lily 2026-07-17 01:13:24 -04:00
commit 8d96b37ce3
4 changed files with 95 additions and 0 deletions

32
.gitignore vendored Normal file
View file

@ -0,0 +1,32 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Code coverage profiles and other test artifacts
*.out
coverage.*
*.coverprofile
profile.cov
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
go.work.sum
# env file
.env
# Editor/IDE
# .idea/
# .vscode/

5
go.mod Normal file
View file

@ -0,0 +1,5 @@
module hypixel-bans-api
go 1.24.4
require github.com/joho/godotenv v1.5.1 // indirect

2
go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

56
main.go Normal file
View file

@ -0,0 +1,56 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"time"
"github.com/joho/godotenv"
)
type PunishmentStats struct {
Success bool `json:"success"`
WatchdogLastMinute int `json:"watchdog_lastMinute"`
WatchdogRollingDaily int `json:"watchdog_rollingDaily"`
WatchdogTotal int64 `json:"watchdog_total"`
StaffRollingDaily int `json:"staff_rollingDaily"`
StaffTotal int64 `json:"staff_total"`
}
func fetchStats(apiKey string) (*PunishmentStats, error) {
req, err := http.NewRequest("GET", "https://api.hypixel.net/v2/punishmentstats", nil)
if err != nil {
return nil, err
}
req.Header.Set("API-Key", apiKey)
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("bad status: %s", resp.Status)
}
var stats PunishmentStats
if err := json.NewDecoder(resp.Body).Decode(&stats); err != nil {
return nil, err
}
return &stats, nil
}
func main() {
_ = godotenv.Load()
key := os.Getenv("HYPIXEL_API_KEY")
stats, err := fetchStats(key)
if err != nil {
fmt.Println("error:", err)
os.Exit(1)
}
fmt.Printf("%+v\n", stats)
}