From 4589265cb22b5e9be5f111f4eeb885bc51d09bff Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 00:58:44 +0000 Subject: [PATCH] Add templates and example files for Python, Go, and JavaScript --- examples/example_go.go | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 examples/example_go.go diff --git a/examples/example_go.go b/examples/example_go.go new file mode 100644 index 0000000..7c3c014 --- /dev/null +++ b/examples/example_go.go @@ -0,0 +1,71 @@ +// Package utils provides utility functions for common operations. +// +// This package includes functions for string manipulation, +// numerical calculations, and file operations. +package utils + +import ( + "errors" + "strings" +) + +// Trim removes whitespace from both ends of a string. +// +// s: The string to trim +// +// Returns: The trimmed string +func Trim(s string) string { + return strings.TrimSpace(s) +} + +// Add adds two integers and returns their sum. +// +// a: First integer +// b: Second integer +// +// Returns: The sum of a and b +func Add(a, b int) int { + return a + b +} + +// Divide performs integer division. +// +// numerator: The number to divide +// denominator: The divisor +// +// Returns: The quotient, or an error if denominator is zero +// +// Raises: error if denominator is zero +func Divide(numerator, denominator int) (int, error) { + if denominator == 0 { + return 0, errors.New("division by zero") + } + return numerator / denominator, nil +} + +// Greet returns a personalized greeting message. +// +// name: The name to include in the greeting +// formal: Whether to use formal greeting +// +// Returns: A greeting string +func Greet(name string, formal bool) string { + if formal { + return "Good day, " + name + "." + } + return "Hi, " + name + "!" +} + +// ProcessList processes a list of strings with the given function. +// +// items: The list of strings to process +// fn: The function to apply to each item +// +// Returns: A new list with processed items +func ProcessList(items []string, fn func(string) string) []string { + result := make([]string, len(items)) + for i, item := range items { + result[i] = fn(item) + } + return result +}