resources

package
v0.0.0-...-8aeb8a1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoModified = errors.New("Resource wasn't modified")

Functions

func GetBytesHash

func GetBytesHash(payload []byte) string

func GetHash

func GetHash(value interface{}) (uint64, error)

func GetStringHash

func GetStringHash(value string) string

func Watch

func Watch(name, source string, loadFunc func(string, string) (*ResponsePayload, error), consumer func([]byte), reloadEvery time.Duration) func()

Watch First loads source then runs goroutine to reload source every 'reloadEvery' duration On every load check if content was changed => run consumer otherwise do nothing

Types

type ContentType

type ContentType string
const (
	JSONContentType    ContentType = "json"
	YamlContentType    ContentType = "yaml"
	UnknownContentType ContentType = "unknown"
)

type ResponsePayload

type ResponsePayload struct {
	Content      []byte
	LastModified string

	ContentType *ContentType
}

func LoadFromFile

func LoadFromFile(filePath, lastModified string) (*ResponsePayload, error)

LoadFromFile returns loaded content, empty string (because there is no last-modified logic in files), error

func LoadFromHTTP

func LoadFromHTTP(fullURL, ifModifiedSinceValue string) (*ResponsePayload, error)

LoadFromHTTP returns loaded content, Last-modified value from header, error

type Watcher

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

Jump to

Keyboard shortcuts

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