genshinapi

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 6 Imported by: 1

README

genshin-api

Go Reference

Golang wrapper for a fan-made Genshin Impact API.

To install, do go get -u github.com/darylhjd/genshin-api.

API can be found here. GitHub repo for API is here.

Feel free to contribute to this project!

Examples

package main

import (
	"fmt"
	
	genshinapi "github.com/darylhjd/genshin-api"
)

func main() {
	// Get list of data types provided by API: artifacts, characters, etc...
	dataTypes, _ := genshinapi.GetDataTypes()
	fmt.Println(dataTypes)

	// Get list of character names
	characters, _ := genshinapi.GetCharacters()
	fmt.Println(characters)
}

Refer to each DataType's corresponding file to see what helper functions are available. As a general rule, most DataTypes support getting the full list of item names as well as a particular DataEntry of that type.

This library provides a wildcard function, GetCustomBody, for your own requests. You can find this function in api.go.

package main

import (
	"encoding/json"
	"fmt"
	
	genshinapi "github.com/darylhjd/genshin-api"
)

func main() {
	// Get data on characters/amber
	urlArgs := []string{
		// Package provides a few helper strings
		genshinapi.CharactersDType, 
		"amber",
	}
	// Function will parse URL for you
	result, _ := genshinapi.GetCustomBody(urlArgs...)

	var character genshinapi.Character
	_ = json.Unmarshal(result, &character)
	fmt.Println(character)
	
	// Get portrait image of Amber
	// The function GetImage in types.go also provides this functionality
	urlArgs = append(urlArgs, genshinapi.CharacterPortrait)
	imagedata, _ := genshinapi.GetCustomBody(urlArgs...)
	_ = imagedata
}

Documentation

Overview

API at : https://api.genshin.dev/ GitHub Repo : https://github.com/genshindev/api

Index

Constants

View Source
const (
	// API DataType name
	ArtifactsDType = "artifacts"
	// Assets
	ArtifactPhoto = "flower-of-life"
)
View Source
const (
	// API DataType name
	CharactersDType = "characters"
	// Assets
	CharacterIcon     = "icon"
	CharacterPortrait = "portrait"
)
View Source
const (
	// API DataType name
	ElementsDType = "elements"
	// Assets
	ElementIcon = "icon"
)
View Source
const (
	// Material types
	BossMaterialType                = "boss-material"
	CharacterAscensionMaterialType  = "character-ascension"
	CharacterExperienceMaterialType = "character-experience"
	CommonAscensionMaterialType     = "common-ascension"
	LocalSpecialtiesMaterialType    = "local-specialties"
	TalentBookMaterialType          = "talent-book"
	TalentBossMaterialType          = "talent-boss"
	WeaponAscensionMaterialType     = "weapon-ascension"
	WeaponExperienceMaterialType    = "weapon-experience"
)
View Source
const (
	// API DataType name
	WeaponsDType = "weapons"
	// Assets
	WeaponIcon = "icon"
)
View Source
const (
	BaseAPI = "https://api.genshin.dev/"
)
View Source
const (
	// API DataType name
	DomainsDType = "domains"
)
View Source
const (
	// API DataType name
	MaterialsDType = "materials"
)
View Source
const (
	// API DataType name
	NationsDType = "nations"
)

Variables

This section is empty.

Functions

func GetArtifacts

func GetArtifacts() ([]string, error)

GetArtifacts : Get list of artifact names.

func GetCharacters

func GetCharacters() ([]string, error)

GetCharacters : Get list of character names.

func GetCustomBody

func GetCustomBody(ext ...string) ([]byte, error)

GetCustomBody : Function to get data from API. Provide the function with a slice of URL-part strings. The function will concatenate the strings with backslashes so you do not need to do so.

func GetDataTypeItemsList added in v1.1.0

func GetDataTypeItemsList(t string) ([]string, error)

GetDataTypeItemsList : Get a list of item names for a particular data type.

func GetDataTypes

func GetDataTypes() ([]string, error)

GetDataTypes : Get data types provided by the API

func GetDomains

func GetDomains() ([]string, error)

GetDomains : Get list of domain names.

func GetElements

func GetElements() ([]string, error)

GetElements : Get list of element names.

func GetImage

func GetImage(dtype, name, imagetype string) ([]byte, error)

GetImage : Return a byte array of image data for a data type entry Returns error if request is not valid (validity of request is guaranteed).

func GetMaterials added in v1.1.0

func GetMaterials() ([]string, error)

GetMaterials : Get list of material names.

func GetNations

func GetNations() ([]string, error)

GetNations : Get list of nation names.

func GetWeapons

func GetWeapons() ([]string, error)

GetWeapons : Get list of weapon names.

Types

type APIError

type APIError struct {
	Error           *string  `json:"error"`                     // If API encounters an error, Error will not be nil.
	AvailableTypes  []string `json:"availableTypes,omitempty"`  // For wrong data type
	AvailableImages []string `json:"availableImages,omitempty"` // For wrong image type
}

APIError : Struct to check for API errors. This struct is used in the GetCustomBody API function.

type Artifact

type Artifact struct {
	Name           string `json:"name"`
	MaxRarity      int    `json:"max_rarity"`
	TwoPieceBonus  string `json:"2-piece_bonus"`
	FourPieceBonus string `json:"4-piece_bonus"`
}

Artifact : Struct containing information on a Artifact.

func GetArtifact

func GetArtifact(name string) (Artifact, error)

GetArtifact : Return a requested Artifact struct.

func (Artifact) EntryName

func (a Artifact) EntryName() string

type BossMaterial added in v1.1.0

type BossMaterial struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Source string `json:"source"`
}

type BossMaterials added in v1.1.1

type BossMaterials struct {
	Anemo   BossMaterial `json:"anemo"`
	Cryo    BossMaterial `json:"cryo"`
	Electro BossMaterial `json:"electro"`
	Geo     BossMaterial `json:"geo"`
	Hydro   BossMaterial `json:"hydro"`
	Pyro    BossMaterial `json:"pyro"`
}

BossMaterials : Struct containing material from each elemental boss.

func (BossMaterials) EntryName added in v1.1.1

func (bm BossMaterials) EntryName() string

func (BossMaterials) MaterialType added in v1.1.1

func (bm BossMaterials) MaterialType() string

type Character

type Character struct {
	Name           string   `json:"name"`
	Title          string   `json:"title"`
	Vision         string   `json:"vision"`
	Weapon         string   `json:"weapon"`
	Gender         string   `json:"gender"`
	Nation         string   `json:"nation"`
	Affiliation    string   `json:"affiliation"`
	SpecialDish    string   `json:"specialDish"`
	Rarity         int      `json:"rarity"`
	Constellation  string   `json:"constellation"`
	Birthday       string   `json:"birthday"`
	Description    string   `json:"description"`
	SkillTalents   []Talent `json:"skillTalents"`
	PassiveTalents []Talent `json:"passiveTalents"`
	Constellations []Talent `json:"constellations"`
}

Character : Struct containing information on a Character.

func GetCharacter

func GetCharacter(name string) (Character, error)

GetCharacter : Return a requested Character struct.

func (Character) EntryName

func (c Character) EntryName() string

type CharacterAscensionMaterial added in v1.1.0

type CharacterAscensionMaterial struct {
	Sliver   GemPiece `json:"sliver"`
	Fragment GemPiece `json:"fragment"`
	Chunk    GemPiece `json:"chunk"`
	Gemstone GemPiece `json:"gemstone"`
}

type CharacterAscensionMaterials added in v1.1.1

type CharacterAscensionMaterials struct {
	Anemo    CharacterAscensionMaterial `json:"anemo"`
	Cryo     CharacterAscensionMaterial `json:"cryo"`
	Electro  CharacterAscensionMaterial `json:"electro"`
	Geo      CharacterAscensionMaterial `json:"geo"`
	Hydro    CharacterAscensionMaterial `json:"hydro"`
	Pyro     CharacterAscensionMaterial `json:"pyro"`
	Traveler CharacterAscensionMaterial `json:"traveler"`
}

CharacterAscensionMaterials : Struct containing each elemental character ascension material.

func (CharacterAscensionMaterials) EntryName added in v1.1.1

func (cam CharacterAscensionMaterials) EntryName() string

func (CharacterAscensionMaterials) MaterialType added in v1.1.1

func (cam CharacterAscensionMaterials) MaterialType() string

type CharacterExperienceMaterial added in v1.1.0

type CharacterExperienceMaterial struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Experience int    `json:"experience"`
	Rarity     int    `json:"rarity"`
}

type CharacterExperienceMaterials added in v1.1.1

type CharacterExperienceMaterials struct {
	Items []CharacterExperienceMaterial `json:"items"`
}

CharacterExperienceMaterials : Struct containing list of each CharacterExperienceMaterial.

func (CharacterExperienceMaterials) EntryName added in v1.1.1

func (cem CharacterExperienceMaterials) EntryName() string

func (CharacterExperienceMaterials) MaterialType added in v1.1.1

func (cem CharacterExperienceMaterials) MaterialType() string

type CommonAscensionMaterial added in v1.1.0

type CommonAscensionMaterial struct {
	Characters []string       `json:"characters"`
	Items      []MaterialItem `json:"items"`
	Sources    []string       `json:"sources"`
}

type CommonAscensionMaterials added in v1.1.1

type CommonAscensionMaterials struct {
	Slime                    CommonAscensionMaterial `json:"slime"`
	HilichurlMasks           CommonAscensionMaterial `json:"hilichurl-masks"`
	HilichurlArrowheads      CommonAscensionMaterial `json:"hilichurl-arrowheads"`
	SamachurlScrolls         CommonAscensionMaterial `json:"samachurl-scrolls"`
	TreasureHoarderInsignias CommonAscensionMaterial `json:"treasure-hoarder-insignias"`
	FatuiInsignias           CommonAscensionMaterial `json:"fatui-insignias"`
	WhopperflowerNectar      CommonAscensionMaterial `json:"whopperflower-nectar"`
	HilichurlHorns           CommonAscensionMaterial `json:"hilichurl-horns"`
	LeyLine                  CommonAscensionMaterial `json:"ley-line"`
	BoneShards               CommonAscensionMaterial `json:"bone-shards"`
	MistGrass                CommonAscensionMaterial `json:"mist-grass"`
	FatuiKnives              CommonAscensionMaterial `json:"fatui-knives"`
	ChaosParts               CommonAscensionMaterial `json:"chaos-parts"`
}

CommonAscensionMaterials : Struct containing information on each common ascension material

func (CommonAscensionMaterials) EntryName added in v1.1.1

func (coam CommonAscensionMaterials) EntryName() string

func (CommonAscensionMaterials) MaterialType added in v1.1.1

func (coam CommonAscensionMaterials) MaterialType() string

type DataEntry

type DataEntry interface {
	EntryName() string
}

DataEntry : This interface is implemented by each particular DataType provided by the API.

type DataTypes

type DataTypes struct {
	Types []string `json:"types"`
}

DataTypes : Struct to hold list of data types provided by API. This is a struct because the API returns a JSON containing the list, rather than just a list.

type Domain

type Domain struct {
	Name                string               `json:"name"`
	Type                string               `json:"type"`
	Description         string               `json:"description"`
	Location            string               `json:"location"`
	Nation              string               `json:"nation"`
	Requirements        []RequirementLevel   `json:"requirements"`
	RecommendedElements []RecommendedElement `json:"recommendedElements"`
	Rewards             []Reward             `json:"rewards"`
}

func GetDomain

func GetDomain(name string) (Domain, error)

GetDomain : Return a requested Domain struct.

func (Domain) EntryName

func (d Domain) EntryName() string

type Drop

type Drop struct {
	Name string `json:"name"`
	Rate string `json:"rate"`
}

type Element

type Element struct {
	Name string `json:"name"`
}

func GetElement

func GetElement(name string) (Element, error)

GetElement : Return a requested Element struct.

func (Element) EntryName

func (e Element) EntryName() string

type GemPiece added in v1.1.1

type GemPiece struct {
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	Sources []string `json:"sources"`
	Rarity  int      `json:"rarity"`
}

type LocalSpecialtiesMaterials added in v1.1.1

type LocalSpecialtiesMaterials struct {
	Mondstadt []LocalSpecialtyMaterial `json:"mondstadt"`
	Liyue     []LocalSpecialtyMaterial `json:"liyue"`
}

LocalSpecialtiesMaterials : Struct containing list of LocalSpecialtyMaterial for each nation.

func (LocalSpecialtiesMaterials) EntryName added in v1.1.1

func (lsm LocalSpecialtiesMaterials) EntryName() string

func (LocalSpecialtiesMaterials) MaterialType added in v1.1.1

func (lsm LocalSpecialtiesMaterials) MaterialType() string

type LocalSpecialtyMaterial added in v1.1.1

type LocalSpecialtyMaterial struct {
	ID         string   `json:"id"`
	Name       string   `json:"name"`
	Characters []string `json:"characters"`
}

type Material added in v1.1.0

type Material interface {
	MaterialType() string
}

Material : This interface is unique to a Material DataEntry. Any Material interface will also implement the normal DataEntry interface.

func GetBossMaterial added in v1.1.0

func GetBossMaterial() (Material, error)

GetBossMaterial : Return a BossMaterials struct.

func GetCharacterAscensionMaterial added in v1.1.0

func GetCharacterAscensionMaterial() (Material, error)

GetCharacterAscensionMaterial : Return a CharacterAscensionMaterials struct.

func GetCharacterExperienceMaterial added in v1.1.0

func GetCharacterExperienceMaterial() (Material, error)

GetCharacterExperienceMaterial : Return a CharacterExperienceMaterials struct.

func GetCommonAscensionMaterial added in v1.1.0

func GetCommonAscensionMaterial() (Material, error)

GetCommonAscensionMaterial : Return a CommonAscensionMaterials struct

func GetLocalSpecialtiesMaterial added in v1.1.0

func GetLocalSpecialtiesMaterial() (Material, error)

GetLocalSpecialtiesMaterial : Return a LocalSpecialtiesMaterials struct

func GetMaterial added in v1.1.0

func GetMaterial(mname string) (Material, error)

GetMaterial : Return a Material struct corresponding to requested MaterialType.

func GetTalentBookMaterial added in v1.1.0

func GetTalentBookMaterial() (Material, error)

GetTalentBookMaterial : Return a TalentBookMaterials struct

func GetTalentBossMaterial added in v1.1.0

func GetTalentBossMaterial() (Material, error)

GetTalentBossMaterial : Return a TalentBossMaterials struct

func GetWeaponAscensionMaterial added in v1.1.0

func GetWeaponAscensionMaterial() (Material, error)

GetWeaponAscensionMaterial : Return a WeaponAscensionMaterials struct

func GetWeaponExperienceMaterial added in v1.1.0

func GetWeaponExperienceMaterial() (Material, error)

GetWeaponExperienceMaterial : Return a WeaponExperienceMaterials struct

type MaterialItem added in v1.1.1

type MaterialItem struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Rarity int    `json:"rarity"`
}

type Nation

type Nation struct {
	Name              string `json:"name"`
	Element           string `json:"element"`
	Archon            string `json:"archon"`
	ControllingEntity string `json:"controllingEntity"`
}

func GetNation

func GetNation(name string) (Nation, error)

GetNation : Return a requested Nation struct.

func (Nation) EntryName

func (n Nation) EntryName() string

type RecommendedElement

type RecommendedElement struct {
	Element string `json:"element"`
}

type RequirementLevel

type RequirementLevel struct {
	Level            string `json:"level"`
	AdventureRank    string `json:"adventureRank"`
	RecommendedLevel string `json:"recommendedLevel"`
	LeyLineDisorder  string `json:"leyLineDisorder"`
}

type Reward

type Reward struct {
	Day     string         `json:"day"`
	Details []RewardDetail `json:"details"`
}

type RewardDetail

type RewardDetail struct {
	Level                   string `json:"level"`
	AdventureExperience     string `json:"adventureExperience"`
	CompanionshipExperience string `json:"companionshipExperience"`
	Mora                    string `json:"mora"`
	Drops                   []Drop `json:"drops"`
}

type Talent

type Talent struct {
	Name        string         `json:"name"`
	Unlock      string         `json:"unlock"`
	Description string         `json:"description"`
	Upgrades    []UpgradeLevel `json:"upgrades,omitempty"`
}

type TalentBookMaterial added in v1.1.0

type TalentBookMaterial struct {
	Characters   []string       `json:"characters"`
	Availability []string       `json:"availability"`
	Source       string         `json:"source"`
	Items        []MaterialItem `json:"items"`
}

type TalentBookMaterials added in v1.1.1

type TalentBookMaterials struct {
	Freedom    TalentBookMaterial `json:"freedom"`
	Resistance TalentBookMaterial `json:"resistance"`
	Ballad     TalentBookMaterial `json:"ballad"`
	Prosperity TalentBookMaterial `json:"prosperity"`
	Diligence  TalentBookMaterial `json:"diligence"`
	Gold       TalentBookMaterial `json:"gold"`
}

TalentBookMaterials : Struct containing each TalentBookMaterials

func (TalentBookMaterials) EntryName added in v1.1.1

func (tbookm TalentBookMaterials) EntryName() string

func (TalentBookMaterials) MaterialType added in v1.1.1

func (tbookm TalentBookMaterials) MaterialType() string

type TalentBossMaterial added in v1.1.0

type TalentBossMaterial struct {
	ID         string   `json:"id"`
	Name       string   `json:"name"`
	Characters []string `json:"characters"`
}

type TalentBossMaterials added in v1.1.1

type TalentBossMaterials struct {
	TailOfBoreas         TalentBossMaterial `json:"tail-of-boreas"`
	RingOfBoreas         TalentBossMaterial `json:"ring-of-boreas"`
	SpiritLocketOfBoreas TalentBossMaterial `json:"spirit-locket-of-boreas"`
	DvalinsPlume         TalentBossMaterial `json:"dvalin's-plume"`
	DvalinsClaw          TalentBossMaterial `json:"dvalin's-claw"`
	DvalinsSigh          TalentBossMaterial `json:"dvalin's-sigh"`
	TuskOfMonocerosCaeli TalentBossMaterial `json:"tusk-of-monoceros-caeli"`
	ShardOfAFoulLegacy   TalentBossMaterial `json:"shard-of-a-foul-legacy"`
	ShadowOfTheWarrior   TalentBossMaterial `json:"shadow-of-the-warrior"`
}

TalentBossMaterials : Sturct containing each TalentBossMaterial

func (TalentBossMaterials) EntryName added in v1.1.1

func (tbossm TalentBossMaterials) EntryName() string

func (TalentBossMaterials) MaterialType added in v1.1.1

func (tbossm TalentBossMaterials) MaterialType() string

type UpgradeLevel

type UpgradeLevel struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Weapon

type Weapon struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Rarity      int    `json:"rarity"`
	BaseAttack  string `json:"baseAttack"`
	SubStat     string `json:"subStat"`
	PassiveName string `json:"passiveName"`
	PassiveDesc string `json:"passiveDesc"`
	Location    string `json:"location"`
}

func GetWeapon

func GetWeapon(name string) (Weapon, error)

GetWeapon : Return a requested Weapon struct.

func (Weapon) EntryName

func (w Weapon) EntryName() string

type WeaponAscensionMaterial added in v1.1.0

type WeaponAscensionMaterial struct {
	Weapons      []string       `json:"weapons"`
	Availability []string       `json:"availability"`
	Source       string         `json:"source"`
	Items        []MaterialItem `json:"items"`
}

type WeaponAscensionMaterials added in v1.1.1

type WeaponAscensionMaterials struct {
	Decarabian   WeaponAscensionMaterial `json:"decarabian"`
	Boreal       WeaponAscensionMaterial `json:"boreal"`
	Dandelion    WeaponAscensionMaterial `json:"dandelion"`
	Guyun        WeaponAscensionMaterial `json:"guyun"`
	Elixir       WeaponAscensionMaterial `json:"elixir"`
	Aerosiderite WeaponAscensionMaterial `json:"aerosiderite"`
}

WeaponAscensionMaterials : Struct containing each WeaponAscensionMaterial

func (WeaponAscensionMaterials) EntryName added in v1.1.1

func (wam WeaponAscensionMaterials) EntryName() string

func (WeaponAscensionMaterials) MaterialType added in v1.1.1

func (wam WeaponAscensionMaterials) MaterialType() string

type WeaponExperienceMaterial added in v1.1.0

type WeaponExperienceMaterial struct {
	ID         string   `json:"id"`
	Name       string   `json:"name"`
	Experience int      `json:"experience"`
	Rarity     int      `json:"rarity"`
	Source     []string `json:"source"`
}

type WeaponExperienceMaterials added in v1.1.1

type WeaponExperienceMaterials struct {
	Items []WeaponExperienceMaterial `json:"items"`
}

WeaponExperienceMaterials : Struct containing list of WeaponExperienceMaterial

func (WeaponExperienceMaterials) EntryName added in v1.1.1

func (wem WeaponExperienceMaterials) EntryName() string

func (WeaponExperienceMaterials) MaterialType added in v1.1.1

func (wem WeaponExperienceMaterials) MaterialType() string

Jump to

Keyboard shortcuts

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