utils

package
v0.0.0-...-4529b90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PermissionDescriptions = PermissionMap{
	PostData:   "Ability to post data to the API.",
	PingAll:    "All ping fom a specified player.",
	PingToday:  "Today's ping for a specified player.",
	PingRecent: "Recent ping for a specified player.",

	ChatAll:      "All chat messages from a specified player.",
	ChatLobbyOne: "Live lobby chat messages",

	AdminGenerate:      "Generate a new API key.",
	AdminDeveloper:     "Developer Permissions.",
	AdminDatabaseStats: "Allowed to fetch Database Stats.",

	ClientEssential: "User is allowed to fetch Essential Client",
	ClientLaby:      "User is allowed to fetch Labymod Client",
	ClientLunar:     "User is allowed to fetch Lunar Client",
	ClientBadlion:   "User is allowed to fetch Badlion Client",
	ClientFeather:   "User is allowed to fetch Feather Client",
	ClientCosmetics: "User is allowed to fetch Cosmetics Client",

	HypixelProxy:        "User is allowed to fetch data from the Hypixel Proxy",
	HypixelLowCache:     "User is allowed to fetch data from the Hypixel Proxy with a lower cache time",
	HypixelLeaderboards: "User is allowed to fetch Hypixel Leaderboards",

	PlayerLookup:  "User is allowed to fetch player lookup data",
	PlayerSearch:  "User is allowed to fetch player search data",
	PlayerHistory: "User is allowed to fetch player history data",

	AccountLinking: "User is allowed to link players to an account",
	AccountUser:    "User is allowed to fetch account data",

	ErrorLogging: "User is allowed to modify error logging data",

	ReleaseAlpha:  "User is allowed to fetch Alpha releases",
	ReleaseBeta:   "User is allowed to fetch Beta releases",
	ReleaseStable: "User is allowed to fetch Stable releases",
}

PermissionDescriptions A map so we can provide descriptions for each permission node.

Functions

func AddPermissionFromArray

func AddPermissionFromArray(currentGrants []string, permissionNode PermissionNode) string

AddPermissionFromArray Adds a permission from an array of permissions.

func AddPermissionFromList

func AddPermissionFromList(currentGrants string, permissionNode PermissionNode) string

AddPermissionFromList Adds a permission to a list of permissions.

func CheckPermissions

func CheckPermissions(ctx *fiber.Ctx, permissionName PermissionNode) bool

CheckPermissions verifies if a given permission is included in the user's grants stored in the request context. It checks the "grants" local variable, ensuring it's a string, and compares it case-insensitively against the requested permission. Returns true if the permission exists, otherwise false.

func FormatTimestamp

func FormatTimestamp(timestamp time.Time) string

FormatTimestamp formats the given timestamp as a human-readable string indicating years, months, days, and hours elapsed since the provided time.

func IsDevelopmentMode

func IsDevelopmentMode() bool

IsDevelopmentMode checks if the application is running in development mode by validating if the "APP_ENV" environment variable is set to "DEV". It returns true if the mode is "DEV", otherwise false.

func RemoveStringDuplicates

func RemoveStringDuplicates(strArray []string, options RemoveStringDuplicatesOptions) []string

RemoveStringDuplicates removes duplicate strings from the given array and returns the result.

Types

type KeyManager

type KeyManager struct {
	// contains filtered or unexported fields
}

func NewKeyManager

func NewKeyManager(refreshInterval time.Duration) *KeyManager

func (*KeyManager) GetError

func (km *KeyManager) GetError() error

func (*KeyManager) GetKey

func (km *KeyManager) GetKey() (string, error)

func (*KeyManager) RefreshToken

func (km *KeyManager) RefreshToken() error

type KeyResponse

type KeyResponse struct {
	Token     string `json:"token"`
	ExpiresAt string `json:"expires_at"`
}

type ListAllPermissions

type ListAllPermissions struct{ Name, Description string }

type PermissionMap

type PermissionMap map[PermissionNode]string

PermissionMap A stringly typed map so we can add helper functionss

func (PermissionMap) GetPermissions

func (pm PermissionMap) GetPermissions() []ListAllPermissions

GetPermissions Returns a list of all permissions.

type PermissionNode

type PermissionNode string

PermissionNode represents a type for defining permission identifiers.

const (
	// PostData Ability to post data to the API.
	PostData PermissionNode = "post/data"

	// PingAll All ping fom a specified player.
	PingAll PermissionNode = "ping/all"
	// PingToday Today's ping for a specified player.
	PingToday PermissionNode = "ping/today"
	// PingRecent Recent ping for a specified player.
	PingRecent PermissionNode = "ping/recent"

	// ChatAll All chat messages from a specified player.
	ChatAll PermissionNode = "chat/all"
	// ChatLobbyOne Live lobby chat messages
	ChatLobbyOne PermissionNode = "chat/lobby-one"

	// AdminGenerate Generate a new API key.
	AdminGenerate PermissionNode = "admin/generate"
	// AdminDeveloper Developer Permissions.
	AdminDeveloper PermissionNode = "admin/developer"
	// AdminDatabaseStats Allowed to fetch Database Stats.
	AdminDatabaseStats PermissionNode = "admin/database-stats"

	// ClientEssential User is allowed to fetch Essential Client
	ClientEssential PermissionNode = "client/essential"
	// ClientLaby User is allowed to fetch Labymod Client
	ClientLaby PermissionNode = "client/laby"
	// ClientLunar User is allowed to fetch Lunar Client
	ClientLunar PermissionNode = "client/lunar"
	// ClientBadlion User is allowed to fetch Badlion Client
	ClientBadlion PermissionNode = "client/blc"
	// ClientFeather User is allowed to fetch Feather Client
	ClientFeather PermissionNode = "client/feather"
	// ClientCosmetics User is allowed to fetch Cosmetics Client
	ClientCosmetics PermissionNode = "client/cosmetics"

	// HypixelProxy User is allowed to fetch data from the  Hypixel Proxy
	HypixelProxy PermissionNode = "hypixel/proxy"
	// HypixelLowCache User is allowed to fetch data from the Hypixel Proxy with a lower cache time
	HypixelLowCache PermissionNode = "hypixel/low-cache"
	// HypixelLeaderboards User is allowed to fetch Hypixel Leaderboards
	HypixelLeaderboards PermissionNode = "hypixel/leaderboards"

	// PlayerLookup User is allowed to fetch player lookup data
	PlayerLookup PermissionNode = "player/lookup"
	// PlayerSearch User is allowed to fetch player search data
	PlayerSearch PermissionNode = "player/search"
	// PlayerHistory User is allowed to fetch player history data
	PlayerHistory PermissionNode = "player/history"

	// AccountLinking User is allowed to link players to an account
	AccountLinking PermissionNode = "account/linking"
	// AccountUser User is allowed to fetch account data
	AccountUser PermissionNode = "account/user"

	ErrorLogging PermissionNode = "error/logging"

	ReleaseAlpha  PermissionNode = "release/alpha"
	ReleaseBeta   PermissionNode = "release/beta"
	ReleaseStable PermissionNode = "release/stable"
)

func (PermissionNode) GetDescription

func (pn PermissionNode) GetDescription() string

GetDescription Returns the description for a given permission node.

func (PermissionNode) GetName

func (pn PermissionNode) GetName() string

GetName Returns the name of a permission node.

type RemoveStringDuplicatesOptions

type RemoveStringDuplicatesOptions struct {
	Sort bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL