Using go enums
I have this code below but im not sure how the enum's side of things is working with the input like how I can determine the case in the switch to activate. Any thoughts?
17 Replies
imma say it, that's garbage don't use it
go doesn't have enums, anyone saying "this is how you can have enums" is just doing a scuffed thing go isn't supposed to do
will they add them eventually? probably, but it is not a thing now and as such it is not something I'd force
specially for 2 damn variables
is the validation stuff ok?
all this is doing is saying Zip and AirportCode are of type
InputType
which is of type int
iota starts at 0
and adds 1 to every const declared within the same block
so zip
is 0 and AirportCode
is 1so it's useless in this situation
I mean
not entirely useless no
tho idk where it comes from
where is validateInput being called?
ive not got that far yet but the goal is in main.go down the road... validate input, convert input into api call format, get the returned json, pull the json info out and display it in the city page
then it is useless here
im just trying to think of a way to send the input to those based on some condition
like some check early on says ok send this to zip code
for that you'd have to parse the user's input I presume
I guess check for a starting digit for zip
im guessing there are cities in the world with very few letters
so input len is a bit odd
airport codes are 3 characters
you need to understand better what your inputs are
that's all I really know
zip is all digits
airport is 3 characters
city can be any lenghth
if that's all you know...you need to understand them better
if the fellas on the API can parse it and use it correctly it's cause it's not arbitrary and each type is unique in some way
find the uniqueness
yeah this is their doc
Weather and Geolocation API - Weather and Geolocation API JSON an...
WeatherAPI.com offer comprehensive Global and Local Weather API, Geo API, Astronomy API and Time Zone API. Simple to use, powerful, fully managed and free!
technically they can take multiple forms of input including json (if you pay for it), for me I tried to limit it to cases commonly used like zip code, airport, and city
airport codes are preferably all caps, where city names are just UCFirst
also, airport codes conform to a single, known list of abbreviations you can check against where the list of cities is just too long for that