shared

package
v0.1.4-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LIVE_MODE        string = "live"
	DEBUG_MODE       string = "debug"
	DEVELOPMENT_MODE string = "development"
)

Variables

View Source
var (
	Write      bool
	Outputpath string = "../../cmd/hyperbricks-docs/hyperbricks-examples/"
)
View Source
var (
	Module string
)

Functions

func ApplyTemplate

func ApplyTemplate(templateStr string, data map[string]interface{}) (string, []error)

applyTemplate generates output based on the provided template and API data.

func CloneMap

func CloneMap(source map[string]interface{}) map[string]interface{}

cloneMap is a helper to do a shallow clone of map[string]interface{}

func DecodeWithBasicHooks

func DecodeWithBasicHooks(instance interface{}, config interface{}) []error

func EncloseContent

func EncloseContent(enclose string, content string) string

EncloseContent encloses the given content with the specified enclose string. The enclose string can be a single tag or a pair separated by '|'.

func ExtractHxData

func ExtractHxData(r *http.Request) (map[string]interface{}, error)

ExtractHxData extracts headers, form data, JSON payloads, and query parameters from an HTTP request.

func GetLogger

func GetLogger() *zap.SugaredLogger

GetLogger returns the singleton SugaredLogger instance

func HyperScriptErrorHash

func HyperScriptErrorHash(s string) string

func Init_configuration

func Init_configuration()

func IsJSONContent

func IsJSONContent(contentType string) bool

IsJSONContent checks if the Content-Type is application/json.

func IsMultipartForm

func IsMultipartForm(contentType string) bool

IsMultipartForm checks if the Content-Type is multipart/form-data.

func JoinHeaderValues

func JoinHeaderValues(values []string) string

JoinHeaderValues concatenates multiple header values into a single string separated by commas.

func JoinTestCode

func JoinTestCode(hyperbricks string, propertyTest string) []string

Helper function to combine the main configuration string with a property-specific test case.

func RenderAllowedAttributes

func RenderAllowedAttributes(attributes map[string]interface{}, allowed []string) string

RenderAllowedAttributes filters and formats the allowed attributes for rendering in a consistent order.

func RenderValidationWarnings

func RenderValidationWarnings(warnings []string) string

func RenderValidationWarningsWithPath

func RenderValidationWarningsWithPath(warnings []string, hyperbrickspath []string) string

func RenderWarning

func RenderWarning(warning string) string

func SortedUniqueKeys

func SortedUniqueKeys(m map[string]interface{}) []string

SortedKeys returns the keys of the map sorted numerically or lexicographically. It caches the sorted keys for maps with the same set of keys. This uses TreeMap, is 5 times faster and uses 53 times less memory than the non-TreeMap

func StructToMap

func StructToMap(data interface{}) map[string]interface{}

Helper function to convert a struct to a map for easy validation in test cases.

func StructToMapRecursive

func StructToMapRecursive(input interface{}) map[string]interface{}

func ToMap

func ToMap(value interface{}) (map[string]interface{}, bool)

func TrimWrap

func TrimWrap(content, html string) string

TrimWrap removes the enclosing content around the placeholder '|'.

func Validate

func Validate(config interface{}) []error

func WriteToFile

func WriteToFile(filename, content string) error

Helper function to write test outputs to a file for documentation purposes.

Types

type CacheTime

type CacheTime struct {
	Duration time.Duration
}

CacheTime manages cache duration.

func (*CacheTime) Parse

func (ct *CacheTime) Parse(value string) error

Parse converts string to CacheTime.

func (CacheTime) String

func (ct CacheTime) String() string

String returns CacheTime as string.

func (*CacheTime) UnmarshalText

func (ct *CacheTime) UnmarshalText(text []byte) error

UnmarshalText allows mapstructure to decode CacheTime.

type Component

type Component = ComponentRendererConfig

type ComponentError

type ComponentError struct {
	Err      string // A descriptive error message
	Key      string // Key of the component
	Path     string // Path of the component in the hierarchy
	Rejected bool   // Rendering is rejected
	Type     string // Which HyperBricks type?
	Level    string // INFO, WARNING, otherwise ERROR
}

ComponentError represents an error associated with a component.

func HyperbricksDecodeError

func HyperbricksDecodeError(err string, path string, key string) (string, []ComponentError)

