util

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const JSONContentType = "application/json"

Variables

View Source
var (
	UnsupportedError    = errors.New("not supported")
	NotImplementedError = errors.New("not implemented")
	InvalidFormatError  = errors.New("invalid format")
	UndefinedError      = errors.New("undefined")
	CastingError        = errors.New("failed to convert")
)

Error messages

Functions

func AnyToJSONInterface

func AnyToJSONInterface(data any) (any, error)

func ArrayInterfaceToStr

func ArrayInterfaceToStr(have []any) ([]string, error)

func ArrayStrToInterface

func ArrayStrToInterface(have []string) []any

func AsRFC3339Timestamp

func AsRFC3339Timestamp(t time.Time) string

func Contains

func Contains(needle string, haystack []string) bool

func Copy

func Copy(src any, dst any) error

Copy makes a 1:1 copy of src into dst.

func GetRFC3339Timestamp

func GetRFC3339Timestamp() string

func InterfaceToInterfaceArray

func InterfaceToInterfaceArray(have any) ([]any, error)

InterfaceToInterfaceArray attempts to array-ify an interface type

func InterfaceToStrings

func InterfaceToStrings(have any) ([]string, error)

InterfaceToStrings assumes we are given an interface of either `string`, `[]string` or `[]any` types and attempts to flatten into an array of strings

func IsRFC3339Timestamp

func IsRFC3339Timestamp(t string) bool

IsRFC3339Timestamp attempts to parse a string as an RFC3339 timestamp, which is a subset of an ISO-8601 timestamp. Returns true if the parsing is successful, false if not.

func IsValidStruct

func IsValidStruct(data any) error

func LDCompact

func LDCompact(document any, context string) (map[string]any, error)

LDCompact runs https://www.w3.org/TR/json-ld-api/#compaction-algorithms which shortens IRIs in the document

func LDFrame

func LDFrame(document any, frame any) (any, error)

LDFrame runs https://www.w3.org/TR/json-ld11-framing/ to transform the data in a document according to its frame

func LDNormalize

func LDNormalize(document any) (any, error)

func LoggingError

func LoggingError(err error) error

LoggingError is a utility to combine logging an error, and returning and error

func LoggingErrorMsg

func LoggingErrorMsg(err error, msg string) error

LoggingErrorMsg is a utility to combine logging an error, and returning and error with a message

func LoggingErrorMsgf

func LoggingErrorMsgf(err error, msg string, args ...any) error

LoggingErrorMsgf is a utility to combine logging an error, and returning and error with a formatted message

func LoggingNewError

func LoggingNewError(msg string) error

LoggingNewError is a utility to create an error from a message, log it, and return it as an error

func LoggingNewErrorf

func LoggingNewErrorf(msg string, args ...any) error

LoggingNewErrorf is a utility to create an error from a formatted message, log it, and return it as an error

func MergeUniqueValues

func MergeUniqueValues(a, b []string) []string

MergeUniqueValues takes in two string arrays and returns the union set the input arrays are not modified

func NewLDDocumentLoader

func NewLDDocumentLoader() (*ld.CachingDocumentLoader, error)

func NewValidator

func NewValidator() *validator.Validate

func PrettyJSON

func PrettyJSON(data any) ([]byte, error)

PrettyJSON JSON-ifies data in a 'pretty-print' fashion

func SanitizeLog

func SanitizeLog(log string) string

SanitizeLog prevents certain classes of injection attacks before logging https://codeql.github.com/codeql-query-help/go/go-log-injection/

func StringPtr

func StringPtr(s string) *string

func ToJSONInterface

func ToJSONInterface(data string) (any, error)

func ToJSONMap

func ToJSONMap(data any) (map[string]any, error)

Types

type AppendError

type AppendError []string

func NewAppendError

func NewAppendError() *AppendError

func (*AppendError) Append

func (a *AppendError) Append(err error)

func (*AppendError) AppendString

func (a *AppendError) AppendString(err string)

func (*AppendError) Error

func (a *AppendError) Error() error

func (*AppendError) IsEmpty

func (a *AppendError) IsEmpty() bool

func (*AppendError) NumErrors

func (a *AppendError) NumErrors() int

type Emptyable

type Emptyable interface {
	IsEmpty() bool
}

type LDProcessor

type LDProcessor struct {
	*ld.JsonLdProcessor
	*ld.JsonLdOptions
}

func NewLDProcessor

func NewLDProcessor() (*LDProcessor, error)

func (LDProcessor) GetContextFromMap

func (l LDProcessor) GetContextFromMap(dataMap map[string]any) (*ld.Context, error)

func (LDProcessor) GetOptions

func (l LDProcessor) GetOptions() *ld.JsonLdOptions

type URL

type URL struct {
	url.URL
}

URL is a wrapper struct of url.URL in order to unmarshal(marshal) URLs from(to) strings.

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

type Validatable

type Validatable interface {
	IsValid() error
}

Jump to

Keyboard shortcuts

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