core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Common errors
	ErrServiceNotConfigured = errors.New("service is not configured")
	ErrNilResponse          = errors.New("received nil response from server")
)

Functions

This section is empty.

Types

type ServiceCore

type ServiceCore struct {
	Type           string
	DisplayName    string
	Description    string
	DefaultURL     string
	ApiKey         string
	HealthEndpoint string
	// contains filtered or unexported fields
}

func (*ServiceCore) CacheVersion

func (s *ServiceCore) CacheVersion(baseURL, version string, ttl time.Duration) error

CacheVersion stores the version in cache with the specified TTL

func (*ServiceCore) ConcurrentRequest

func (s *ServiceCore) ConcurrentRequest(requests []func() (interface{}, error)) []interface{}

ConcurrentRequest executes multiple requests concurrently and returns their results

func (*ServiceCore) CreateHealthResponse

func (s *ServiceCore) CreateHealthResponse(lastChecked time.Time, status string, message string, extras ...map[string]interface{}) models.ServiceHealth

CreateHealthResponse creates a standardized health response

func (*ServiceCore) GetCachedVersion

func (s *ServiceCore) GetCachedVersion(ctx context.Context, baseURL, apiKey string, fetchVersion func(string, string) (string, error)) (string, error)

GetCachedVersion attempts to get version from cache or fetches it if not found

func (*ServiceCore) GetVersionFromCache

func (s *ServiceCore) GetVersionFromCache(baseURL string) string

GetVersionFromCache retrieves the version from cache

func (*ServiceCore) MakeRequest

func (s *ServiceCore) MakeRequest(url string, apiKey string, headers map[string]string) (*http.Response, error)

func (*ServiceCore) MakeRequestWithContext

func (s *ServiceCore) MakeRequestWithContext(ctx context.Context, url string, apiKey string, headers map[string]string) (*http.Response, error)

MakeRequestWithContext makes an HTTP request with the provided context and timeout

func (*ServiceCore) ReadBody

func (s *ServiceCore) ReadBody(resp *http.Response) ([]byte, error)

ReadBody reads and returns the response body

Jump to

Keyboard shortcuts

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