Add templates and example files for Python, Go, and JavaScript
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-01-31 00:58:44 +00:00
parent 3b52b445db
commit 4589265cb2

71
examples/example_go.go Normal file
View File

@@ -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
}