oxffaa/gopher-parse-sitemap

How can I extend this package to parse and catch other attribute of sitemap?

Twister7 opened this issue · 0 comments

This package is very handy and useful and its totally functional. However I think I could not find a way to extend and use this package in my app to catch an additional attribute of the sitemap without changing the code of package.

For example I have a sitemap like this :

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
    <url>
        <loc>https://example.com/123</loc>
        <xhtml:link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.example.com/123" />
        <image:image>
            <image:loc>https://example.com/123.jpg</image:loc>
            <image:title>example title</image:title>
            <image:caption>example capltion</image:caption>
        </image:image>
    </url>
</urlset>

To catch image data I add a function GetImage() in Entry interface and implement it in sitemap_types.go file also a minor change in sitemapEntry struct. But as you see I changed the package source code which is tribe idea IMO.

I google a lot how to extend struct and interface and I find some approach which is named Composition
But I couldn't apply this because when I trace the code, at entryParser function new entry will create from sitemapEntry Struct and its not parametric so I couldn't tell to package to create and entry from extended struct which is create Composition approach.
So the question is How can I extend this package to parse and catch other attribute of sitemap without touching source code of package?

I'm new in go and any help and suggestion could be helpful