Skip to content

Commit

Permalink
init template
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdneilsfield committed Oct 30, 2024
1 parent b92d7cf commit 2865060
Show file tree
Hide file tree
Showing 18 changed files with 800 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/.dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
time: "08:00"
labels:
- "dependencies"
commit-message:
prefix: "feat"
include: "scope"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
time: "08:00"
labels:
- "dependencies"
commit-message:
prefix: "chore"
include: "scope"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
time: "08:00"
labels:
- "dependencies"
commit-message:
prefix: "feat"
include: "scope"
59 changes: 59 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: write
packages: write

jobs:
goreleaser:
runs-on: ubuntu-latest
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23.2
# -
# name: Set up Node.js
# uses: actions/setup-node@v4
# with:
# node-version: 20.18.0
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
# -
# name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# -
# name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# -
# name: ghcr-login
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ go.work.sum

# env file
.env


.vscode/
.idea/
dist/
go-template
25 changes: 25 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
linters:
enable:
- gofmt
- goimports
- govet
- revive
- errcheck
- staticcheck
- gosimple
- ineffassign

run:
timeout: 5m

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck

linters-settings:
gofmt:
simplify: true
govet:
shadow: true
153 changes: 153 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
version: 2
env:
- GO111MODULE=on
- CGO_ENABLED=0

# before:
# hooks:
# - ./scripts/manpages.sh
# - ./scripts/completions.sh

builds:
-
binary: go-template
ldflags:
- -s -w
- -X main.version={{ .Version }}
- -X main.buildTime={{ .Date }}
- -X main.gitCommit={{ .FullCommit }}
goos:
- linux
- darwin
- windows
- freebsd
goarch:
- "386"
- amd64
- arm64
overrides:
- goos: darwin
goarch: amd64
ldflags:
- -s -w
env:
- CGO_ENABLED=0
- goos: darwin
goarch: arm64
ldflags:
- -s -w
env:
- CGO_ENABLED=0
- goos: linux
ldflags:
- -s -w -extldflags "-static"
- -X main.version={{ .Version }}
- -X main.buildTime={{ .Date }}
- -X main.gitCommit={{ .FullCommit }}


archives:
-
builds:
- go-template
format_overrides:
- goos: windows
format: zip
# files:
# - "config_example.toml"

release:
github:
owner: nerdneilsfield
name: go-template

# dockers:
# - image_templates:
# - 'nerdneils/go-template:{{ .Tag }}-amd64'
# - 'ghcr.io/nerdneilsfield/go-template:{{ .Tag }}-amd64'
# dockerfile: Dockerfile
# use: buildx
# build_flag_templates:
# - "--pull"
# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/nerdneilsfield/go-template/master/README.md"
# - "--label=io.artifacthub.package.maintainers=[{\"name\":\"dengqqi\",\"email\":\"dengqqi935@gmail.com\"}]"
# - "--label=io.artifacthub.package.license=MIT"
# - "--label=org.opencontainers.image.description=A fast and flexible translation gateway that routes requests to various LLM endpoints with configurable rate limiting and model-specific prompts."
# - "--label=org.opencontainers.image.created={{.Date}}"
# - "--label=org.opencontainers.image.name={{.ProjectName}}"
# - "--label=org.opencontainers.image.revision={{.FullCommit}}"
# - "--label=org.opencontainers.image.version={{.Version}}"
# - "--label=org.opencontainers.image.source={{.GitURL}}"
# - "--platform=linux/amd64"
# extra_files:
# - "config_example.toml"
# - image_templates:
# - 'nerdneils/go-template:{{ .Tag }}-arm64'
# - 'ghcr.io/nerdneilsfield/go-template:{{ .Tag }}-arm64'
# dockerfile: Dockerfile
# use: buildx
# build_flag_templates:
# - "--pull"
# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/nerdneilsfield/go-template/master/README.md"
# # - "--label=io.artifacthub.package.logo-url=https://raw.githubusercontent.com/nerdneilsfield/ghproxy-go/master/www/static/images/logo.png"
# - "--label=io.artifacthub.package.maintainers=[{\"name\":\"dengqqi\",\"email\":\"dengqqi935@gmail.com\"}]"
# - "--label=io.artifacthub.package.license=MIT"
# - "--label=org.opencontainers.image.description=A fast and flexible translation gateway that routes requests to various LLM endpoints with configurable rate limiting and model-specific prompts."
# - "--label=org.opencontainers.image.created={{.Date}}"
# - "--label=org.opencontainers.image.name={{.ProjectName}}"
# - "--label=org.opencontainers.image.revision={{.FullCommit}}"
# - "--label=org.opencontainers.image.version={{.Version}}"
# - "--label=org.opencontainers.image.source={{.GitURL}}"
# - "--platform=linux/arm64"
# goarch: arm64
# extra_files:
# - "config_example.toml"

