What is Libraries.io?
Libraries.io helps you keep track of your project’s dependencies and can notify you when there’s a new release of a library. It monitors projects from a variety of programming languages and package managers.
The project is developed and managed by Andrew Nesbitt, Benjamin Nickolls and a number of contributors from the Open Source community.
Why is it any useful?
Sometimes maintaining larger, successful Open Source projects can be quite exhausting and tiring (read about it in Nolan’s and Jan’s blog posts from last weekend), so I think that it’s important to automate those tasks, that can be automated, to free up some time for maintainers.
Keeping track of new releases of your dependencies, but also projects that depend on your library is a time-consuming and not very fun thing to do, if done manually. However it is crucial in understanding the scope of your project and making decisions about priorities for bugfixes and features.
This is why I personally think that libraries.io is a great project!
API client library
I’ve been wanting to learn more about developing API client libraries in Go. APIs allow me to use a service w/o having to use a specific web UI or app. API client libraries make APIs more accessible by taking away part of the complexity (for instance one does not need to care about resource deserialization or error handling).
Since Libraries.io offers an API, I decided to write go-librariesio, a client library for Libraries.io in Go. Distributed under the terms of the MIT License, it is free and open source software.
You can find the repository on GitHub at github.com/hackebrot/go-librariesio! 😄
Usage
Connecting to the libraries.io API with go-librariesio requires a private API key.
// Create new API client with your API key
c := librariesio.NewClient("... your API key ...")
// Create a new context (with a timeout if you want)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
// Request information about a project using the client
project, _, err := c.Project(ctx, "pypi", "cookiecutter")
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
// All structs for API resources use pointer values.
// If you expect fields to not be returned by the API
// make sure to check for nil values before dereferencing.
fmt.Printf("name: %v\n", *project.Name)
fmt.Printf("version: %v\n", *project.LatestReleaseNumber)
fmt.Printf("language: %v\n", *project.Language)
Contributing
At this point only the Project
endpoint is supported, but I’ve
implemented the framework for accesssing the API, deserializing resources
and writing unit tests.
I will happily review PRs for adding new endpoints, so I created a number of help wanted issues for new contributors to pick up. Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
Please check out the contributing guide and be sure to read the project’s code of conduct. Thank you!
Feedback
Do you like go-librariesio? Let me know on twitter. 😃