returns a anchor with error

func (ComponentError) Error

func (e ComponentError) Error() string

Error implements the error interface for ComponentError.

type ComponentRenderer

type ComponentRenderer interface {
	Renderer
}

type ComponentRendererConfig

type ComponentRendererConfig struct {
	Meta            `mapstructure:",squash"` // Embedding RendererConfig
	ExtraAttributes map[string]interface{}   `mapstructure:"attributes" description:"Extra attributes like id, data-role, data-action"`
	Enclose         string                   `mapstructure:"enclose" description:"The enclosing HTML element for the header divided by |"`
}

Basic config for ComponentRenderers

func (ComponentRendererConfig) GetConfigType

func (c ComponentRendererConfig) GetConfigType() string

func (ComponentRendererConfig) GetKey

func (c ComponentRendererConfig) GetKey() string

func (ComponentRendererConfig) GetPath

func (c ComponentRendererConfig) GetPath() string

type Composite

type Composite = CompositeRendererConfig

type CompositeError

type CompositeError struct {
	Err      string // A descriptive error message
	Key      string // Key of the component
	Path     string // Path of the component in the hierarchy
	Rejected bool   // Rendering is rejected
	Type     string // Which HyperBricks type?
	Level    string // INFO, WARNING, otherwise ERROR
}

ComponentError represents an error associated with a component.

func (CompositeError) Error

func (e CompositeError) Error() string

Error implements the error interface for ComponentError.

type CompositeRenderer

type CompositeRenderer interface {
	Renderer
}

CompositeRenderer extends Renderer to handle composite rendering (itself and children).

type CompositeRendererConfig

type CompositeRendererConfig struct {
	Meta  `mapstructure:",squash"`
	Items map[string]interface{} `mapstructure:",remain"`
}

type Config

type Config struct {
	Mode        string            `mapstructure:"mode"`
	Logger      LoggerConfig      `mapstructure:"logger"`
	Server      ServerConfig      `mapstructure:"server"`
	Development DevelopmentConfig `mapstructure:"development"`
	Debug       DebugConfig       `mapstructure:"debug"`
	Live        LiveConfig        `mapstructure:"live"`
	Directories map[string]string `mapstructure:"directories"`
}

Config structure with default values.

func GetHyperBricksConfiguration

func GetHyperBricksConfiguration() *Config

GetHyperBricksConfiguration returns the singleton instance of the Config.

type DebugConfig

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

type DevelopmentConfig

type DevelopmentConfig struct {
	Watch  bool `mapstructure:"watch"`
	Reload bool `mapstructure:"reload"`
}

type ExtendedRendererConfig

type ExtendedRendererConfig struct {
	Meta  // Embedding RendererConfig
	Value string
}

Example Extended struct

type LiveConfig

type LiveConfig struct {
	CacheTime CacheTime `mapstructure:"cache"`
}

type LoggerConfig

type LoggerConfig struct {
	Level string `mapstructure:"level"`
	Path  string `mapstructure:"path"`
}

LoggerConfig with defaults.

type Meta

type Meta struct {
	ConfigType     string `mapstructure:"@type" exclude:"true" description:"Identification for renderer"`
	ConfigCategory string
	Key            string `mapstructure:"key" exclude:"true"`
	Path           string `mapstructure:"path" exclude:"true"`
	File           string `mapstructure:"file" exclude:"true"`
}

GENERIC CONFIG FIELDS

type PathKeyer

type PathKeyer interface {
	GetPath() string
	GetKey() string
	GetConfigType() string
}

type PluginConfig

type PluginConfig map[string]interface{}

PluginConfig is a generic configuration map for plugins.

type PluginRenderer

type PluginRenderer interface {
	Render(data interface{}) (string, []error)
}

RenderPlugin defines the interface for dynamic plugins.

type RenderFunc

type RenderFunc func(contentType string, data interface{}) (string, []error)

RenderFunc defines the signature for the render callback.

type Renderer

type Renderer interface {
	Render(instance interface{}) (string, []error)
	Types() []string
}

type ServerConfig

type ServerConfig struct {
	Port     int  `mapstructure:"port"`
	Beautify bool `mapstructure:"beautify"`
}

ServerConfig with defaults.

Jump to

Keyboard shortcuts

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