Documentation
¶
Index ¶
- func NewPlugin() plugin.Plugin
- type CheckOptions
- type CheckRequest
- type CheckResponse
- type Config
- type FieldInfo
- type Handler
- type Middleware
- type SpellcheckPlugin
- type Spellchecker
- type SpellingError
- type SpellingErrors
- type TagParser
- func (p *TagParser) CacheSize() int
- func (p *TagParser) ClearCache()
- func (p *TagParser) ExtractFieldsFromMap(data map[string]interface{}, fieldInfos []FieldInfo) map[string]string
- func (p *TagParser) GetFieldValue(v interface{}, fieldName string) (string, bool)
- func (p *TagParser) Parse(v interface{}) []FieldInfo
- func (p *TagParser) ParseValue(v reflect.Value) []FieldInfo
- type TextTooLongError
- type UnsupportedLanguageError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CheckOptions ¶
type CheckOptions struct {
CaseSensitive *bool `json:"case_sensitive,omitempty"`
MaxSuggestions *int `json:"max_suggestions,omitempty"`
}
CheckOptions contains optional parameters for spell checking
type CheckRequest ¶
type CheckRequest struct {
Text string `json:"text" validate:"required"`
Language string `json:"language,omitempty"`
Context []string `json:"context,omitempty"` // Additional words to ignore for this request
Options *CheckOptions `json:"options,omitempty"`
}
CheckRequest represents a request to check spelling
func (*CheckRequest) Validate ¶
func (r *CheckRequest) Validate() error
Validate validates the CheckRequest
type CheckResponse ¶
type CheckResponse struct {
Valid bool `json:"valid"`
Errors []*SpellingError `json:"errors,omitempty"`
Suggestions map[string][]string `json:"suggestions,omitempty"`
Text string `json:"text,omitempty"`
}
CheckResponse represents the response from spell checking
type Config ¶
type Config struct {
Enabled bool
DefaultLanguage string
SupportedLanguages []string
MaxTextLength int
MaxSuggestions int
IgnoredWords []string
CustomDictionary string
CaseSensitive bool
MinWordLength int
}
func DefaultConfig ¶
func DefaultConfig() Config
type FieldInfo ¶
type FieldInfo struct {
Name string // Go field name
JSONName string // JSON tag name
SpellCheck bool // Whether to spellcheck this field
IsStringField bool // Whether the field is a string type
}
FieldInfo contains metadata about a struct field for spellchecking
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for the spellcheck endpoint
func NewHandler ¶
func NewHandler(config *Config, spellchecker *Spellchecker) *Handler
NewHandler creates a new Handler instance
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware returns a Fiber middleware that validates request bodies for spelling errors
func NewMiddleware ¶
func NewMiddleware(config *Config, spellchecker *Spellchecker) (*Middleware, error)
NewMiddleware creates a new Middleware instance
func (*Middleware) IsEnabled ¶
func (m *Middleware) IsEnabled() bool
Enable/disable middleware at runtime
func (*Middleware) Validate ¶
func (m *Middleware) Validate() fiber.Handler
Validate is the middleware handler that checks spelling in request bodies
func (*Middleware) ValidateStruct ¶
func (m *Middleware) ValidateStruct(v interface{}) (*SpellingErrors, error)
ValidateStruct validates a specific struct instance for spelling errors This can be called manually from handlers if you want explicit validation
type SpellcheckPlugin ¶
type SpellcheckPlugin struct {
// contains filtered or unexported fields
}
func (*SpellcheckPlugin) Config ¶
func (p *SpellcheckPlugin) Config() *Config
func (*SpellcheckPlugin) Handler ¶
func (p *SpellcheckPlugin) Handler() fiber.Handler
func (*SpellcheckPlugin) Initialize ¶
func (p *SpellcheckPlugin) Initialize(config map[string]interface{}) error
func (*SpellcheckPlugin) Name ¶
func (p *SpellcheckPlugin) Name() string
func (*SpellcheckPlugin) SetupEndpoints ¶
func (p *SpellcheckPlugin) SetupEndpoints(app *fiber.App) error
type Spellchecker ¶
type Spellchecker struct {
// contains filtered or unexported fields
}
Spellchecker provides spell checking functionality using fuzzy matching
func NewSpellchecker ¶
func NewSpellchecker(config *Config) (*Spellchecker, error)
NewSpellchecker creates a new spellchecker with the given configuration
func (*Spellchecker) Check ¶
func (s *Spellchecker) Check(text string) (*SpellingErrors, error)
Check checks the spelling of the given text and returns any errors found
func (*Spellchecker) CheckField ¶
func (s *Spellchecker) CheckField(fieldName, text string) (*SpellingErrors, error)
CheckField checks the spelling of text in a specific field (for middleware)
type SpellingError ¶
type SpellingError struct {
Field string `json:"field,omitempty"` // Field name (for middleware validation)
Word string `json:"word"` // Misspelled word
Position int `json:"position"` // Position in text
Suggestions []string `json:"suggestions,omitempty"` // Suggested corrections
}
SpellingError represents a single spelling error with suggestions
func (*SpellingError) Error ¶
func (e *SpellingError) Error() string
type SpellingErrors ¶
type SpellingErrors struct {
Errors []*SpellingError `json:"errors"`
}
SpellingErrors is a collection of spelling errors
func (*SpellingErrors) Add ¶
func (e *SpellingErrors) Add(err *SpellingError)
func (*SpellingErrors) Error ¶
func (e *SpellingErrors) Error() string
func (*SpellingErrors) HasErrors ¶
func (e *SpellingErrors) HasErrors() bool
type TagParser ¶
type TagParser struct {
// contains filtered or unexported fields
}
TagParser parses struct tags and caches the results
func (*TagParser) CacheSize ¶
CacheSize returns the approximate number of types cached Note: This is O(n) as sync.Map doesn't expose size directly
func (*TagParser) ClearCache ¶
func (p *TagParser) ClearCache()
ClearCache clears the tag parser cache Useful for testing or if types are redefined at runtime
func (*TagParser) ExtractFieldsFromMap ¶
func (p *TagParser) ExtractFieldsFromMap(data map[string]interface{}, fieldInfos []FieldInfo) map[string]string
ExtractFieldsFromMap extracts fields from a map[string]interface{} This is useful for checking JSON request bodies before they're unmarshaled
func (*TagParser) GetFieldValue ¶
GetFieldValue extracts the string value of a field from a struct
type TextTooLongError ¶
TextTooLongError indicates text exceeds maximum length
func (*TextTooLongError) Error ¶
func (e *TextTooLongError) Error() string
type UnsupportedLanguageError ¶
UnsupportedLanguageError indicates requested language is not supported
func (*UnsupportedLanguageError) Error ¶
func (e *UnsupportedLanguageError) Error() string
type ValidationError ¶
ValidationError represents errors during request validation
func NewValidationError ¶
func NewValidationError(message string, details map[string]string) *ValidationError
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string