go-osf

module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2022 License: MIT

README

Open Science Framework (OSF) SDK for Golang

Go Version GoDoc Go Report Card

go-osf if a Go client library for accessing the Open Science Framework (OSF) API.

Installation

go-osf makes use of the generics, so it requires Go v1.18.

To use this library within a Go module project:

go get github.com/joshuabezaleel/go-osf

Usage

An OSF access token is required to use this library. You can create one from the OSF settings page. You can create an account if you haven't had already.

The following code gets the first 100 public preprints from the OSF.

package main

import (
	"context"
	"log"

	"github.com/joshuabezaleel/go-osf/osf"
	"golang.org/x/oauth2"
)

func main() {
	ctx := context.Background()
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: "your token here ..."},
	)
	tc := oauth2.NewClient(ctx, ts)

	client := osf.NewClient(tc)

	opts := &osf.PreprintsListOptions{
		ListOptions: osf.ListOptions{
			Page:    1,
			PerPage: 100,
		},
	}
	preprints, _, err := client.Preprints.ListPreprints(ctx, opts)
	if err != nil {
		log.Fatal(err)
	}

	for _, preprint := range preprints {
		log.Printf("URL: %s", *preprint.Links.Html)
		log.Printf("Title: %s", preprint.Title)
		log.Printf("Description: %s", preprint.Description)
	}

}

Head over to the examples folder or pkg.go.dev for more usage examples.

License

This library is distributed under the MIT license found in the LICENSE.txt file.

Directories

Path Synopsis
Package osf provides a client for using the Open Science Framework (OSF, https://osf.io) API.
Package osf provides a client for using the Open Science Framework (OSF, https://osf.io) API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL