Skip to content

Instantly share code, notes, and snippets.

@bayashi
Last active December 8, 2023 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayashi/7de519d16b38d167a1001056947f4479 to your computer and use it in GitHub Desktop.
Save bayashi/7de519d16b38d167a1001056947f4479 to your computer and use it in GitHub Desktop.
go-tmpl.patch for Module::Setup flavor
diff --git a/additional/config.yaml b/additional/config.yaml
new file mode 100644
index 0000000..2fbf0ff
--- /dev/null
+++ b/additional/config.yaml
@@ -0,0 +1 @@
+--- {}
diff --git a/config.yaml b/config.yaml
new file mode 100644
index 0000000..3777dd0
--- /dev/null
+++ b/config.yaml
@@ -0,0 +1,12 @@
+---
+author: YOUR NAME
+github_account: your_account
+class: Module::Setup::Flavor::Default
+email: your_email [at] example.com
+license: artistic_2
+plugins:
+ - Config::Basic
+ - Template
+ - +OreOre::Hide::Module::Setup::Plugin::Golang
+ - Additional
+ - VC::Git
diff --git a/plugins/Golang.pm b/plugins/Golang.pm
new file mode 100644
index 0000000..c6e2fc2
--- /dev/null
+++ b/plugins/Golang.pm
@@ -0,0 +1,43 @@
+package OreOre::Hide::Module::Setup::Plugin::Golang;
+use strict;
+use warnings;
+use parent 'Module::Setup::Plugin';
+
+my @WEEK_DAYS = (
+ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
+);
+my @MONTHS = (
+ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
+ 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
+);
+
+sub register {
+ my ( $self, ) = @_;
+
+ $self->add_trigger(
+ 'after_setup_template_vars' => \&after_setup_template_vars
+ );
+}
+
+sub after_setup_template_vars {
+ my ( $self, $config ) = @_;
+
+ my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst )
+ = localtime;
+ my $new_config = +{
+ 'mysimple_year' => $year + 1900,
+ 'mysinple_localtime' => sprintf(
+ "%s %s %s %s:%s:%s JST %s",
+ $WEEK_DAYS[$wday],
+ $MONTHS[$mon], $mday,
+ $hour, $min, $sec,
+ $year + 1900,
+ ),
+ };
+
+ while ( my ( $key, $val ) = each %{$new_config} ) {
+ $config->{$key} = $val;
+ }
+}
+
+1;
diff --git a/template/.github/workflows/run-staticcheck.yaml b/template/.github/workflows/run-staticcheck.yaml
new file mode 100644
index 0000000..9ae9249
--- /dev/null
+++ b/template/.github/workflows/run-staticcheck.yaml
@@ -0,0 +1,49 @@
+name: staticcheck
+
+on:
+ push:
+ branches:
+ - '*'
+ tags-ignore:
+ - '*'
+ paths-ignore:
+ - '**/*.md'
+ - '**/.gitignore'
+ pull_request:
+ paths-ignore:
+ - '**/*.md'
+ - '**/.gitignore'
+
+jobs:
+ build:
+ strategy:
+ fail-fast: false
+ matrix:
+ os: ["ubuntu-latest"]
+ go: ["1.21"]
+
+ runs-on: ${{ matrix.os }}
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Setup go${{ matrix.go }}
+ uses: actions/setup-go@v4
+ with:
+ go-version: ${{ matrix.go }}
+
+ - name: Install dependencies
+ run: go get .
+
+ - name: Run vet
+ run: go vet -v ./...
+
+ - name: Setup staticcheck
+ uses: dominikh/staticcheck-action@v1.3.0
+ with:
+ version: "2023.1.6"
+ install-go: false
+ min-go-version: ${{ matrix.go }}
+ cache-key: ${{ matrix.os }}-${{ matrix.go }}
+
+ - name: Run staticcheck
+ run: staticcheck ./...
diff --git a/template/.github/workflows/run-tests.yaml b/template/.github/workflows/run-tests.yaml
new file mode 100644
index 0000000..3d255af
--- /dev/null
+++ b/template/.github/workflows/run-tests.yaml
@@ -0,0 +1,45 @@
+name: main
+
+on:
+ push:
+ branches:
+ - '*'
+ tags-ignore:
+ - '*'
+ paths-ignore:
+ - '**/*.md'
+ - '**/.gitignore'
+ pull_request:
+ paths-ignore:
+ - '**/*.md'
+ - '**/.gitignore'
+
+jobs:
+ build:
+ strategy:
+ fail-fast: false
+ matrix:
+ os: ["windows-latest", "ubuntu-latest", "macOS-latest"]
+ go: ["1.18", "1.21"]
+
+ runs-on: ${{ matrix.os }}
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Setup go${{ matrix.go }}
+ uses: actions/setup-go@v4
+ with:
+ go-version: ${{ matrix.go }}
+
+ - name: Ensure go.mod is already tidied
+ run: go mod tidy && git diff -s --exit-code go.sum
+
+ - name: Install dependencies
+ run: go get .
+
+ - name: Build
+ run: go build -v ./...
+
+ - name: Test with the Go CLI
+ run: go test -v ./... -shuffle=on -timeout=3m -cover
diff --git a/template/.gitignore b/template/.gitignore
new file mode 100644
index 0000000..67201fd
--- /dev/null
+++ b/template/.gitignore
@@ -0,0 +1,5 @@
+.idea
+.vscode
+*.sw[po]
+vendor
+dist/
diff --git a/template/LICENSE b/template/LICENSE
new file mode 100644
index 0000000..f88eed5
--- /dev/null
+++ b/template/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) [% mysimple_year %] [% config.author %]
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/template/README.md b/template/README.md
new file mode 100644
index 0000000..0f4c62b
--- /dev/null
+++ b/template/README.md
@@ -0,0 +1,36 @@
+# [% module %]
+
+<a href="https://github.com/[% config.github_account %]/[% module %]/blob/main/LICENSE" title="[% module %] License"><img src="https://img.shields.io/badge/LICENSE-MIT-GREEN.png" alt="MIT License"></a>
+<a href="https://github.com/[% config.github_account %]/[% module %]/actions" title="[% module %] CI"><img src="https://github.com/[% config.github_account %]/[% module %]/workflows/main/badge.svg" alt="[% module %] CI"></a>
+<a href="https://goreportcard.com/report/github.com/[% config.github_account %]/[% module %]" title="[% module %] report card" target="_blank"><img src="https://goreportcard.com/badge/github.com/[% config.github_account %]/[% module %]" alt="[% module %] report card"></a>
+<a href="https://pkg.go.dev/github.com/[% config.github_account %]/[% module %]" title="Go [% module %] package reference" target="_blank"><img src="https://pkg.go.dev/badge/github.com/[% config.github_account %]/[% module %].svg" alt="Go Reference: [% module %]"></a>
+
+`[% module %]` provides
+
+## Usage
+
+```go
+package main
+
+import (
+ "fmt"
+)
+
+func main() {
+
+}
+```
+
+## Installation
+
+```cmd
+go get github.com/[% config.github_account %]/[% module %]
+```
+
+## License
+
+MIT License
+
+## Author
+
+[% config.author %]: https://github.com/[% config.github_account %]
diff --git a/template/go.mod b/template/go.mod
new file mode 100644
index 0000000..4e68f31
--- /dev/null
+++ b/template/go.mod
@@ -0,0 +1,3 @@
+module github.com/[% config.github_account %]/[% module %]
+
+go 1.21
diff --git a/template/main.go b/template/main.go
new file mode 100644
index 0000000..e9a2527
--- /dev/null
+++ b/template/main.go
@@ -0,0 +1,9 @@
+package main
+
+import (
+ "fmt"
+)
+
+func main() {
+ fmt.Println("foo")
+}
@bayashi
Copy link
Author

bayashi commented Dec 8, 2023

How to apply this patch

curl -L https://gist.githubusercontent.com/bayashi/7de519d16b38d167a1001056947f4479/raw/aed552951777492107874520dee1f571d7ff4c91/go-tmpl.patch -o /tmp/go-tmpl.patch
mkdir your_flavor
cd your_flavor
patch -p1 < /tmp/go-tmpl.patch

Then,

$ tree -a
.
├── additional
│   └── config.yaml
├── config.yaml
├── plugins
│   └── Golang.pm
└── template
    ├── .github
    │   └── workflows
    │       ├── run-staticcheck.yaml
    │       └── run-tests.yaml
    ├── .gitignore
    ├── LICENSE
    ├── README.md
    ├── go.mod
    └── main.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment