Skip to content
linkvitePublic

About

🦫 Go SDK for Linkvite.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

40 Commits

Folders and files

Repository files navigation

linkvite-go

The official Go SDK for Linkvite. Its services and types are generated from the Linkvite OpenAPI spec, so every endpoint, request and response matches the API.

go get github.com/linkvite/go/v2

Requires Go 1.24+. No dependencies outside the standard library.

Quick start

client, err := linkvite.NewClient(os.Getenv("LINKVITE_API_KEY"))
if err != nil {
	log.Fatal(err)
}

b, err := client.Bookmarks.Create(ctx, &linkvite.CreateBookmarkRequest{
	URL:  "https://example.com",
	Tags: "reading",
})

page, err := client.Bookmarks.GetAll(ctx, &linkvite.BookmarksGetAllParams{
	Q:     linkvite.Ptr("rust"),
	Limit: linkvite.Ptr(50),
})

Path parameters are arguments, request bodies are *XRequest structs, and query parameters are *XParams structs (pass nil for none). Optional values are pointers: use linkvite.Ptr.

Authentication

You're building Use
A script or server acting as your own account An API key (Settings → Developers): linkvite.NewClient("link_...")
An app other people sign in to OAuth (authorization code + PKCE), below
A first-party tool signing in with a password linkvite.NewClientWithCredentials(ctx, user, pass)

OAuth with golang.org/x/oauth2

The oauth2 package's HTTP client adds the bearer token and refreshes it (Linkvite's refresh tokens rotate; oauth2.ReuseTokenSource handles that).

conf := &oauth2.Config{
	ClientID:    "app_...",
	RedirectURL: "https://example.com/callback",
	Scopes:      []string{"bookmarks:read", "bookmarks:write"},
	Endpoint:    oauth2.Endpoint{AuthURL: linkvite.AuthURL, TokenURL: linkvite.TokenURL},
}
verifier := oauth2.GenerateVerifier()
url := conf.AuthCodeURL(state, oauth2.S256ChallengeOption(verifier))
// ...on the redirect back:
tok, err := conf.Exchange(ctx, code, oauth2.VerifierOption(verifier))

client, err := linkvite.NewClient("", linkvite.WithHTTPClient(conf.Client(ctx, tok)))

Or bring your own token: linkvite.NewClientWithTokens(access, refresh), WithTokenSource(...), and WithOnUnauthorized(...) to refresh and retry once on a 401.

Errors

_, err := client.Bookmarks.Get(ctx, "bmk_123")
var e *linkvite.Error
if errors.As(err, &e) {
	e.Status    // 400, 401, 402 (Pro required), 404, 429, ... (0: network error)
	e.Errors    // field -> problem, for validation errors
	e.RequestID // quote this when contacting support
}
if linkvite.IsNotFound(err) { ... }

Idempotent requests (GET, PUT, DELETE) are retried on 429, 5xx and network errors (twice by default, honouring Retry-After; WithMaxRetries changes it). Cancel with the context.

Pagination

for b, err := range linkvite.Paginate(ctx, func(ctx context.Context, page int) ([]linkvite.BookmarkResponse, *linkvite.Pagination, error) {
	r, err := client.Bookmarks.GetAll(ctx, &linkvite.BookmarksGetAllParams{Page: linkvite.Ptr(page), Limit: linkvite.Ptr(100)})
	if err != nil {
		return nil, nil, err
	}
	return r.Bookmarks, r.Pagination, nil
}) {
	if err != nil {
		return err
	}
	fmt.Println(b.Title)
}

Files

f, _ := os.Open("paper.pdf")
err := client.Bookmarks.CreateFile(ctx, &linkvite.BookmarksCreateFileRequest{
	File:       linkvite.File{Name: "paper.pdf", Reader: f},
	Collection: linkvite.Ptr("col_123"),
})

Anything else

client.Do(ctx, method, path, query, body, &out) calls any endpoint, including ones newer than the SDK, decoding the response's data into out.

Services

APIKeys, Apps, Bookmarks, Collections, Comments, Explore, Feed, Files, Highlights, InviteLinks, Invites, Notifications, Parser, Plans, Profiles, Reminders, RSSFeeds, Search, User. Each method's doc comment gives its scope, rate limit and route; the full reference is at docs.linkvite.io.

Upgrading from v1

  • Import github.com/linkvite/go/v2.
  • Types are now named after the API's schemas (CreateBookmarkRequest, BookmarkResponse, ...), and list methods take a *XParams struct.
  • Errors are *linkvite.Error (Status, Errors, RequestID).
  • New services: Apps, Explore, Feed, Files, InviteLinks, Notifications, Plans, Profiles.
  • Removed (no longer in the API): bookmark re-parse, bookmarks by tag, collection star, comment report.

Development

make generate SPEC=../cultus/api/openapi.json   # refresh the spec (cultus: make openapi) and regenerate
make check                                       # generated code current + lint + tests

types_gen.go and services_gen.go are generated by internal/gen; don't edit them. Method names come from x-linkvite-sdk in the spec, shared with the JS SDK.

To release a new version, see RELEASE.md.

License

MIT

About

🦫 Go SDK for Linkvite.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages