cncf

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 8 Imported by: 0

README

CNCF Package

This package provides functionality to interact with the CNCF Landscape, specifically for querying project information from the landscape's data.

Features

  • Fetch and parse the official CNCF landscape data
  • Cache landscape data with configurable TTL
  • Search for projects by:
    • Repository URL
    • Homepage URL
    • Project name (case-insensitive)

Usage

import "github.com/neticdk/go-common/pkg/cncf"

// Create a client (or use your own that implements HTTPClient)
client := &cncf.DefaultHTTPClient{}

// Get the landscape data (cached for 1 hour by default)
landscape, err := cncf.GetLandscape(client)
if err != nil {
    // Handle error
}

// Find a project by repo URL
project := landscape.FindProject(cncf.FindProjectOptions{
    RepoURL: "https://github.com/kubernetes/kubernetes",
})

// Find a project by name
project = landscape.FindProject(cncf.FindProjectOptions{
    Name: "Kubernetes",
})

Cache Behavior

The package includes built-in caching of landscape data to avoid unnecessary network requests. The default cache TTL is 1 hour but can be modified by changing the CacheTTL constant.

Documentation

Overview

Package cncf provides functionality for interacting with the Cloud Native Computing Foundation (CNCF) landscape.

The package allows fetching and querying the official CNCF landscape data, which contains information about all CNCF projects, their status, and related metadata. It includes built-in caching to minimize network requests and provides a simple interface for finding projects by various identifiers.

Basic usage:

client := &cncf.DefaultHTTPClient{}
landscape, err := cncf.GetLandscape(client)
if err != nil {
	// Handle error
}

// Find a project
project := landscape.FindProject(cncf.FindProjectOptions{
	Name: "Kubernetes",
})

The landscape data is automatically cached for one hour (configurable via CacheTTL) to reduce network requests and improve performance.

Projects can be found by:

  • Repository URL
  • Homepage URL
  • Project name (case-insensitive matching)

Index

Constants

View Source
const (
	LandscapeURL = "https://raw.githubusercontent.com/cncf/landscape/master/landscape.yml"
	CacheTTL     = 1 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

type Category

type Category struct {
	Name          string        `yaml:"name"`
	Subcategories []Subcategory `yaml:"subcategories"`
}

type DefaultHTTPClient

type DefaultHTTPClient struct{}

DefaultHTTPClient is the default implementation of HTTPClient that uses http.Get.

func (*DefaultHTTPClient) Get

func (c *DefaultHTTPClient) Get(rawURL string) (*http.Response, error)

Get gets the content of the URL and returns the response.

type FindProjectOptions

type FindProjectOptions struct {
	// RepoURL is the URL of the repository.
	RepoURL string

	// HomepageURL is the URL of the project's homepage.
	HomepageURL string

	// Name is the name of the project.
	Name string
}

FindProjectOptions is a set of options to find a project in the landscape.

type HTTPClient

type HTTPClient interface {
	// Get gets the content of the URL and returns the response.
	Get(rawURL string) (*http.Response, error)
}

HTTPClient is an interface that abstracts the http.Get function.

type Landscape

type Landscape struct {
	Categories []Category `yaml:"landscape"`
}

func GetLandscape

func GetLandscape(client HTTPClient) (*Landscape, error)

GetLandscape fetches the CNCF landscape from the official repository

func (*Landscape) FindProject

func (l *Landscape) FindProject(opts FindProjectOptions) *Project

FindProject finds a project in the landscape by repo URL, homepage URL, or name.

type Project

type Project struct {
	Name        string `yaml:"name"`
	HomepageURL string `yaml:"homepage_url"`
	RepoURL     string `yaml:"repo_url"`
	Project     string `yaml:"project"`
}

type Subcategory

type Subcategory struct {
	Name  string    `yaml:"name"`
	Items []Project `yaml:"items"`
}

Jump to

Keyboard shortcuts

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