github.com/blend/go-sdk@v1.20220411.3/examples/r2/request/main.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package main 9 10 import ( 11 "io" 12 "log" 13 "net/http" 14 "os" 15 "strconv" 16 17 "github.com/blend/go-sdk/r2" 18 ) 19 20 func makeRequest(path string, arguments ...r2.Option) (*http.Response, error) { 21 fullOptions := append(arguments, 22 r2.OptPath(path), 23 r2.OptQueryValue("limit", "10"), 24 r2.OptQueryValue("offset", "100"), 25 ) 26 27 return r2.New("http://localhost:5000", fullOptions...).Do() 28 } 29 30 func main() { 31 32 page := 10 33 pageSize := 50 34 opts := []r2.Option{ 35 r2.OptQueryValue("limit", strconv.Itoa(page)), 36 r2.OptQueryValue("offset", strconv.Itoa(page*pageSize)), 37 } 38 39 res, err := makeRequest("/headers", opts...) 40 if err != nil { 41 log.Fatal(err) 42 } 43 defer res.Body.Close() 44 io.Copy(os.Stdout, res.Body) 45 os.Exit(0) 46 }