示例#1
0
func RunMatch(port, name, name2, commit, commit2, mapName string, category tournament.TournamentCategory) error {
	response := struct{}{}
	if err := web.SendPostJson("http://localhost:"+port+"/match/run", web.JsonBody{
		"player1":  name,
		"player2":  name2,
		"commit1":  commit,
		"commit2":  commit2,
		"category": string(category),
		"map":      mapName,
	}, &response); err != nil {
		return err
	} else {
		return nil
	}
}
示例#2
0
func CreatePlayer(port, name string, category tournament.TournamentCategory) (string, error) {
	var response struct {
		Data struct {
			CommitHash string `json:"commit_hash"`
			RepoURL    string `json:"repo_url"`
		} `json:"data"`
	}
	if _, pubKey, err := testutil.CreateKeyPair(); err != nil {
		return "", err
	} else if err := web.SendPostJson("http://localhost:"+port+"/register", web.JsonBody{"name": name, "public_key": pubKey, "category": string(category)}, &response); err != nil {
		return "", err
	} else if repo, err := (git.TempRemote{}).CheckoutRepository(response.Data.RepoURL); err != nil {
		return "", err
	} else {
		defer repo.Delete()
		return response.Data.CommitHash, nil
	}
}