go-osf if a Go client library for accessing the Open Science Framework (OSF) API.
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
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.
This library is distributed under the MIT license found in the LICENSE.txt file.