Giter Club home page Giter Club logo

go-pokedex's Introduction

Refactoring plan

  • Add refactoring basically make functions generics. For example func GenericRequest[T any](c *Client, url string, search string) (T, error) we need to make it a method receiver for c *Client. So that it can be shared with other packages.
package pokeapi

import (
	"encoding/json"
	"io"
	"log"
)

func GenericRequest[T any](c *Client, url string, search string) (T, error) {
	completeUrl := baseUrl + url + search

	var response T
	res, err := c.httpClient.Get(completeUrl)
	if err != nil {
		return response, err
	}

	defer res.Body.Close()

	if res.StatusCode > 299 {
		log.Fatalf("Response failed with status code: %d and message: %s", res.StatusCode, res.Body)
	}

	body, err := io.ReadAll(res.Body)
	if err != nil {
		return response, err
	}

	if err := json.Unmarshal(body, &response); err != nil {
		return response, err
	}

	return response, nil
}

Some more feature to work on

  • Update the CLI to support the "up" arrow to cycle through previous commands
  • Simulate battles between pokemon
  • Add more unit tests
  • Refactor your code to organize it better and make it more testable
  • Keep pokemon in a "party" and allow them to level up
  • Allow for pokemon that are caught to evolve after a set amount of time
  • Persist a user's Pokedex to disk so they can save progress between sessions
  • Use the PokeAPI to make exploration more interesting. For example, rather than typing the names of areas, maybe you are given choices of areas and just type "left" or "right"
  • Random encounters with wild pokemon
  • Adding support for different types of balls (Pokeballs, Great Balls, Ultra Balls, etc), which have different chances of catching pokemon

go-pokedex's People

Contributors

divyue30597 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.