examples

command
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: MIT Imports: 10 Imported by: 0

README

goisl Examples

This directory contains practical, copy/paste-ready examples demonstrating the use of the goisl input sanitization and escaping library.

Each file is self-contained and includes a helpful comment block describing its purpose, along with valid and invalid input examples.


🔧 Core Functionality

These examples show basic usage of goisl with default sanitization and escaping:

  • plaintext_escape.go: Escape plain text while preserving only safe characters.
  • cli_flags.go: Bind input flags using pflag and sanitize values using BindSanitizedFlag and BindSanitizedTextFlag.

🧩 Custom Override Hooks (Real-World Formats)

These examples demonstrate how to create custom sanitization hooks for specific formats:

  • uuid_format.go: Require input to match a valid UUID pattern.
  • twitter_handle.go: Validate Twitter handles (e.g., @username).
  • ip_address.go: Validate and sanitize IPv4 and IPv6 addresses.
  • hex_token.go: Validate secure hex tokens (e.g., for email confirmations).
  • country_code.go: Restrict ISO 3166-1 country codes (e.g., "US", "DE").
  • api_key_format.go: Validate test only API Stripe and prohibit production or invalid keys.
  • slack_webhook.go: Validate Slack webhook path and format.
  • mask_last4.go: Uses isl to mask all but the last for digits of a sensative string (e.g. logging purposes).
  • block_shortener.go: Disallows a URL input that is a known URL shortener.
  • crypto_btc_address.go: Validates Bitcoin addresses starting with 1, 3, or bc1.
  • guid_format.go: Validates GUID-style identifiers using a custom format check.
  • german_filename.go: Demonstrates transliteration of German characters (e.g., umlauts and ß) in filenames using a custom sanitization hook.

▶️ How to Run

The header comments in each example file contains testing examples. Use the Go CLI to test an example with your own inputs:

go run twitter_handle.go --handle="@derick"
go run ip_address.go --ip="192.168.1.1"
go run uuid_format.go --uuid="123e4567-e89b-12d3-a456-426614174000"

Documentation

Overview

Package main contains standalone example programs that demonstrate how to use the goisl (Go Input Sanitization Library) package.

These CLI-style examples show how to sanitize and validate various types of input, such as email addresses, URLs, file names, UUIDs, and plain text. Most examples showcase goisl's custom hook capability for domain-specific input logic, including format validation, character transliteration, and filtering.

Each example is designed to be executed directly using `go run` and is built for educational use, testing, or integration into real-world CLI tools.

See README.md in this directory for a full list of available examples.

---

Example: Transliterate German Characters in Filenames with a Custom Hook

This CLI-style example accepts a --file flag and uses goisl.SanitizeFileName with a custom hook to transliterate German umlauts and the ß character into ASCII-friendly equivalents.

Usage:

go run german_filename.go --file="Schloßgärtenüberwachungsdienst.xlsx"

Example Output:

✅ Sanitized Filename: Schlossgaertenueberwachungsdienst.xlsx

Jump to

Keyboard shortcuts

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