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/.envrc | 1 + common/templates/go/.gitignore | 36 +++++++++++++++++++++++++++++++ common/templates/go/flake.nix | 49 ++++++++++++++++++++++++++++++++++++++++++ common/templates/go/go.mod | 4 ++++ common/templates/go/main.go | 43 ++++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 common/templates/go/.envrc create mode 100644 common/templates/go/.gitignore create mode 100644 common/templates/go/flake.nix create mode 100644 common/templates/go/go.mod create mode 100644 common/templates/go/main.go (limited to 'common/templates/go') diff --git a/common/templates/go/.envrc b/common/templates/go/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/common/templates/go/.envrc @@ -0,0 +1 @@ +use flake diff --git a/common/templates/go/.gitignore b/common/templates/go/.gitignore new file mode 100644 index 0000000..9c1605b --- /dev/null +++ b/common/templates/go/.gitignore @@ -0,0 +1,36 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Code coverage profiles and other test artifacts +*.out +coverage.* +*.coverprofile +profile.cov + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env +.direnv + +#nix +result + +# Editor/IDE +# .idea/ +# .vscode/ diff --git a/common/templates/go/flake.nix b/common/templates/go/flake.nix new file mode 100644 index 0000000..3f8e7d5 --- /dev/null +++ b/common/templates/go/flake.nix @@ -0,0 +1,49 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = + { + self, + nixpkgs, + ... + }: + let + inherit (nixpkgs) lib; + forAllSystems = lib.genAttrs lib.systems.flakeExposed; + in + { + packages = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + default = pkgs.buildGoModule { + pname = "hello_go"; + version = "0.0.1"; + src = self; + + # The "Trust but Verify" hash. + vendorHash = null; + }; + } + ); + + devShells = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + default = pkgs.mkShellNoCC { + packages = with pkgs; [ + go + gopls + gotools + go-tools + ]; + }; + } + ); + }; +} diff --git a/common/templates/go/go.mod b/common/templates/go/go.mod new file mode 100644 index 0000000..24673a6 --- /dev/null +++ b/common/templates/go/go.mod @@ -0,0 +1,4 @@ +module hello_go + +go 1.25.5 + 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