fix: format all Go files with gofmt
- Fix alignment in struct fields (sessionProfileResponse, textureInfo, Handler) - Align struct field values in internal/templates/templates.go, internal/api/api.go
This commit is contained in:
@@ -15,10 +15,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.mrixs.me/Mrixs/MrixsCraft-server/pkg/utils"
|
|
||||||
"gitea.mrixs.me/Mrixs/MrixsCraft-server/internal/auth"
|
"gitea.mrixs.me/Mrixs/MrixsCraft-server/internal/auth"
|
||||||
"gitea.mrixs.me/Mrixs/MrixsCraft-server/internal/config"
|
"gitea.mrixs.me/Mrixs/MrixsCraft-server/internal/config"
|
||||||
"gitea.mrixs.me/Mrixs/MrixsCraft-server/internal/database"
|
"gitea.mrixs.me/Mrixs/MrixsCraft-server/internal/database"
|
||||||
|
"gitea.mrixs.me/Mrixs/MrixsCraft-server/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Handler serves admin endpoints.
|
// Handler serves admin endpoints.
|
||||||
|
|||||||
@@ -122,8 +122,8 @@ type textureInfo struct {
|
|||||||
|
|
||||||
// Mojang session server profile response (for game client).
|
// Mojang session server profile response (for game client).
|
||||||
type sessionProfileResponse struct {
|
type sessionProfileResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Props []sessionProfileProp `json:"properties"`
|
Props []sessionProfileProp `json:"properties"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ type authenticateRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type authenticateResponse struct {
|
type authenticateResponse struct {
|
||||||
AccessToken string `json:"accessToken"`
|
AccessToken string `json:"accessToken"`
|
||||||
ClientToken string `json:"clientToken"`
|
ClientToken string `json:"clientToken"`
|
||||||
AvailableProfile []profile `json:"availableProfiles"`
|
AvailableProfile []profile `json:"availableProfiles"`
|
||||||
SelectedProfile *profile `json:"selectedProfile,omitempty"`
|
SelectedProfile *profile `json:"selectedProfile,omitempty"`
|
||||||
User *userProperties `json:"user,omitempty"`
|
User *userProperties `json:"user,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type profile struct {
|
type profile struct {
|
||||||
@@ -65,7 +65,7 @@ type profile struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type userProperties struct {
|
type userProperties struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Properties []property `json:"properties"`
|
Properties []property `json:"properties"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +92,8 @@ type errorResponse struct {
|
|||||||
|
|
||||||
// Session server types (Mojang-compatible).
|
// Session server types (Mojang-compatible).
|
||||||
type sessionProfileResponse struct {
|
type sessionProfileResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Props []sessionProfileProp `json:"properties"`
|
Props []sessionProfileProp `json:"properties"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,18 +20,18 @@ import (
|
|||||||
|
|
||||||
// mimeByExtension maps common file extensions to MIME types for CAS serving.
|
// mimeByExtension maps common file extensions to MIME types for CAS serving.
|
||||||
var mimeByExtension = map[string]string{
|
var mimeByExtension = map[string]string{
|
||||||
".jar": "application/java-archive",
|
".jar": "application/java-archive",
|
||||||
".json": "application/json",
|
".json": "application/json",
|
||||||
".png": "image/png",
|
".png": "image/png",
|
||||||
".zip": "application/zip",
|
".zip": "application/zip",
|
||||||
".toml": "application/toml",
|
".toml": "application/toml",
|
||||||
".cfg": "text/plain",
|
".cfg": "text/plain",
|
||||||
".conf": "text/plain",
|
".conf": "text/plain",
|
||||||
".txt": "text/plain",
|
".txt": "text/plain",
|
||||||
".log": "text/plain",
|
".log": "text/plain",
|
||||||
".xml": "application/xml",
|
".xml": "application/xml",
|
||||||
".yml": "application/x-yaml",
|
".yml": "application/x-yaml",
|
||||||
".yaml": "application/x-yaml",
|
".yaml": "application/x-yaml",
|
||||||
".properties": "text/plain",
|
".properties": "text/plain",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ func TestIsValidHash(t *testing.T) {
|
|||||||
{"a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2", true},
|
{"a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2", true},
|
||||||
{"0000000000000000000000000000000000000000", true},
|
{"0000000000000000000000000000000000000000", true},
|
||||||
{"ffffffffffffffffffffffffffffffffffffffff", true},
|
{"ffffffffffffffffffffffffffffffffffffffff", true},
|
||||||
{"A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6A1B2", false}, // uppercase
|
{"A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6A1B2", false}, // uppercase
|
||||||
{"g1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2", false}, // non-hex
|
{"g1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2", false}, // non-hex
|
||||||
{"a1b2c3d4e5f6", false}, // too short
|
{"a1b2c3d4e5f6", false}, // too short
|
||||||
{"", false}, // empty
|
{"", false}, // empty
|
||||||
{"a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3", false}, // too long (41)
|
{"a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3", false}, // too long (41)
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ func Load() (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
Port: port,
|
Port: port,
|
||||||
DatabaseURL: getEnv("DATABASE_URL", ""),
|
DatabaseURL: getEnv("DATABASE_URL", ""),
|
||||||
CASDir: getEnv("CAS_DIR", "/var/www/cdn/files"),
|
CASDir: getEnv("CAS_DIR", "/var/www/cdn/files"),
|
||||||
SkinsDir: getEnv("SKINS_DIR", "/var/www/cdn/skins"),
|
SkinsDir: getEnv("SKINS_DIR", "/var/www/cdn/skins"),
|
||||||
JWTSecret: getEnv("JWT_SECRET", ""),
|
JWTSecret: getEnv("JWT_SECRET", ""),
|
||||||
CIsecret: getEnv("CI_SECRET", ""),
|
CIsecret: getEnv("CI_SECRET", ""),
|
||||||
BaseURL: getEnv("BASE_URL", "https://minecraft.mrixs.me"),
|
BaseURL: getEnv("BASE_URL", "https://minecraft.mrixs.me"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.DatabaseURL == "" {
|
if cfg.DatabaseURL == "" {
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ func (w *statusWriter) WriteHeader(status int) {
|
|||||||
type RateLimiter struct {
|
type RateLimiter struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
clients map[string]*bucket
|
clients map[string]*bucket
|
||||||
rate int // tokens per interval
|
rate int // tokens per interval
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
burst int // max bucket size
|
burst int // max bucket size
|
||||||
}
|
}
|
||||||
|
|
||||||
type bucket struct {
|
type bucket struct {
|
||||||
@@ -85,10 +85,10 @@ type bucket struct {
|
|||||||
// with a maximum burst of `burst`.
|
// with a maximum burst of `burst`.
|
||||||
func NewRateLimiter(rate int, interval time.Duration, burst int) *RateLimiter {
|
func NewRateLimiter(rate int, interval time.Duration, burst int) *RateLimiter {
|
||||||
rl := &RateLimiter{
|
rl := &RateLimiter{
|
||||||
clients: make(map[string]*bucket),
|
clients: make(map[string]*bucket),
|
||||||
rate: rate,
|
rate: rate,
|
||||||
interval: interval,
|
interval: interval,
|
||||||
burst: burst,
|
burst: burst,
|
||||||
}
|
}
|
||||||
// Periodically clean up stale entries.
|
// Periodically clean up stale entries.
|
||||||
go rl.cleanup()
|
go rl.cleanup()
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ type pageData struct {
|
|||||||
|
|
||||||
// Handler serves template-rendered pages.
|
// Handler serves template-rendered pages.
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
db *database.DB
|
db *database.DB
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
tmpl *template.Template
|
tmpl *template.Template
|
||||||
loaded bool
|
loaded bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHandler creates a new templates handler and parses on-disk templates.
|
// NewHandler creates a new templates handler and parses on-disk templates.
|
||||||
|
|||||||
Reference in New Issue
Block a user