signal

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAsMap

func SetAsMap(s Set, namespace bool) map[string]any

SetAsMap returns a map where each field name is mapped to the value of the field.

Fields are named as returned by SetFields and values are the same as those returned by SetValues.

func SetAsMapWithNamespace

func SetAsMapWithNamespace(s Set) map[string]map[string]any

SetAsMapWithNamespace returns a map where the outer map contains keys corresponding to the namespace, and each inner map contains each field name mapped to the value of the field.

func SetFields

func SetFields(s Set, namespace bool) []string

SetFields returns a slice containing the names of the fields for s.

If namespace is true the field names will be prefixed with the namespace.

func SetValues

func SetValues(s Set) []any

SetValues returns a slice containing the values for each field for s.

The values are either `nil` if the Field is not set, or the value that was set.

func ValidateSet

func ValidateSet(s Set) error

ValidateSet tests whether a Set is valid.

An invalid Set will return an error with the first test that failed. A valid Set will return nil.

Types

type Field

type Field[T SupportedType] struct {
	// contains filtered or unexported fields
}

func Val

func Val[T SupportedType](v T) Field[T]

Val is used to create a Field instance that is already set with the value v.

This method is particularly useful when creating an new instance of a Set.

    s = &FooSet{
	       myField: signal.Val("hello, world!")
    }

func (*Field[T]) Get

func (s *Field[T]) Get() T

func (*Field[T]) IsSet

func (s *Field[T]) IsSet() bool

func (*Field[T]) Set

func (s *Field[T]) Set(v T)

func (*Field[T]) Unset

func (s *Field[T]) Unset()

func (Field[T]) Value

func (s Field[T]) Value() any

type IssuesSet

type IssuesSet struct {
	UpdatedCount     Field[int]     `signal:"updated_issues_count,legacy"`
	ClosedCount      Field[int]     `signal:"closed_issues_count,legacy"`
	CommentFrequency Field[float64] `signal:"issue_comment_frequency,legacy"`
}

func (*IssuesSet) Namespace

func (r *IssuesSet) Namespace() Namespace

type Namespace

type Namespace string
const (
	NamespaceRepo   Namespace = "repo"
	NamespaceIssues Namespace = "issues"
)
const (

	// namespaceLegacy is an internal namespace used for fields that provide
	// compatibility with the legacy python implementation.
	NamespaceLegacy Namespace = "legacy"
)

func (Namespace) String

func (ns Namespace) String() string

type RepoSet

type RepoSet struct {
	URL      Field[string]
	Language Field[string]
	License  Field[string]

	StarCount Field[int]
	CreatedAt Field[time.Time]
	UpdatedAt Field[time.Time]

	CreatedSince Field[int] `signal:"legacy"`
	UpdatedSince Field[int] `signal:"legacy"`

	ContributorCount Field[int] `signal:"legacy"`
	OrgCount         Field[int] `signal:"legacy"`

	CommitFrequency    Field[float64] `signal:"legacy"`
	RecentReleaseCount Field[int]     `signal:"legacy"`
}

func (*RepoSet) Namespace

func (r *RepoSet) Namespace() Namespace

type Set

type Set interface {
	Namespace() Namespace
}

type Source

type Source interface {
	// EmptySet returns an empty instance of a signal Set that can be used for
	// determining the namespace and signals supported by the Source.
	EmptySet() Set

	// IsSupported returns true if the Source supports the supplied Repo.
	IsSupported(projectrepo.Repo) bool

	// Get gathers and returns a Set of signals for the given project repo r.
	//
	// An optional string jobID can be specified and may be used by the Source
	// to manage caches related to a collection run.
	//
	// An error is returned if it is unable to successfully gather the signals,
	// or if the context is cancelled.
	Get(ctx context.Context, r projectrepo.Repo, jobID string) (Set, error)
}

A Source is used to get a set of signals for a given project repository.

type SupportedType

type SupportedType interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 |
		~string | time.Time
}

Jump to

Keyboard shortcuts

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