steamid

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 14 Imported by: 7

Documentation

Overview

Package steamid provides conversion to and from all steam ID formats.

If you wish to resolve vanity names like https://steamcommunity.com/id/SQUIRRELLY into steam id, or to GetPlayerSummaries requests against the WebAPI you must first obtain an API key at https://steamcommunity.com/dev/apikey.

You can then set it for the package to use:

	steamid.SetKey(apiKey)

With a steam api key set you can now use the following functions:

	steamid.ResolveVanity()

Index

Constants

View Source
const (
	BaseSID = uint64(76561197960265728)
	BaseGID = uint64(103582791429521408)
)

Variables

View Source
var (

	// BuildVersion is replaced at compile time with the current tag or revision.
	BuildVersion = "master" //nolint:gochecknoglobals

	// ErrNoAPIKey is returned for functions that require an API key to use when one has not been set.
	ErrNoAPIKey = errors.New("No steam web api key, to obtain one see: " +
		"https://steamcommunity.com/dev/apikey and call steamid.SetKey()")
	ErrInvalidSID = errors.New("Invalid steam id")
)

Functions

func KeyConfigured added in v2.3.0

func KeyConfigured() bool

func SetKey

func SetKey(key string) error

SetKey will set the package global steam webapi key used for some requests Basic id conversion usage does not require this to be set.

You can alternatively set the key with the environment variable `STEAM_TOKEN={YOUR_API_KEY` To get a key see: https://steamcommunity.com/dev/apikey

Types

type AppID

type AppID uint32

AppID is the id associated with games/apps.

type Collection added in v2.2.0

type Collection []SID64

func (Collection) Contains added in v2.2.1

func (c Collection) Contains(sid64 SID64) bool

func (Collection) ToStringSlice added in v2.2.0

func (c Collection) ToStringSlice() []string

type GID

type GID struct {
	big.Int
}

GID represents a GroupID (64bit) 103582791453729676.

func GIDFromString

func GIDFromString(steamID string) (GID, error)

GIDFromString will attempt to convert a properly formatted string to a GID.

func NewGID added in v2.3.0

func NewGID(value any) GID

func ResolveGID

func ResolveGID(ctx context.Context, groupVanityURL string) (GID, error)

ResolveGID tries to resolve the GroupID from a group custom URL. NOTE This may be prone to error due to not being a real api endpoint.

func (GID) Valid

func (t GID) Valid() bool

Valid checks if the valid meets the minimum requirements to be considered valid.

type SID

type SID string

SID represents a SteamID STEAM_0:0:86173181.

func SID32ToSID

func SID32ToSID(steam32 SID32) SID

SID32ToSID converts a given SID32 to a SteamID. eg. 172346362 -> STEAM_0:0:86173181

An empty SteamID (string) is returned if the process was unsuccessful.

func SID3ToSID

func SID3ToSID(steam3 SID3) SID

SID3ToSID converts a given SID3 to a SteamID. eg. [U:1:172346362] -> STEAM_0:0:86173181

An empty SteamID (string) is returned if the process was unsuccessful.

func SID64ToSID

func SID64ToSID(steam64 SID64) SID

SID64ToSID converts a given SID64 to a SteamID. e.g. 76561198132612090 -> STEAM_0:0:86173181

An empty SteamID (string) is returned if the process was unsuccessful.

type SID3

type SID3 string

SID3 represents a Steam3 [U:1:172346362].

func SID32ToSID3

func SID32ToSID3(steam32 SID32) SID3

SID32ToSID3 converts a given SID32 to a SID3. eg. 172346362 -> [U:1:172346362]

An empty SID3 (string) is returned if the process was unsuccessful.

func SID64ToSID3

func SID64ToSID3(steam64 SID64) SID3

SID64ToSID3 converts a given SID64 to a SID3. e.g. 76561198132612090 -> [U:1:172346362]

An empty SID3 (string) is returned if the process was unsuccessful.

func SIDToSID3

func SIDToSID3(steamID SID) SID3

SIDToSID3 converts a given SteamID to a SID3. e.g. STEAM_0:0:86173181 -> [U:1:172346362]

An empty SID3 (string) is returned if the process was unsuccessful.

type SID32

type SID32 uint32

SID32 represents a Steam32 172346362.

func SID3ToSID32

func SID3ToSID32(steam3 SID3) SID32

SID3ToSID32 converts a given SID3 to a SID64. eg. [U:1:172346362] -> 172346362

0 is returned if the process was unsuccessful.

func SID64ToSID32

func SID64ToSID32(steam64 SID64) SID32

SID64ToSID32 converts a given SID64 to a SID32. e.g. 76561198132612090 -> 172346362

0 is returned if the process was unsuccessful.

func SIDToSID32

func SIDToSID32(steamID SID) SID32

SIDToSID32 converts a given SteamID to a SID32. e.g. STEAM_0:0:86173181 -> 172346362

0 is returned if the process was unsuccessful.

type SID64

type SID64 struct {
	big.Int
}

SID64 represents a Steam64 76561198132612090.

func New added in v2.3.0

func New(value any) SID64

func ParseString

func ParseString(body string) []SID64

ParseString attempts to parse any strings of any known format within the body to a common SID64 format.

func RandSID64

func RandSID64() SID64

RandSID64 generates a unique random (numerically) valid steamid for testing.

func ResolveSID64

func ResolveSID64(ctx context.Context, query string) (SID64, error)

ResolveSID64 tries to retrieve a SteamID64 using a query (search).

If an error occurs or the SteamID was unable to be resolved from the query then am error is returned. TODO try and resolve len(17) && len(9) failed conversions as vanity.

func ResolveVanity

func ResolveVanity(ctx context.Context, query string) (SID64, error)

ResolveVanity attempts to resolve the underlying SID64 of a users vanity url name This only accepts the name or last portion of the /id/ profile link For https://steamcommunity.com/id/SQUIRRELLY the value is SQUIRRELLY.

func SID32ToSID64

func SID32ToSID64(steam32 SID32) SID64

SID32ToSID64 converts a given SID32 to a SID64. e.g. 172346362 -> 76561198132612090

0 is returned if the process was unsuccessful.

func SID3ToSID64

func SID3ToSID64(steam3 SID3) SID64

SID3ToSID64 converts a given SID3 to a SID64. eg. [U:1:172346362] -> 76561198132612090

0 is returned if the process was unsuccessful.

func SID64FromString

func SID64FromString(steamID string) (SID64, error)

SID64FromString will attempt to convert a Steam64 formatted string into a SID64.

func SIDToSID64

func SIDToSID64(steamID SID) SID64

SIDToSID64 converts a given SteamID to a SID64. e.g. STEAM_0:0:86173181 -> 76561198132612090

0 is returned if the process was unsuccessful.

func StringToSID64

func StringToSID64(s string) (SID64, error)

StringToSID64 will attempt to convert a string containing some format of steam id into a SID64 automatically, picking the appropriate matching conversion to make.

This will not resolve vanity ids. Use ResolveSID64 if you also want to attempt

to resolve it as a vanity url in addition.

func (SID64) MarshalJSON added in v2.3.1

func (t SID64) MarshalJSON() ([]byte, error)

func (*SID64) UnmarshalJSON

func (t *SID64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaler interface for steam ids. It will attempt to do all steam id types by calling StringToSID64.

func (SID64) Valid

func (t SID64) Valid() bool

Valid ensures the value is at least large enough to be valid No further validation is done.

Jump to

Keyboard shortcuts

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