This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count int | |
func GetPdfUrl(ctx context.Context) (string, error) { | |
count++ | |
if count <= 3 { | |
return "", errors.New("boom") | |
} else { | |
return "https://linktopdf.com", nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Effector func(context.Context) (string, error) | |
func Retry(effector Effector, retries int, delay time.Duration) Effector { | |
return func(ctx context.Context) (string, error) { | |
for r := 0; ; r++ { | |
response, err := effector(ctx) | |
if err == nil || r >= retries { | |
// Return when there is no error or the maximum amount | |
// of retries is reached. | |
return response, err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// squares returns a function that returns | |
// the next square number each time it is called. | |
func squares() func() int { | |
var x int | |
return func() int { | |
x++ | |
return x * x | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GetUrlElement = ({ host, route, date }: Url): string => { | |
if (date) { | |
return `<url><loc>${host}${route}</loc><lastmod>${date}</lastmod></url>`; | |
} else return `<url><loc>${host}${route}</loc></url>`; | |
}; | |
const GetSitemapXml = (urls: Array<Url>): string => `<?xml version="1.0" encoding="UTF-8"?> | |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | |
${urls.map((url) => GetUrlElement(url)).join('')} | |
</urlset>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GetServerSideProps } from 'next'; | |
import fs from 'fs'; | |
import path from 'path'; | |
// This functions returns a domain based on the NODE_ENV setting | |
import { GetCurrentDomain } from '../utils/UrlBuilder'; | |
export default function Sitemap() {} | |
type Url = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Breadcrumb breadcrumbItems={breadcrumb} /> | |
/// Data passed could be something like: | |
const breadcrumb = [ | |
{url:'https://example.com/', name:"Home"}, | |
{url:'https://example.com/bikes', name:"Bikes"}, | |
{url:'https://example.com/bikes/bike-x', name:"Bike-X"}]; |
NewerOlder