Skip to content

Commit

Permalink
feat(go): add some options
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 18, 2023
1 parent 5916345 commit 0d685ec
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 36 deletions.
2 changes: 0 additions & 2 deletions template/cxx/cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ cargo_generate_version = ">=0.10.0"
[placeholders.gh_uname]
type = "string"
prompt = "GitHub username (or organization)?"
# The username cannot end with a hyphen, too, but
# this requirement is not captured by the regex at the moment.
regex = "^[A-Za-z0-9][A-Za-z0-9-]{0,38}$"

[placeholders.proj_description]
Expand Down
2 changes: 1 addition & 1 deletion template/go/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ max_line_length = 120
tab_width = 4
trim_trailing_whitespace = true

[{*.go,*.go2}]
[{Makefile,*.go}]
indent_style = tab
34 changes: 2 additions & 32 deletions template/go/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,12 @@ If the required subsection does not exist yet under **Unreleased**, create it!

### Set up

This is no different than other Rust projects.
This is no different from other Go projects.

```shell
git clone https://github.com/{{gh_uname}}/{{project-name}}
cd {{project-name}}
cargo test
make test
```

### Useful Commands
{% if crate_type == "bin" %}
- Build and run release version:

```shell
cargo build --release && cargo run --release
```
{% endif %}
- Run Clippy:

```shell
cargo clippy --all-targets --all-features --workspace
```

- Run all tests:

```shell
cargo test --all-features --workspace
```

- Check to see if there are code formatting issues

```shell
cargo fmt --all -- --check
```

- Format the code in the project

```shell
cargo fmt --all
```
2 changes: 1 addition & 1 deletion template/go/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 {{authors}}
Copyright (c) 2023 {{authors}}

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
27 changes: 27 additions & 0 deletions template/go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.PHONY: help
.DEFAULT_GOAL := help

APP_NAME := go

# build image
image:
@docker image build -t $(APP_NAME) .

# buildx cross

# Show help
help:
@echo ""
@echo "Usage:"
@echo " make [target]"
@echo ""
@echo "Targets:"
@awk '/^[a-zA-Z\-_0-9]+:/ \
{ \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} { lastLine = $$0 }' $(MAKEFILE_LIST)
14 changes: 14 additions & 0 deletions template/go/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
[template]
cargo_generate_version = ">=0.10.0"

[placeholders.gh_uname]
type = "string"
prompt = "GitHub username (or organization)?"
regex = "^[A-Za-z0-9][A-Za-z0-9-]{0,38}$"

[placeholders.proj_desc]
type = "string"
prompt = "Project description?"

[placeholders.go_version]
type = "string"
prompt = "Go version? e.g. 1.18, 1.21"
regex = "^[0-9]+(\\.[0-9]+){0,2}$"
File renamed without changes.
3 changes: 3 additions & 0 deletions template/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/{{gh_uname}}/{{project-name}}

go {{go_version}}

0 comments on commit 0d685ec

Please sign in to comment.