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 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
- Variables
- func KeyConfigured() bool
- func SetKey(key string) error
- type AccountType
- type AppID
- type Collection
- type Instance
- type SID
- type SID3
- type SID32
- type SteamID
- func New(input any) SteamID
- func RandSID64() SteamID
- func Resolve(ctx context.Context, query string) (SteamID, error)
- func ResolveGID(ctx context.Context, groupVanityURL string) (SteamID, error)
- func ResolveVanity(ctx context.Context, query string) (SteamID, error)
- func SID64FromString(steamID string) (SteamID, error)
- func (t *SteamID) Equal(id SteamID) bool
- func (t *SteamID) Int64() int64
- func (t SteamID) MarshalJSON() ([]byte, error)
- func (t SteamID) MarshalText() ([]byte, error)
- func (t *SteamID) Scan(value interface{}) error
- func (t *SteamID) Steam(format bool) SID
- func (t *SteamID) Steam3() SID3
- func (t *SteamID) String() string
- func (t *SteamID) UnmarshalJSON(data []byte) error
- func (t *SteamID) UnmarshalYAML(node *yaml.Node) error
- func (t *SteamID) Valid() bool
- func (t SteamID) Value() (driver.Value, error)
- type Universe
Constants ¶
const ( BaseGID = uint64(103582791429521408) BaseSID = uint64(76561197960265728) InstanceMask = 0x000FFFFF ClanMask = (InstanceMask + 1) >> 1 Lobby = (InstanceMask + 1) >> 2 MMSLobby = (InstanceMask + 1) >> 3 )
Variables ¶
var ( // BuildVersion is replaced at compile time with the current tag or revision. BuildVersion = "dev" //nolint:gochecknoglobals BuildCommit = "master" //nolint:gochecknoglobals BuildDate = "" //nolint:gochecknoglobals )
var ( // 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()") ErrInvalidKey = errors.New("invalid steam api key length, must be 32 chars or 0 to remove it") ErrInvalidSID = errors.New("invalid steam id") ErrEmptyString = errors.New("invalid id, string empty") ErrSIDConvertInt64 = errors.New("failed to convert id to int64") ErrInvalidGID = errors.New("invalid gid") ErrDecodeSID = errors.New("could not decode steamid value") ErrUnmarshalStringSID = errors.New("failed to unmarshal string to SteamID") ErrRequestCreate = errors.New("failed to create request") ErrInvalidStatusCode = errors.New("invalid status code") ErrResponsePerform = errors.New("failed to perform request") ErrResponseBody = errors.New("failed to read response body") ErrResolveVanityGID = errors.New("failed to resolve group vanity name") ErrInvalidQueryValue = errors.New("invalid query value") ErrInvalidQueryLen = errors.New("invalid value length") )
Functions ¶
func KeyConfigured ¶
func KeyConfigured() bool
func SetKey ¶
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 AccountType ¶
type AccountType int
AccountType is split into 10 types for a Steam account, of which 4 can be created today. Users of an "Individual" account are temporarily referred to as having a "Pending" account, which has a textual representation of "STEAM_ID_PENDING" until their account credentials are verified with Steam's authentication servers, a process usually complete by the time a server is fully connected to. Accounts of the type "Invalid" have a textual representation of "UNKNOWN" and are used for bots and accounts which do not belong to another class.
Multi-user chats use the "T" character. Steam group (clan) chats use the "c" character. Steam lobbies use Chat IDs and use the "L" character.
const ( AccountTypeInvalid AccountType = iota AccountTypeIndividual AccountTypeMultiSeat AccountTypeGameServer AccountTypeAnonGameServer AccountTypePending AccountTypeContentServer AccountTypeClan AccountTypeChat AccountTypeP2PSuperSeeder AccountTypeAnonUser )
func (AccountType) Letter ¶
func (ac AccountType) Letter() string
func (AccountType) String ¶
func (ac AccountType) String() string
type Collection ¶
type Collection []SteamID
func (Collection) Contains ¶
func (c Collection) Contains(sid64 SteamID) bool
func (Collection) ToInt64Slice ¶ added in v4.0.2
func (c Collection) ToInt64Slice() []int64
func (Collection) ToStringSlice ¶
func (c Collection) ToStringSlice() []string
type SteamID ¶
type SteamID struct { AccountID SID32 Instance Instance AccountType AccountType Universe Universe }
SteamID represents a Steam64
((Universe << 56) | (Account Type << 52) | (Instance << 32) | Account ID)
This is using a string as the base type mainly to make interop with javascript/json simpler. There is no JSON bigint type, so when used with js the Number type gets represented as a float and will result in an invalid/truncated id value when decoded back to a native int64 form. 76561198132612090.
func New ¶
New accepts the following forms of steamid:
Steam64: - "76561198045011302" - int64(76561198045011302) - uint64(76561198045011302) Steam3: - "[U:1:84745574]" Steam: - "STEAM_0:0:42372787" AccountID: - int(84745574) - int32(84745574) - int64(84745574)
Returned SteamID should be verified with the SteamID.Valid method.
func RandSID64 ¶
func RandSID64() SteamID
RandSID64 generates a unique random (numerically) valid steamid for testing.
func Resolve ¶ added in v4.0.2
Resolve tries to retrieve a SteamID from a profile URL.
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 ResolveGID ¶
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 ResolveVanity ¶
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 SID64FromString ¶
SID64FromString will attempt to convert a Steam64 formatted string into a SID64.
func (SteamID) MarshalJSON ¶
func (SteamID) MarshalText ¶ added in v4.0.1
MarshalText implements encoding.TextMarshaler which is used by the yaml package for marshalling.
func (*SteamID) Steam ¶
Steam converts a given SID64 to a SteamID2 format. e.g. 76561198132612090 -> STEAM_0:0:86173181
An empty SteamID (string) is returned if the process was unsuccessful.
func (*SteamID) Steam3 ¶
Steam3 converts a given id to a SID3 format. e.g. 76561198132612090 -> [U:1:172346362].
func (*SteamID) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaler interface for steam ids. It will attempt to do all steam id types by calling StringToSID64.
func (*SteamID) UnmarshalYAML ¶ added in v4.0.1
UnmarshalYAML implements the yaml.Unmarshaler interface for steam ids.