Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyTemplate(templateStr string, data map[string]interface{}) (string, []error)
- func CloneMap(source map[string]interface{}) map[string]interface{}
- func DecodeWithBasicHooks(instance interface{}, config interface{}) []error
- func EncloseContent(enclose string, content string) string
- func ExtractHxData(r *http.Request) (map[string]interface{}, error)
- func GenerateHash() string
- func GenerateShortHash(input string, bits int) string
- func GenerateTimestampRandomHash(length int) string
- func GenericTemplate() *template.Template
- func GetGenericFuncMap() template.FuncMap
- func GetLogger() *zap.SugaredLogger
- func HyperScriptErrorHash(s string) string
- func Init_configuration()
- func IsJSONContent(contentType string) bool
- func IsMultipartForm(contentType string) bool
- func JoinHeaderValues(values []string) string
- func JoinTestCode(hyperbricks string, propertyTest string) []string
- func Random(args ...interface{}) interface{}
- func RenderAllowedAttributes(attributes map[string]interface{}, allowed []string) string
- func RenderValidationWarnings(warnings []string) string
- func RenderValidationWarningsWithPath(warnings []string, hyperbrickspath []string) string
- func RenderWarning(warning string) string
- func SortedUniqueKeys(m map[string]interface{}) []string
- func StructToMap(data interface{}) map[string]interface{}
- func StructToMapRecursive(input interface{}) map[string]interface{}
- func ToMap(value interface{}) (map[string]interface{}, bool)
- func TrimWrap(content, html string) string
- func Validate(config interface{}) []error
- func WriteToFile(filename, content string) error
- type CacheTime
- type Component
- type ComponentError
- type ComponentRenderer
- type ComponentRendererConfig
- type Composite
- type CompositeError
- type CompositeRenderer
- type CompositeRendererConfig
- type Config
- type DebugConfig
- type DevelopmentConfig
- type ExtendedRendererConfig
- type LiveConfig
- type LoggerConfig
- type Meta
- type PathKeyer
- type PluginConfig
- type PluginRenderer
- type RateLimitConfig
- type RenderFunc
- type Renderer
- type ServerConfig
- type SystemConfig
Constants ¶
const ( LIVE_MODE string = "live" DEBUG_MODE string = "debug" DEVELOPMENT_MODE string = "development" )
const FormData contextKey = "formData"
const JwtKey contextKey = "jwtToken"
const Request contextKey = "request"
const RequestBody contextKey = "requestBody"
const ResponseWriter contextKey = "ResponseWriter"
Variables ¶
var ( Write bool Outputpath string = "../../cmd/hyperbricks-docs/hyperbricks-examples/" )
var FuncMap = template.FuncMap{ "random": Random, "valueOrEmpty": func(value interface{}) string { if value == nil { return "" } return fmt.Sprintf("%v", value) }, }
Create a FuncMap with a custom function
var Location string
var (
Module string
)
Functions ¶
func ApplyTemplate ¶
applyTemplate generates output based on the provided template and API data.
func DecodeWithBasicHooks ¶
func DecodeWithBasicHooks(instance interface{}, config interface{}) []error
func EncloseContent ¶
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 ¶
ExtractHxData extracts headers, form data, JSON payloads, and query parameters from an HTTP request.
func GenerateHash ¶
func GenerateHash() string
func GenerateShortHash ¶
GenerateShortHash returns a short base62-encoded hash of the input string. 'bits' specifies how many bits of the SHA-256 digest to use. Default 48 bits is a good balance. Note: Using fewer bits increases collision risk; using more bits produces a longer string.
func GenerateTimestampRandomHash ¶
GenerateTimestampRandomHash combines the current timestamp and a secure random number, hashes the combination using SHA-1, and returns the first 'length' hex characters.
func GenericTemplate ¶
// Why use clone ? Prevents concurrent modification: Clone() creates a separate instance per goroutine, avoiding map modification issues. Better performance: Reusing a base template reduces overhead compared to creating a new one every time. Cleaner & safer: No need for sync.Mutex, and avoids unnecessary allocations.
func GetGenericFuncMap ¶
Lazy load function map based on context
func GetLogger ¶
func GetLogger() *zap.SugaredLogger
GetLogger returns the singleton SugaredLogger instance
func HyperScriptErrorHash ¶
func Init_configuration ¶
func Init_configuration()
func IsJSONContent ¶
IsJSONContent checks if the Content-Type is application/json.
func IsMultipartForm ¶
IsMultipartForm checks if the Content-Type is multipart/form-data.
func JoinHeaderValues ¶
JoinHeaderValues concatenates multiple header values into a single string separated by commas.
func JoinTestCode ¶
Helper function to combine the main configuration string with a property-specific test case.
func RenderAllowedAttributes ¶
RenderAllowedAttributes filters and formats the allowed attributes for rendering in a consistent order.
func RenderWarning ¶
func SortedUniqueKeys ¶
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 WriteToFile ¶
Helper function to write test outputs to a file for documentation purposes.
Types ¶
type CacheTime ¶
CacheTime manages cache duration.
func (*CacheTime) UnmarshalText ¶
UnmarshalText allows mapstructure to decode CacheTime.
type Component ¶
type Component = ComponentRendererConfig
type ComponentError ¶
type ComponentError struct {
Hash string // non-collision hash
File string // Hyperbricks file
Err string // A descriptive error message
Key string // Current key of the component where the error occured
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 Config ¶
type Config struct {
Mode string `mapstructure:"mode"`
Logger LoggerConfig `mapstructure:"logger"`
Server ServerConfig `mapstructure:"server"`
RateLimit RateLimitConfig `mapstructure:"rate_limit"`
Development DevelopmentConfig `mapstructure:"development"`
Debug DebugConfig `mapstructure:"debug"`
Live LiveConfig `mapstructure:"live"`
Directories map[string]string `mapstructure:"directories"`
Plugins map[string]string `mapstructure:"plugins"`
System SystemConfig `mapstructure:"system"`
}
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 ExtendedRendererConfig ¶
Example Extended struct
type LiveConfig ¶
type LiveConfig struct {
CacheTime CacheTime `mapstructure:"cache"`
}
type LoggerConfig ¶
LoggerConfig with defaults.
type Meta ¶
type Meta struct {
ConfigType string `mapstructure:"@type" exclude:"true" description:"Identification for renderer"`
ConfigCategory string
HyperBricksKey string `mapstructure:"hyperbrickskey" exclude:"true"`
HyperBricksPath string `mapstructure:"hyperbrickspath" exclude:"true"`
HyperBricksFile string `mapstructure:"hyperbricksfile" exclude:"true"`
}
GENERIC CONFIG FIELDS
type PluginConfig ¶
type PluginConfig map[string]interface{}
PluginConfig is a generic configuration map for plugins.
type PluginRenderer ¶
RenderPlugin defines the interface for dynamic plugins.
type RateLimitConfig ¶
type RenderFunc ¶
RenderFunc defines the signature for the render callback.
type ServerConfig ¶
type ServerConfig struct {
Port int `mapstructure:"port"`
Beautify bool `mapstructure:"beautify"`
ReadTimeout time.Duration `mapstructure:"read_timeout"`
WriteTimeout time.Duration `mapstructure:"write_timeout"`
IdleTimeout time.Duration `mapstructure:"idle_timeout"`
}
ServerConfig with defaults.