From 9d2256adddbb830d33119a5e01e3fad6b4b0652b Mon Sep 17 00:00:00 2001 From: brustybee Date: Thu, 19 Mar 2026 23:43:21 +0530 Subject: add flake templates --- common/templates/go/main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 common/templates/go/main.go (limited to 'common/templates/go/main.go') diff --git a/common/templates/go/main.go b/common/templates/go/main.go new file mode 100644 index 0000000..d895205 --- /dev/null +++ b/common/templates/go/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + "runtime" + "strings" + "unicode" +) + +func hello_world(action string) { + // 1. Get the Program Counter (PC) of the current function + pc, _, _, _ := runtime.Caller(0) + + // 2. Get the full function name (e.g., "main.hello_world") + fullFuncName := runtime.FuncForPC(pc).Name() + + // 3. Strip the package path to get just "hello_world" + // Splits "main.hello_world" and takes the last part + parts := strings.Split(fullFuncName, ".") + funcName := parts[len(parts)-1] + + // 4. Split into words: "hello", "world" + words := strings.Split(funcName, "_") + + // 5. Capitalize each word: "Hello", "World" + for i, w := range words { + runes := []rune(w) + runes[0] = unicode.ToUpper(runes[0]) + words[i] = string(runes) + } + + // 6. Join with ", " and add "!" -> "Hello, World!" + finalString := strings.Join(words, ", ") + "!" + + // 7. Execute the action + if action == "print" { + fmt.Println(finalString) + } +} + +func main() { + hello_world("print") +} -- cgit v1.3.1