Skip to content

joshuabezaleel/go-osf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Open Science Framework (OSF) SDK for Golang

Go Version GoDoc tests 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.

About

Go wrapper for OSF (Open Science Framework) API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages