Beispiel #1
0
// Request ...
func Request(url string) []byte {
	resp, err := http.Get(url)
	utils.ErrChecker(err)
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	utils.ErrChecker(err)
	return body
}
Beispiel #2
0
// GetLeagueInfo ...
func GetLeagueInfo(playersID []int64, region string, apikey string) map[string][]LeagueDto {
	var leagueDtoMap map[string][]LeagueDto
	var err error
	leagueDtoMap, err = leagueRequest(playersID, region, apikey)
	utils.ErrChecker(err)
	return leagueDtoMap
}
Beispiel #3
0
func gameRequest(playerID int64, region string, apikey string) RecentGamesDto {
	var recentGamesDto RecentGamesDto
	var requestBody []byte
	var url string
	url = "https://euw.api.pvp.net/api/lol/%s/v1.3/game/by-summoner/%d/recent?api_key=%s"
	url = fmt.Sprintf(url, region, playerID, apikey)
	requestBody = Request(url)
	err := json.Unmarshal(requestBody, &recentGamesDto)
	utils.ErrChecker(err)
	return recentGamesDto
}
Beispiel #4
0
func leagueRequest(playersID []int64, region string, apikey string) (map[string][]LeagueDto, error) {
	var size int
	var leagueDtoMap map[string][]LeagueDto
	size = len(playersID)
	if size > 10 {
		return leagueDtoMap, errors.New("More than 10 playersID")
	}
	var requestBody []byte
	var url string
	var playersIds string
	playersIds = arrayToString(playersID)
	url = "https://euw.api.pvp.net/api/lol/%s/v2.5/league/by-summoner/%s?api_key=%s"
	url = fmt.Sprintf(url, region, playersIds, apikey)
	requestBody = Request(url)
	err := json.Unmarshal(requestBody, &leagueDtoMap)
	utils.ErrChecker(err)
	return leagueDtoMap, nil
}
Beispiel #5
0
// Load ...
func Load(pathname string) string {
	dat, err := ioutil.ReadFile(pathname)
	utils.ErrChecker(err)
	return string(dat)
}
Beispiel #6
0
// Query ...
func Query(db *sql.DB, query string) *sql.Rows {
	rows, err := db.Query(query)
	utils.ErrChecker(err)
	return rows
}
Beispiel #7
0
// Connect ...
func Connect(database Database) *sql.DB {
	db, err := sql.Open("postgres", database.String())
	utils.ErrChecker(err)
	return db
}
Beispiel #8
0
// Load ...
func (database *Database) Load(pathname string) {
	dat, err := ioutil.ReadFile(pathname)
	utils.ErrChecker(err)
	err = json.Unmarshal(dat, &database)
	utils.ErrChecker(err)
}