tkmcclellan / kocha

Kocha - Black Tea - A tool for reading manga.
MIT License
1 stars 0 forks source link

Improve provider detection #2

Closed tkmcclellan closed 2 years ago

tkmcclellan commented 2 years ago

All go files can have an init function that's called at the start of the program. Instead of hard coding the names of each provider in a list somewhere, add a map[string]interface{} map to provider.go that holds a map of names to providers. each provider should add their name and value to that map in their init function. so for example:

provider.go

ProviderList := map[string]interface{}{}

func FindProvider(provider string) Provider {
  return ProviderList[provider]
}

mangakakalot.go

func init() {
  ProviderList["mangakakalot"] = new(Mangakakalot)
}

This would make adding providers a bit more maintainable since all you would have to do is add that in each new provider. Whenever you add a new provider, nothing needs to be changed in any other files and you can just drop it in there.

You can also use ProviderList in other places where you need a list of providers. For instance, when adding a manga, instead of hardcoding values, you could just loop through that list.