example

package module
v0.0.0-...-32cbb59 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

example

example is a Go package designed to bridge the gap between complex business logic or technical implementations and non-technical users. It provides a simple, user-friendly interface for interacting with and testing various functions or services using markdown-formatted tables as input and output.

For examples of this package in use, visit the examples documentation.

Purpose

The main goal of this package is to allow users without programming experience to:

  • Easily input data and parameters for testing complex functions or services.
  • Visualize the results in a clear, tabular format.
  • Experiment with different inputs to understand the underlying logic or behavior of a system.

By using markdown tables, which are human-readable and easy to edit, this package enables a wide range of users to interact with and gain insights from technical implementations without needing to understand or write code.

Installation

To use this package in your Go project, you can install it using:

$ go get github.com/dbut2/example

Usage

The main function provided by this package is Run. It takes two parameters:

  1. A function that processes the input data and returns the output data
  2. A string containing the input data in markdown table format

For practical examples of how to use this package, please check the /examples directory in the repository. This directory contains various use cases and implementations that demonstrate how to expose different types of logic or services using markdown tables.

Contributing

For information on how to contribute to this project, please see the CONTRIBUTING.md file.

Documentation

Overview

Package example provides a generic utility for processing structured data using markdown-formatted tables as input and output. It is designed to simplify the testing and demonstration of functions that operate on tabular data by allowing easy input specification and result visualization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[T, U any](f func(T) (U, error), inputTable string, opts ...RunOption)

Run executes a function f with input data from a markdown table and outputs the results as a markdown table.

The function f can accept either a single item or a slice/array of items as input (type T), and should return a single item or a slice/array of items as output (type U), along with an error.

Run performs the following steps: 1. Parses the input markdown table. 2. Processes the input data based on the type of T (single item or slice/array). 3. Executes the provided function f with the processed input. 4. Formats the results (type U) into a markdown table. 5. Prints the formatted output table.

This function uses reflection to handle various input and output types, making it flexible for different use cases. It can adapt to both individual items and slices/arrays, depending on the function signature provided.

If any errors occur during parsing, processing, or function execution, Run will print an error message and return without producing output.

Types

type RunConfig

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

RunConfig holds configuration options for the Run function.

type RunOption

type RunOption func(*RunConfig)

RunOption is a function type used to set options for the Run function.

func WithHeaderAliases

func WithHeaderAliases(aliases map[string]string) RunOption

WithHeaderAliases is a RunOption that sets up aliases for field names. This can be useful when the table headers don't exactly match the struct field names, allowing for more flexible parsing. In the aliases map, each key is an alias and its corresponding value is the struct field name it represents.

func WithOutputHeader

func WithOutputHeader(header string) RunOption

WithOutputHeader sets the output headers using a markdown-formatted header row.

func WithOutputHeaders

func WithOutputHeaders(headers []string) RunOption

WithOutputHeaders sets the output headers using a slice of strings.

Directories

Path Synopsis
examples
calculator
Package calculator provides basic arithmetic operations on numeric data.
Package calculator provides basic arithmetic operations on numeric data.

Jump to

Keyboard shortcuts

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