common

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleRequest

func HandleRequest[Request any, Response ResponseTo[Request]](handler RequestHandler[Request, Response]) func(*nats.Msg)

HandleRequest returns a NATS subscription target that calls the provided request handler in a new goroutine if the NATS message payload can be parsed into the specified request type, and responds to the client appropriately.

func UnmarshalResponse

func UnmarshalResponse[T any](data []byte) (T, error)

UnmarshalResponse parses a response received from the job server, either into a result of the specified type, or as an error; depending on the response's structure.

Types

type Cache

type Cache[V any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[V any](stats *CacheStats) Cache[V]

func (*Cache[V]) Load

func (c *Cache[V]) Load(key string, loader func() (V, error)) (V, error)

Load retrieves the value for the provided key in the cache, loading it using the provided callback function if it is not already present. If the loader returns an error, the cache slot is not marked as loaded, and the error is returned as-is.

type CacheStats

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

func (*CacheStats) Count

func (c *CacheStats) Count() uint64

Count returns the total count of cache accesses.

func (*CacheStats) Hits

func (c *CacheStats) Hits() uint64

Hits returns the count of cache accesses that resulted in a hit.

func (*CacheStats) RecordHit

func (c *CacheStats) RecordHit()

func (*CacheStats) RecordMiss

func (c *CacheStats) RecordMiss()

func (*CacheStats) String

func (c *CacheStats) String() string

type Graph

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

Graph keeps track of a directed acyclic graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(from string, to string) error

AddEdge adds a new edge to this graph. Returns an error if the new edge would introduce a cycle in the graph.

func (*Graph) RemoveEdge

func (g *Graph) RemoveEdge(from string, to string)

RemoveEdge removes an edge from this graph.

type RequestHandler

type RequestHandler[Request any, Response ResponseTo[Request]] func(Request) (Response, error)

RequestHandler is a function that processes a request of a given type, and returns a response or an error to be sent back to the client.

type ResponseTo

type ResponseTo[Request any] interface {
	IsResponseTo(Request)
}

Jump to

Keyboard shortcuts

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