hensur / go-harbor

A Harbor API client enabling Go programs to interact with Harbor in a simple and uniform way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-harbor

A Harbor API client enabling Go programs to perform CRUD operations on goharbor users and projects

GitHub license

This library is mainly build upon goharbor/v1.10.1

Usage

Initialize a new go-harbor client, then use the various services on the client to access different parts of the Harbor API.

package main

import (
    "errors"
    "fmt"
    "github.com/elenz97/go-harbor"
)

func main() {
    client, err := harbor.NewClient("url", "username", "password")
    if err != nil {
        panic(err)
    }

    // Projects
    projects, err := client.Projects().ListProjects(harbor.ListProjectOptions{})
    if err != nil {
        var e *harbor.StatusCodeError
        if errors.As(err, &e) {
            // handle status code error
            fmt.Printf("request failed with status code: %d", e.StatusCode)
        } else {
            panic(err)
        }
    }
    
    for _, p := range projects {
        fmt.Println(p.Name)
    }
    
    // Users
    users, err := client.Users().ListUsers()
    // ...
}

Documentation

For more specific documentation, please refer to the godoc of this library

About

A Harbor API client enabling Go programs to interact with Harbor in a simple and uniform way

License:MIT License


Languages

Language:Go 100.0%