hello hello and welcome to part 15 of
hello hello and welcome to part 15 of our go language tutorial series in this
our go language tutorial series in this
our go language tutorial series in this tutorial what we’re gonna be doing is
tutorial what we’re gonna be doing is
tutorial what we’re gonna be doing is using the mapping system that we’ve just
using the mapping system that we’ve just
using the mapping system that we’ve just learned in the previous tutorial and
learned in the previous tutorial and
learned in the previous tutorial and applying that to our news aggregator
applying that to our news aggregator
applying that to our news aggregator application so at this point I’m going
application so at this point I’m going
application so at this point I’m going back to the code for that news
back to the code for that news
back to the code for that news aggregator app that we left off on
aggregator app that we left off on
aggregator app that we left off on basically we’re to the point where we we
basically we’re to the point where we we
basically we’re to the point where we we visited the the site map that contains a
visited the the site map that contains a
visited the the site map that contains a bunch of site maps we’ve pulled those
bunch of site maps we’ve pulled those
bunch of site maps we’ve pulled those locations to all the other site maps and
locations to all the other site maps and
locations to all the other site maps and now we’re parsing all those site maps
now we’re parsing all those site maps
now we’re parsing all those site maps basically and well at least we’re just
basically and well at least we’re just
basically and well at least we’re just grabbing that information basically and
grabbing that information basically and
grabbing that information basically and throwing it into end basically and
throwing it into end basically and
throwing it into end basically and parsing out the titles keywords and
parsing out the titles keywords and
parsing out the titles keywords and locations but at that point what we
locations but at that point what we
locations but at that point what we probably like to do is store that in
probably like to do is store that in
probably like to do is store that in some sort of map that we can then
some sort of map that we can then
some sort of map that we can then iterate through and basically pass so so
iterate through and basically pass so so
iterate through and basically pass so so that we can just pass just that map over
that we can just pass just that map over
that we can just pass just that map over and iterate over that now it could be
and iterate over that now it could be
and iterate over that now it could be the case that actually you could just
the case that actually you could just
the case that actually you could just pass the news struct and then try to
pass the news struct and then try to
pass the news struct and then try to iterate over that as well I just think
iterate over that as well I just think
iterate over that as well I just think probably putting it into a map makes a
probably putting it into a map makes a
probably putting it into a map makes a little bit more sense also if you were
little bit more sense also if you were
little bit more sense also if you were gonna probably convert it to a JSON or
gonna probably convert it to a JSON or
gonna probably convert it to a JSON or something like that it would make more
something like that it would make more
something like that it would make more sense that way as well but in theory you
sense that way as well but in theory you
sense that way as well but in theory you you could leave the news struct and then
you could leave the news struct and then
you could leave the news struct and then iterate over that as well but that’s not
iterate over that as well but that’s not
iterate over that as well but that’s not what we’re gonna do we’re gonna throw it
what we’re gonna do we’re gonna throw it
what we’re gonna do we’re gonna throw it into map of keys and values and all that
into map of keys and values and all that
into map of keys and values and all that I think it’ll be a little cleaner and
I think it’ll be a little cleaner and
I think it’ll be a little cleaner and easier for us I think to iterate over
easier for us I think to iterate over
easier for us I think to iterate over when we do pass it to our web app so
when we do pass it to our web app so
when we do pass it to our web app so first of all what we’re going to go
first of all what we’re going to go
first of all what we’re going to go ahead and do this since we talked about
ahead and do this since we talked about
ahead and do this since we talked about the previous tutorial you’re not going
the previous tutorial you’re not going
the previous tutorial you’re not going to be able to make a map to multiple
to be able to make a map to multiple
to be able to make a map to multiple values you could only map you know to a
values you could only map you know to a
values you could only map you know to a single type value so if you wanted to
single type value so if you wanted to
single type value so if you wanted to have multiple values what you can do is
have multiple values what you can do is
have multiple values what you can do is create a struct create your own type so
create a struct create your own type so
create a struct create your own type so that’s what we’re gonna do now so we’re
that’s what we’re gonna do now so we’re
that’s what we’re gonna do now so we’re going to just do it type and we’re going
going to just do it type and we’re going
going to just do it type and we’re going to call this news map it’s going to be a
to call this news map it’s going to be a
to call this news map it’s going to be a struct and this type will just contain
struct and this type will just contain
struct and this type will just contain keyword which will be a string and then
keyword which will be a string and then
keyword which will be a string and then it’s going to contain location which
it’s going to contain location which
it’s going to contain location which will also be a string keyword should be
will also be a string keyword should be
will also be a string keyword should be plural because it’s going to be but
plural because it’s going to be but
plural because it’s going to be but we’ve got enough keywords I mean we
we’ve got enough keywords I mean we
we’ve got enough keywords I mean we could do it I don’t think you’d wind up
could do it I don’t think you’d wind up
could do it I don’t think you’d wind up in trouble
in trouble
in trouble I’m just gonna leave it that way for now
I’m just gonna leave it that way for now
I’m just gonna leave it that way for now anyway you might be thinking oh but
anyway you might be thinking oh but
anyway you might be thinking oh but Harrison titles well what I’m gonna do
Harrison titles well what I’m gonna do
Harrison titles well what I’m gonna do is I’m gonna make the key of the map the
is I’m gonna make the key of the map the
is I’m gonna make the key of the map the title and then keyword and location will
title and then keyword and location will
title and then keyword and location will be our values so that’s gonna be our
be our values so that’s gonna be our
be our values so that’s gonna be our news map now we’re gonna go ahead and do
news map now we’re gonna go ahead and do
news map now we’re gonna go ahead and do is come down into our main loop here and
is come down into our main loop here and
is come down into our main loop here and then we’re just gonna add a new variable
then we’re just gonna add a new variable
then we’re just gonna add a new variable here which will be the the news map
here which will be the the news map
here which will be the the news map itself so we’re just going to say news
itself so we’re just going to say news
itself so we’re just going to say news map colon equals and then that’s gonna
map colon equals and then that’s gonna
map colon equals and then that’s gonna be make make what we’re gonna make a map
be make make what we’re gonna make a map
be make make what we’re gonna make a map and that’ll be a map where the key is a
and that’ll be a map where the key is a
and that’ll be a map where the key is a string and the values are news map
string and the values are news map
string and the values are news map values so then what we’re gonna do is we
values so then what we’re gonna do is we
values so then what we’re gonna do is we can
can
can we’vewe’ve unmarshal this data to to our
we’vewe’ve unmarshal this data to to our
we’vewe’ve unmarshal this data to to our news type here so we know we have all
news type here so we know we have all
news type here so we know we have all that information and we we can iterate
that information and we we can iterate
that information and we we can iterate over that information so and then as we
over that information so and then as we
over that information so and then as we iterate over that information we can
iterate over that information we can
iterate over that information we can store it into our map so that’s what
store it into our map so that’s what
store it into our map so that’s what we’re gonna do now so basically we’re
we’re gonna do now so basically we’re
we’re gonna do now so basically we’re just gonna start a new for loop so for
just gonna start a new for loop so for
just gonna start a new for loop so for and then it’ll be the value basically
and then it’ll be the value basically
and then it’ll be the value basically and then or for the index rather and
and then or for the index rather and
and then or for the index rather and then or actually you probably want to do
then or actually you probably want to do
then or actually you probably want to do sorry probably one of the incentives for
sorry probably one of the incentives for
sorry probably one of the incentives for the index and then we don’t actually
the index and then we don’t actually
the index and then we don’t actually care about the value here we’re gonna
care about the value here we’re gonna
care about the value here we’re gonna say colon equals range and then we’re
say colon equals range and then we’re
say colon equals range and then we’re just gonna do end keywords and so this
just gonna do end keywords and so this
just gonna do end keywords and so this is gonna be kind of a hacky way to do
is gonna be kind of a hacky way to do
is gonna be kind of a hacky way to do this there’s there’s probably a better
this there’s there’s probably a better
this there’s there’s probably a better way to do it maybe some sort of like
way to do it maybe some sort of like
way to do it maybe some sort of like range and a length of something
range and a length of something
range and a length of something something like that but this should work
something like that but this should work
something like that but this should work as well so because we’re just gonna grab
as well so because we’re just gonna grab
as well so because we’re just gonna grab the the values and keywords so maybe it
the the values and keywords so maybe it
the the values and keywords so maybe it would be even better to grab like rather
would be even better to grab like rather
would be even better to grab like rather than keywords do like n dot titles maybe
than keywords do like n dot titles maybe
than keywords do like n dot titles maybe like that might be more efficient and
like that might be more efficient and
like that might be more efficient and then entering over them I don’t know I
then entering over them I don’t know I
then entering over them I don’t know I actually don’t know if that’ll change or
actually don’t know if that’ll change or
actually don’t know if that’ll change or anything
anything
anything anyways all we really want to get is an
anyways all we really want to get is an
anyways all we really want to get is an index value like that’s what I’m after
index value like that’s what I’m after
index value like that’s what I’m after so then what we’re gonna say is oops
so then what we’re gonna say is oops
so then what we’re gonna say is oops training that like a Python anyway I was
training that like a Python anyway I was
training that like a Python anyway I was like why didn’t an indent
like why didn’t an indent
like why didn’t an indent for me so now we’re going to say is news
for me so now we’re going to say is news
for me so now we’re going to say is news underscore map because for this value
underscore map because for this value
underscore map because for this value variable that we just defined up here so
variable that we just defined up here so
variable that we just defined up here so news map and then the title will just be
news map and then the title will just be
news map and then the title will just be n whoops
n whoops
n whoops n dot titles which is that that slice of
n dot titles which is that that slice of
n dot titles which is that that slice of titles so then to get a specific element
titles so then to get a specific element
titles so then to get a specific element we can grab it with the index of that
we can grab it with the index of that
we can grab it with the index of that element so we can just say I DX so news
element so we can just say I DX so news
element so we can just say I DX so news map whatever title equals the news map
map whatever title equals the news map
map whatever title equals the news map type that we just kind of that we just
type that we just kind of that we just
type that we just kind of that we just created basically and in there what
created basically and in there what
created basically and in there what we’re gonna say is n dot and then we’ll
we’re gonna say is n dot and then we’ll
we’re gonna say is n dot and then we’ll do keywords keywords let me make sure
do keywords keywords let me make sure
do keywords keywords let me make sure yet so keyword came first and then
yet so keyword came first and then
yet so keyword came first and then location so n dot keywords ID X and then
location so n dot keywords ID X and then
location so n dot keywords ID X and then n dot capital locations ID x cool and
n dot capital locations ID x cool and
n dot capital locations ID x cool and then now what we could do is iterate
then now what we could do is iterate
then now what we could do is iterate over iterate over the the the things
over iterate over the the the things
over iterate over the the the things inside of our map like so basically once
inside of our map like so basically once
inside of our map like so basically once we’ve gone through all the locations
we’ve gone through all the locations
we’ve gone through all the locations like basically up to this point we
like basically up to this point we
like basically up to this point we should have now news map which contains
should have now news map which contains
should have now news map which contains all the data we’re interested in this
all the data we’re interested in this
all the data we’re interested in this should contain the the titles right the
should contain the the titles right the
should contain the the titles right the keywords to articles and the locations
keywords to articles and the locations
keywords to articles and the locations of all the articles so if we wanted what
of all the articles so if we wanted what
of all the articles so if we wanted what we’re more interested in doing is
we’re more interested in doing is
we’re more interested in doing is displaying this on our web app but if we
displaying this on our web app but if we
displaying this on our web app but if we wanted to iterate over this we could do
wanted to iterate over this we could do
wanted to iterate over this we could do something like for ID X data : eat
something like for ID X data : eat
something like for ID X data : eat whoops :
whoops :
whoops : why is that keep happening : equals that
why is that keep happening : equals that
why is that keep happening : equals that must be hitting the backspace key at the
must be hitting the backspace key at the
must be hitting the backspace key at the same time range news map let’s go ahead
same time range news map let’s go ahead
same time range news map let’s go ahead and format dot print line and then let’s
and format dot print line and then let’s
and format dot print line and then let’s just add some new lines here this is do
just add some new lines here this is do
just add some new lines here this is do three and then the index and then let’s
three and then the index and then let’s
three and then the index and then let’s go ahead and format die
go ahead and format die
go ahead and format die it’s a print line and then I’m just
it’s a print line and then I’m just
it’s a print line and then I’m just gonna do two more so index should be the
gonna do two more so index should be the
gonna do two more so index should be the title right and then we want to see the
title right and then we want to see the
title right and then we want to see the keywords so let’s just do keyword or I’m
keywords so let’s just do keyword or I’m
keywords so let’s just do keyword or I’m sorry what we need to do is data dot
sorry what we need to do is data dot
sorry what we need to do is data dot keyword and then data dot location okay
keyword and then data dot location okay
keyword and then data dot location okay let’s save that and let’s run that make
let’s save that and let’s run that make
let’s save that and let’s run that make sure we didn’t screw anything up because
sure we didn’t screw anything up because
sure we didn’t screw anything up because we probably did yeah index out of range
we probably did yeah index out of range
we probably did yeah index out of range boy would I like a better error than
boy would I like a better error than
boy would I like a better error than that it doesn’t even give me a line
that it doesn’t even give me a line
that it doesn’t even give me a line number oh it does here 38 okay so here
number oh it does here 38 okay so here
number oh it does here 38 okay so here keywords index let’s try
and titles let’s try keywords here you
and titles let’s try keywords here you rerun that real quick see if we run on
rerun that real quick see if we run on
rerun that real quick see if we run on that same issue
somewhere yes so it’s definitely
somewhere yes so it’s definitely something to do with our keywords like
something to do with our keywords like
something to do with our keywords like it’s not getting populated so for range
it’s not getting populated so for range
it’s not getting populated so for range and dot keyword n is our news okay so
and dot keyword n is our news okay so
and dot keyword n is our news okay so our issue here is likely this capital K
our issue here is likely this capital K
our issue here is likely this capital K that’s gonna be my guess
that’s gonna be my guess
that’s gonna be my guess so I’m gonna switch that to lowercase K
so I’m gonna switch that to lowercase K
so I’m gonna switch that to lowercase K because I don’t think it was a capital K
because I don’t think it was a capital K
because I don’t think it was a capital K hopefully that’s our only issue let’s
hopefully that’s our only issue let’s
hopefully that’s our only issue let’s see what happens
okay yeah so that was our issue so the
okay yeah so that was our issue so the reason why first of all it was like so
reason why first of all it was like so
reason why first of all it was like so when we passed n dot so we should be
when we passed n dot so we should be
when we passed n dot so we should be able to change this back to titles and
able to change this back to titles and
able to change this back to titles and that should work
that should work
that should work basically titles was getting populated
basically titles was getting populated
basically titles was getting populated but keywords wasn’t because it was
but keywords wasn’t because it was
but keywords wasn’t because it was looking for a capital K tag and I wasn’t
looking for a capital K tag and I wasn’t
looking for a capital K tag and I wasn’t finding it so it was populating titles
finding it so it was populating titles
finding it so it was populating titles and locations but not keywords but then
and locations but not keywords but then
and locations but not keywords but then what we were trying to do was reference
what we were trying to do was reference
what we were trying to do was reference that specific index for a capital K
that specific index for a capital K
that specific index for a capital K keywords tag not the variable that we’re
keywords tag not the variable that we’re
keywords tag not the variable that we’re using here and it was like oh we don’t
using here and it was like oh we don’t
using here and it was like oh we don’t have that so that’s why that was
have that so that’s why that was
have that so that’s why that was throwing that error that was relatively
throwing that error that was relatively
throwing that error that was relatively unhelpful anyway um I changed back to
unhelpful anyway um I changed back to
unhelpful anyway um I changed back to title titles let’s try that one more
title titles let’s try that one more
title titles let’s try that one more time
time
time and then if that works we’ll be off –
and then if that works we’ll be off –
and then if that works we’ll be off – okay cool okay so now that we have all
okay cool okay so now that we have all
okay cool okay so now that we have all this information what we’re going to be
this information what we’re going to be
this information what we’re going to be doing now is going back to our web
doing now is going back to our web
doing now is going back to our web application information basically in
application information basically in
application information basically in part of this tutorial because now we’re
part of this tutorial because now we’re
part of this tutorial because now we’re getting close to being able to like hey
getting close to being able to like hey
getting close to being able to like hey let’s actually put this up on our on our
let’s actually put this up on our on our
let’s actually put this up on our on our web app so we’re going to be focusing
web app so we’re going to be focusing
web app so we’re going to be focusing back on learning a little bit more about
back on learning a little bit more about
back on learning a little bit more about web applications and go so if you have
web applications and go so if you have
web applications and go so if you have any more questions or if you’ve got
any more questions or if you’ve got
any more questions or if you’ve got comments tutorials tutorials if you have
comments tutorials tutorials if you have
comments tutorials tutorials if you have any tutorials let us know any way
any tutorials let us know any way
any tutorials let us know any way questions comments leaving below
questions comments leaving below
questions comments leaving below otherwise I will see you in the next
otherwise I will see you in the next
otherwise I will see you in the next tutorial
Be First to Comment