# docker_manifests:
# - name_template: 'nerdneils/go-template:{{ .Tag }}'
# image_templates:
# - 'nerdneils/go-template:{{ .Tag }}-amd64'
# - 'nerdneils/go-template:{{ .Tag }}-arm64'
# - name_template: 'ghcr.io/nerdneilsfield/go-template:{{ .Tag }}'
# image_templates:
# - 'ghcr.io/nerdneilsfield/go-template:{{ .Tag }}-amd64'
# - 'ghcr.io/nerdneilsfield/go-template:{{ .Tag }}-arm64'
# - name_template: 'nerdneils/go-template:latest'
# image_templates:
# - 'nerdneils/go-template:{{ .Tag }}-amd64'
# - 'nerdneils/go-template:{{ .Tag }}-arm64'
# - name_template: 'ghcr.io/nerdneilsfield/go-template:latest'
# image_templates:
# - 'ghcr.io/nerdneilsfield/go-template:{{ .Tag }}-amd64'
# - 'ghcr.io/nerdneilsfield/go-template:{{ .Tag }}-arm64'

checksum:
name_template: "checksums.txt"

changelog:
sort: asc
use: github
filters:
exclude:
- '^test:'
- '^chore'
- 'merge conflict'
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
groups:
- title: Dependency updates
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
order: 300
- title: 'New Features'
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 100
- title: 'Bug fixes'
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 200
- title: 'Documentation updates'
regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$
order: 400
- title: Other work
order: 9999
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": ["prettier-plugin-go"],
"printWidth": 100,
"tabWidth": 4,
"semi": false,
"trailingComma": "es5"
}
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine:latest

COPY polyglot-gate-server /app/polyglot-gate-server
COPY config_example.toml /app/config.toml

ENTRYPOINT ["/app/polyglot-gate-server", "run", "/app/config.toml"]
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
projectname?=go-template

default: help

.PHONY: help
help: ## list makefile targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: build
build: ## build golang binary
@go build -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)" -o $(projectname)

.PHONY: install
install: ## install golang binary
@go install -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)"

.PHONY: run
run: ## run the app
@go run -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)" main.go

.PHONY: bootstrap
bootstrap: ## install build deps
go generate -tags tools tools/tools.go

PHONY: test
test: clean ## display test coverage
go test --cover -parallel=1 -v -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | sort -rnk3

PHONY: clean
clean: ## clean up environment
@rm -rf coverage.out dist/ $(projectname)

PHONY: cover
cover: ## display test coverage
go test -v -race $(shell go list ./... | grep -v /vendor/) -v -coverprofile=coverage.out
go tool cover -func=coverage.out

PHONY: fmt
fmt: ## format go files
gofumpt -w .
gci write .

PHONY: lint
lint: ## lint go files
golangci-lint run -c .golang-ci.yml

PHONY: release-test
release-test: ## test release
goreleaser release --rm-dist --snapshot --clean --skip-publish

# .PHONY: pre-commit
# pre-commit: ## run pre-commit hooks
# pre-commit run --all-files
Loading

0 comments on commit 2865060

Please sign in to comment.