summaryrefslogtreecommitdiff
path: root/common/templates/go/main.go
diff options
context:
space:
mode:
authorbrustybee <bee@4d2.org>2026-03-19 23:43:21 +0530
committerbrustybee <bee@4d2.org>2026-03-19 23:43:21 +0530
commit9d2256adddbb830d33119a5e01e3fad6b4b0652b (patch)
tree958e1de443a6d59a9b09716ba5815c52bfb7bfb3 /common/templates/go/main.go
parentf9142a5822a4f212a3031b932cbf51b2d50344a8 (diff)
add flake templates
Diffstat (limited to 'common/templates/go/main.go')
-rw-r--r--common/templates/go/main.go43
1 files changed, 43 insertions, 0 deletions
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")
+}