utils

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SPDXLicensesURL = "https://raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json"
)

Variables

View Source
var NilStack = &Stack[string]{nil, 0}
View Source
var UserHomeDir, _ = getUserHomeDir()

Functions

func CacheLicensesFile

func CacheLicensesFile(basedir string, spdxFileBytes *[]byte, overwrite bool) error

converts the full SPDX JSON file into a JSON file of licenseId => reference and store it

func DeleteFile

func DeleteFile(path string) error

func DoRequest

func DoRequest(client *http.Client, request *http.Request) (*[]byte, error)

func Filter

func Filter[T any](input []T, predicate Predicate[T]) []T

func GetHomeDir

func GetHomeDir(basedir string) string

func GetInProgressFilePath

func GetInProgressFilePath(basedir string) string

func GetLicensesFilePath

func GetLicensesFilePath(basedir string) string

func GetSupportedLicenses

func GetSupportedLicenses(basedir string) (*[]string, error)

func LoadFile

func LoadFile(filePath string) ([]byte, error)

func Marshal

func Marshal(path string, m map[string]any, args ...any) error

func MarshalBytes added in v0.49.0

func MarshalBytes(path string, bytes []byte, args ...any) error

func MkHomeDir

func MkHomeDir(basedir string) error

func MkHttpClient

func MkHttpClient() *http.Client

func MkJSONRequest

func MkJSONRequest(method string, url string) (*http.Request, error)

func MkPrompt

func MkPrompt(stdin *io.ReadCloser, stdout *io.WriteCloser, text string, validate func(string) error) (*string, error)

func NewPersonOrOrganizationPrompt

func NewPersonOrOrganizationPrompt(reader *Reader, writer *Writer, label string) (*map[string]any, error)

func NewTestHttpClient

func NewTestHttpClient(responses *Stack[string]) *http.Client

func Nop

func Nop(s string) error

func ReadJSON

func ReadJSON(path string) (*string, error)

func Unmarshal

func Unmarshal(path string) (*map[string]any, error)

func ValidEmailAddress

func ValidEmailAddress(address string) error

func ValidUrl

func ValidUrl(str string) error

func WriteFile added in v0.49.0

func WriteFile(path string, bytes []byte) error

func WriteJSON

func WriteJSON(path string, json string) error

Types

type Predicate

type Predicate[T any] func(T) bool

type Reader

type Reader interface {
	Stdin() io.ReadCloser
}

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any]() *Stack[T]

Create a new stack

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

Return the number of items in the stack

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() *T

View the top item on the stack

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() *T

Pop the top item of the stack and return it

func (*Stack[T]) Push

func (s *Stack[T]) Push(value T)

Push a value onto the top of the stack

type StdinReader

type StdinReader struct {
	Reader
}

func (*StdinReader) Stdin

func (*StdinReader) Stdin() io.ReadCloser

type StdoutWriter

type StdoutWriter struct {
	Writer
}

func (StdoutWriter) Errorf

func (s StdoutWriter) Errorf(format string, a ...any) error

func (StdoutWriter) Print

func (s StdoutWriter) Print(a ...any) (n int, err error)

func (StdoutWriter) Println

func (s StdoutWriter) Println(a ...any) (n int, err error)

func (StdoutWriter) StdErr

func (StdoutWriter) StdErr() io.WriteCloser

func (StdoutWriter) Stdout

func (StdoutWriter) Stdout() io.WriteCloser

type TestReader

type TestReader struct {
	Reader
	In TestStdin
}

func (*TestReader) Stdin

func (r *TestReader) Stdin() io.ReadCloser

type TestRoundTripper

type TestRoundTripper struct {
	Responses *Stack[string]
}

func (*TestRoundTripper) RoundTrip

func (r *TestRoundTripper) RoundTrip(*http.Request) (*http.Response, error)

type TestStdin

type TestStdin struct {
	io.ReadCloser
	Data Stack[string]
	// contains filtered or unexported fields
}

func (*TestStdin) Close

func (*TestStdin) Close() error

func (*TestStdin) Read

func (r *TestStdin) Read(buf []byte) (int, error)

type TestWriter

type TestWriter struct {
	Writer
	Verbose bool
}

func (TestWriter) Errorf

func (r TestWriter) Errorf(format string, a ...any) error

func (TestWriter) Print

func (r TestWriter) Print(a ...any) (n int, err error)

func (TestWriter) Println

func (r TestWriter) Println(a ...any) (n int, err error)

func (TestWriter) StdErr

func (r TestWriter) StdErr() io.WriteCloser

func (TestWriter) Stdout

func (r TestWriter) Stdout() io.WriteCloser

type Writer

type Writer interface {
	Stdout() io.WriteCloser
	StdErr() io.WriteCloser
	Println(a ...any) (n int, err error)
	Print(a ...any) (n int, err error)
	Errorf(format string, a ...any) error
}

Jump to

Keyboard shortcuts

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