Skip to content

Instantly share code, notes, and snippets.

@redrush85
Created June 22, 2017 13:27
Show Gist options
  • Save redrush85/a5c9e248d4b63c9127781bcb612318a6 to your computer and use it in GitHub Desktop.
Save redrush85/a5c9e248d4b63c9127781bcb612318a6 to your computer and use it in GitHub Desktop.
package main
import (
"sync"
"context"
"golang.org/x/time/rate"
)
type Summoner struct {
SummonerID int64
SummonerName string
}
type Repository interface {
GetSummonerByName(name string) Summoner
GetMatchByID(id int)
GetTimeLineByID(id int)
}
type RiotRepo struct {
API_KEY string
}
func (repo RiotRepo) GetSummonerByName(name string) Summoner {
// request to RIOT
return Summoner{}
}
func (repo RiotRepo) GetmatchByID(name string) {
// request to RIOT
return Summoner{}
}
func (repo RiotRepo) GetTimeLineByID(name string) {
// request to RIOT
return Summoner{}
}
type Service struct {
repo Repository
}
func (service Service) GetMatchByID(id int, timeline bool) {
var wg sync.WaitGroup
ctx, cancelCtx := context.WithTimeout(context.TODO(), time.Duration(conf.Timeout)*time.Second)
defer cancelCtx()
c.rateLimiterMap[limitKey].WaitN(ctx, 2)
if timeline {
wg.Add(1)
go service.repo.GetTimeLineByID(id)
}
go service.repo.GetMatchByID(id)
wg.Wait()
}
func main() {
repo := RiotRepo{API_KEY: "fdfgfdgfghfghfghf"}
service := Service{repo: repo}
server := NewWebServer(service: service)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment