{"id":470,"date":"2026-06-02T09:00:00","date_gmt":"2026-06-02T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/"},"modified":"2026-06-02T09:00:00","modified_gmt":"2026-06-02T03:30:00","slug":"go-pagination-rest-api","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/","title":{"rendered":"Go Pagination for REST APIs: Offset vs Cursor"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go pagination lets your API return a long list in small pages instead of one huge reply. In this post, you will learn two popular styles, offset and cursor. Then we will build cursor pagination in Go and test it page by page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/\">Go REST API for beginners<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/\">Go JSON encoding and decoding<\/a>. We also use ideas from <a href=\"https:\/\/smitabharat.com\/blog\/go-input-validation\/\">Go input validation<\/a>. So it helps to read those first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go Pagination?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine a library with 50,000 books. Now a user asks for the list of books. You would not hand over all 50,000 at once, because the reply would be huge and slow. Instead, you give ten books and tell the user to ask again for the next ten. That simple idea is pagination. It is also the base of every list API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In an API, each page is one response with a fixed number of items. The client reads the page, shows it and asks for the next one when needed. Go pagination is just the server code that decides which items belong on each page. So the idea is simple, even though the details need care.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are two main styles. The first is offset pagination, which says &#8220;skip 20 items and give me 10&#8221;. The second is cursor pagination, which says &#8220;give me 10 items after this marker&#8221;. Each has strengths and weaknesses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Pagination Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Without Go pagination, one request can load a whole table into memory. That is slow for the user, and it is also costly for your server. Here is what Go pagination gives you.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Faster replies<\/strong>: small pages are quick to build and quick to send.<\/li>\n\n\n\n<li><strong>Lower memory use<\/strong>: the server never holds the full list in one response.<\/li>\n\n\n\n<li><strong>Smoother apps<\/strong>: a mobile app can show the first page while it loads the next.<\/li>\n\n\n\n<li><strong>Fair use<\/strong>: a client cannot ask for everything in one call.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">However, bad pagination can cause strange bugs. Items can appear twice or vanish between pages. Therefore, the choice of style matters, and we will see why in a moment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Pagination Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every paged API follows the same loop, and Go pagination is no different. First, the client sends a request with a page size. Next, the server returns the items and a hint for the next page. Then the client uses that hint in its next request.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-1-1024x640.png\" alt=\"Go Pagination diagram showing three requests, three pages and the cursor passed to each next request\" class=\"wp-image-460\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The client asks for a page with a limit. The server returns the items plus a next cursor. The client sends that cursor to get the following page, until no cursor is returned.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">How Offset Pagination Works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With offset pagination, the client sends <code>limit<\/code> and <code>offset<\/code>. For example, <code>limit=10&amp;offset=20<\/code> means &#8220;skip 20 and take 10&#8221;. In SQL, this maps to <code>LIMIT 10 OFFSET 20<\/code>. It is easy to understand, and you can also jump to any page number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Cursor Pagination Works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With cursor pagination, the client sends <code>limit<\/code> and a <code>cursor<\/code>. The cursor marks the last item of the previous page. In our example, it is the last ID, encoded as text. The server returns the items that come after that ID. When there are no more items, it returns no cursor at all.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Pagination: Offset vs Cursor<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The two styles behave differently as data grows and changes. The table below compares them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Offset<\/th><th>Cursor<\/th><\/tr><\/thead><tbody><tr><td>Jump to page 50<\/td><td>Easy<\/td><td>Not possible<\/td><\/tr><tr><td>Speed on big tables<\/td><td>Slows down as the offset grows<\/td><td>Stays fast with an index<\/td><\/tr><tr><td>New rows during paging<\/td><td>Items may repeat or be skipped<\/td><td>Stable results<\/td><\/tr><tr><td>Client code<\/td><td>Very simple<\/td><td>Slightly more steps<\/td><\/tr><tr><td>Best for<\/td><td>Admin tables with page numbers<\/td><td>Feeds, timelines and APIs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-2-1024x640.png\" alt=\"Go Pagination diagram comparing offset and cursor pages when a new row appears\" class=\"wp-image-461\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">With offset pagination, a new row at the top shifts every later item, so a page repeats an item. With cursor pagination, the marker stays on the same item.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here is why offset can fail. Suppose you read page 1. Then a new row appears at the top. When you ask for page 2, every item has moved down by one. As a result, the last item of page 1 shows up again on page 2. A cursor avoids this, because it points to a specific item and not to a position. For this reason, most public APIs use cursors for feeds.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Pagination Request and Response Design<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Good Go pagination starts with a clear contract. Clients should know which parameters exist and what comes back. The table below shows a simple design that works for most APIs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Part<\/th><th>Name<\/th><th>Example<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>Request<\/td><td>limit<\/td><td>10<\/td><td>How many items to return<\/td><\/tr><tr><td>Request<\/td><td>cursor<\/td><td>MTA=<\/td><td>Where the next page starts<\/td><\/tr><tr><td>Response<\/td><td>items<\/td><td>A list of objects<\/td><td>The data for this page<\/td><\/tr><tr><td>Response<\/td><td>next_cursor<\/td><td>MjA=<\/td><td>Cursor for the following page<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Keep the names stable, because mobile apps may stay on an old version for months. Also, add the new fields instead of renaming old ones. In that way, no client breaks when you improve the API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What About the Total Count?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Many clients ask for the total number of items. Counting a big table on every request is slow, though. So, return a total only when the user really needs page numbers. Otherwise, a simple &#8220;next&#8221; button works fine, and it keeps each request cheap.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pagination with a Database<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In a real project, the loop in our handler becomes a query. For cursor pages, the query looks like <code>WHERE id &gt; $1 ORDER BY id LIMIT $2<\/code>. An index on <code>id<\/code> makes it fast, even on millions of rows. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-database-sql-tutorial\/\">Go database\/sql tutorial<\/a> shows how to run such a query safely.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Pagination Hands-On: Cursor Pages<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s build cursor pagination. We use 25 fake books with IDs from 1 to 25, so that we can see every page.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Types and the Handler<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, an <code>Item<\/code> has an ID and a name, while the <code>Page<\/code> holds the list. A <code>Page<\/code> also holds an optional <code>next_cursor<\/code>. Then the handler reads <code>limit<\/code> and <code>cursor<\/code> from the query string. After that, it collects the items after the cursor, and it builds the next cursor.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type Page struct {\n\tItems      []Item `json:\"items\"`\n\tNextCursor string `json:\"next_cursor,omitempty\"`\n}\n\nfunc listHandler(w http.ResponseWriter, r *http.Request) {\n\tlimit, err := strconv.Atoi(r.URL.Query().Get(\"limit\"))\n\tif err != nil || limit &lt; 1 || limit &gt; 100 {\n\t\tlimit = 10\n\t}\n\tafter := 0\n\tif c := r.URL.Query().Get(\"cursor\"); c != \"\" {\n\t\traw, err := base64.URLEncoding.DecodeString(c)\n\t\tif err != nil {\n\t\t\thttp.Error(w, \"bad cursor\", http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\t\tafter, _ = strconv.Atoi(string(raw))\n\t}\n\n\tvar page Page\n\tfor _, it := range items {\n\t\tif it.ID &gt; after {\n\t\t\tpage.Items = append(page.Items, it)\n\t\t\tif len(page.Items) == limit {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\tif n := len(page.Items); n == limit &amp;&amp; page.Items[n-1].ID &lt; items[len(items)-1].ID {\n\t\tpage.NextCursor = base64.URLEncoding.EncodeToString([]byte(strconv.Itoa(page.Items[n-1].ID)))\n\t}\n\tjson.NewEncoder(w).Encode(page)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at the key lines. The limit has a default of 10 and a hard cap of 100. Because of this, a client cannot ask for a million items. The cursor is the last ID in base64, which hides the inner detail from the client. In other words, you can change the format later. Finally, <code>omitempty<\/code> leaves out <code>next_cursor<\/code> on the last page, and that is how the client knows to stop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Walk Through All the Pages<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Then we write a loop that acts like a client. It asks for a page and prints a summary. After that, it follows the cursor until none is left.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\th := http.HandlerFunc(listHandler)\n\turl := \"\/books?limit=10\"\n\tfor page := 1; ; page++ {\n\t\tp := get(h, url)\n\t\tfmt.Printf(\"page %d: ids %d-%d, items=%d, next=%q\\n\", page, p.Items[0].ID, p.Items[len(p.Items)-1].ID, len(p.Items), p.NextCursor)\n\t\tif p.NextCursor == \"\" {\n\t\t\tbreak\n\t\t}\n\t\turl = \"\/books?limit=10&amp;cursor=\" + p.NextCursor\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the real output from our run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>page 1: ids 1-10, items=10, next=\"MTA=\"\npage 2: ids 11-20, items=10, next=\"MjA=\"\npage 3: ids 21-25, items=5, next=\"\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, 25 items arrive in three pages. The cursors <code>MTA=<\/code> and <code>MjA=<\/code> are just the numbers 10 and 20 in base64, so they are easy to check. On page 3, only five items remain, so the cursor is empty and the loop ends. This is Go pagination working from the first page to the last.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Pagination<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>No upper limit<\/strong>: a client can ask for a million rows. So always cap the page size, even for trusted clients.<\/li>\n\n\n\n<li><strong>Using offset on huge tables<\/strong>: the database must skip many rows each time. Therefore, prefer cursors for large or fast-changing data.<\/li>\n\n\n\n<li><strong>Sorting without a stable key<\/strong>: if two rows share the same sort value, they may swap places. Instead, sort by a unique column such as the ID.<\/li>\n\n\n\n<li><strong>Trusting the cursor<\/strong>: a client can send any text. So decode it carefully and return a 400 for bad input.<\/li>\n\n\n\n<li><strong>Missing the end signal<\/strong>: clients need to know when to stop. For that reason, return an empty cursor or a clear flag on the last page.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Pagination<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Set a default and a maximum page size<\/strong>, because both protect your server.<\/li>\n\n\n\n<li><strong>Sort by a unique, indexed column<\/strong>, since the cursor depends on a stable order.<\/li>\n\n\n\n<li><strong>Treat the cursor as opaque<\/strong>, which lets you change its format later.<\/li>\n\n\n\n<li><strong>Return the next cursor in the body<\/strong>, so clients do not build URLs by hand.<\/li>\n\n\n\n<li><strong>Validate every query value<\/strong>, because paging parameters come from users.<\/li>\n\n\n\n<li><strong>Document the style<\/strong>, so other teams know how to loop through your pages.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise Go pagination, add a <code>prev_cursor<\/code> field so clients can go back one page. Alternatively, add an offset version of the handler and compare the two on a changing list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: for the offset version, insert a new item at the start of the slice between two calls. Then watch an item appear twice, as in the second diagram.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages describe the packages used in this lesson.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/net\/http\">net\/http package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/encoding\/base64\">encoding\/base64 package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/strconv\">strconv package documentation<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go pagination returns a long list as small pages.<\/li>\n\n\n\n<li>Offset pagination skips a number of items, while cursor pagination continues after a marker.<\/li>\n\n\n\n<li>Cursors stay stable when data changes, and offsets can repeat or skip items.<\/li>\n\n\n\n<li>Always set a default and a maximum page size.<\/li>\n\n\n\n<li>Sort by a unique column so the order never changes.<\/li>\n\n\n\n<li>An empty cursor tells the client that the last page is done.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By now, you can serve large lists in small, stable pages. However, some data is read far more often than it changes. So next, we will build an in-memory cache with a time to live.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up: <a href=\"https:\/\/smitabharat.com\/blog\/go-in-memory-cache-ttl\/\">Go in-memory cache with TTL and generics<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go pagination lets your API return a long list in small pages instead of one huge reply. In this post, you will learn two&hellip;<\/p>\n","protected":false},"author":1,"featured_media":462,"comment_status":"","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,89,77],"swapz_series":[],"class_list":["post-470","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-pagination","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Pagination for REST APIs: Offset vs Cursor<\/title>\n<meta name=\"description\" content=\"Learn Go pagination for REST APIs. Compare offset and cursor styles, then build stable cursor pages with a limit and a next cursor in Go.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Pagination for REST APIs: Offset vs Cursor\" \/>\n<meta property=\"og:description\" content=\"Learn Go pagination for REST APIs. Compare offset and cursor styles, then build stable cursor pages with a limit and a next cursor in Go.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-02T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Pagination for REST APIs: Offset vs Cursor\",\"datePublished\":\"2026-06-02T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/\"},\"wordCount\":1544,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pagination-rest-api-featured.png\",\"keywords\":[\"Go Lang\",\"Go Pagination\",\"Intermediate\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/\",\"name\":\"Go Pagination for REST APIs: Offset vs Cursor\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pagination-rest-api-featured.png\",\"datePublished\":\"2026-06-02T03:30:00+00:00\",\"description\":\"Learn Go pagination for REST APIs. Compare offset and cursor styles, then build stable cursor pages with a limit and a next cursor in Go.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pagination-rest-api-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pagination-rest-api-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Pagination featured image: limit, cursor and item count cards\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pagination-rest-api\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Pagination for REST APIs: Offset vs Cursor\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Pagination for REST APIs: Offset vs Cursor","description":"Learn Go pagination for REST APIs. Compare offset and cursor styles, then build stable cursor pages with a limit and a next cursor in Go.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/","og_locale":"en_US","og_type":"article","og_title":"Go Pagination for REST APIs: Offset vs Cursor","og_description":"Learn Go pagination for REST APIs. Compare offset and cursor styles, then build stable cursor pages with a limit and a next cursor in Go.","og_url":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-06-02T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Pagination for REST APIs: Offset vs Cursor","datePublished":"2026-06-02T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/"},"wordCount":1544,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-featured.png","keywords":["Go Lang","Go Pagination","Intermediate"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/","url":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/","name":"Go Pagination for REST APIs: Offset vs Cursor","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-featured.png","datePublished":"2026-06-02T03:30:00+00:00","description":"Learn Go pagination for REST APIs. Compare offset and cursor styles, then build stable cursor pages with a limit and a next cursor in Go.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pagination-rest-api-featured.png","width":2400,"height":1260,"caption":"Go Pagination featured image: limit, cursor and item count cards"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-pagination-rest-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Pagination for REST APIs: Offset vs Cursor"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=470"}],"version-history":[{"count":0,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/470\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/462"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=470"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}