Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templater #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

5 changes: 0 additions & 5 deletions build/package/project.dockerfile

This file was deleted.

25 changes: 0 additions & 25 deletions cmd/boilerplate-go/handle.go

This file was deleted.

26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"os"

"github.com/temp-lib/templater"
)

func main() {
if len(os.Args) != 3 {
fmt.Println("usage : app serviceName user")
return
}
cfg := templater.Config{
ServiceName: os.Args[1],
User: os.Args[2],
IgnorePatterns: []string{".html", ".yml", ".yaml", ".tpl", ".txt", "js.map"},
}
templtr := templater.New(cfg)
err := templtr.BuildService(`./template/{{.ServiceName}}`,
`./`)
if err != nil {
fmt.Println(err)
}
}
File renamed without changes.
109 changes: 109 additions & 0 deletions template/{{.ServiceName}}/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Build and Test
on:
push:
branches:
- master
pull_request:

jobs:

lint:
name: Lint
strategy:
matrix:
go-version: [1.14.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v2

- name: Lint Go Code
run: |
make lint

test:
name: Test
strategy:
matrix:
go-version: [1.14.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v2

- name: Run Unit tests.
run: make test

slint:
name: Super Linter
strategy:
matrix:
go-version: [1.14.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Check out code
uses: actions/checkout@v2

# - name: Super-Linter
# uses: github/[email protected]
# with:
# fail_ci_if_error: true

test-coverage:
name: Test Coverage
strategy:
matrix:
go-version: [1.14.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v2

- name: Run tests coverage.
run: make test-coverage

- name: Upload Coverage report to CodeCov
uses: codecov/[email protected]
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.txt
# fail_ci_if_error: true

build:
name: Build
strategy:
matrix:
go-version: [1.14.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
needs: [lint, test]
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v2

- name: Build
run: make build
28 changes: 28 additions & 0 deletions template/{{.ServiceName}}/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Mac OS X files
.DS_Store

#.env

# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

deployments/redis-persistence/*
bin/*
logs/*

/vendor
/vendor.pb
/.idea
/.vscode
6 changes: 3 additions & 3 deletions .gitlab-ci.yml → template/{{.ServiceName}}/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ stages:

variables:
KUBECONFIG: /etc/deploy/config
REPOSITORY: and07/boilerplate-go
NAMESPACE: boilerplate-go
REPOSITORY: {{.User}}/{{.ServiceName}}
NAMESPACE: {{.ServiceName}}
TAG: ${CI_BUILD_REF_NAME}_${CI_BUILD_REF}
CONTAINER_IMAGE: docker.io/${REPOSITORY}:${CI_BUILD_REF_NAME}_${CI_BUILD_REF}
CONTAINER_IMAGE_LATEST: docker.io/${REPOSITORY}:latest
Expand Down Expand Up @@ -41,7 +41,7 @@ lint:
# - echo ${kube_config} | base64 -d > ${KUBECONFIG}
# - helm init --client-only
# script:
# - cd deployments/kubernetes/boilerplate-go-chart
# - cd deployments/kubernetes/{{.ServiceName}}-chart
# - export DEPLOYS=$(helm ls | grep $NAMESPACE | wc -l)
# - >
# if [ ${DEPLOYS} -eq 0 ]; then
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion LICENSE → template/{{.ServiceName}}/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 and07
Copyright (c) 2020 {{.User}}

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
24 changes: 12 additions & 12 deletions Makefile → template/{{.ServiceName}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# note: call scripts from /scripts
SERVICE_NAME=boilerplate-go
USER=and07
.ServiceName={{.ServiceName}}
USER={{.User}}
VERSION=latest
REPOSITORY="$(USER)/$(SERVICE_NAME)"
REPOSITORY="$(USER)/$(.ServiceName)"
QUAYVERSION = "${REPOSITORY}:$(VERSION)"

TAG=${CI_BUILD_REF_NAME}_${CI_BUILD_REF}
Expand Down Expand Up @@ -47,10 +47,10 @@ export GO111MODULE=on
SHELL=/bin/bash -o pipefail


APP?=$(SERVICE_NAME)
PROJECT?=github.com/$(USER)/$(SERVICE_NAME)
APP?=$(.ServiceName)
PROJECT?=github.com/$(USER)/$(.ServiceName)

LDFLAGS:=-X '${PROJECT}/version.Name=$(SERVICE_NAME)'\
LDFLAGS:=-X '${PROJECT}/version.Name=$(.ServiceName)'\
-X '${PROJECT}/version.ProjectID=$(CI_PROJECT_ID)'\
-X '${PROJECT}/version.Version=$(APP_VERSION)'\
-X '${PROJECT}/version.GoVersion=$(GO_VERSION_SHORT)'\
Expand Down Expand Up @@ -125,14 +125,14 @@ install-protoc: ## Install protoc
github.com/golang/protobuf/protoc-gen-go

gen-protoc: ## protoc generation
mkdir -p "./api/gen-${SERVICE_NAME}"
mkdir -p "./api/gen-${.ServiceName}"
protoc -I/usr/local/include -I. \
-I${GOPATH}/src \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway \
--grpc-gateway_out=logtostderr=true:./api/gen-$(SERVICE_NAME) \
--grpc-gateway_out=logtostderr=true:./api/gen-$(.ServiceName) \
--swagger_out=allow_merge=true,merge_file_name=api:./assets/swaggerui \
--go_out=plugins=grpc:./api/gen-$(SERVICE_NAME) ./api/*.proto
--go_out=plugins=grpc:./api/gen-$(.ServiceName) ./api/*.proto


.PHONY: install-lint
Expand Down Expand Up @@ -201,7 +201,7 @@ docker-logs: ## Docker logs
mkdir -p ./logs || true
#docker logs postgres-$${CI_JOB_ID:-local} >& logs/postgres.log
#docker logs pg-migrations-$${CI_JOB_ID:-local} >& logs/pg-migrations.log
docker logs $${SERVICE_NAME}-$${CI_JOB_ID:-local} >& logs/$${SERVICE_NAME}.log
docker logs $${.ServiceName}-$${CI_JOB_ID:-local} >& logs/$${.ServiceName}.log
docker logs redis-$${CI_JOB_ID:-local} >& logs/redis.log
docker logs rabbitmq-$${CI_JOB_ID:-local} >& logs/rabbitmq.log
docker logs elasticsearch-$${CI_JOB_ID:-local} >& logs/elasticsearch.log
Expand All @@ -219,8 +219,8 @@ docker-clean:
docker rm -f $$(docker ps -a -f status=exited -q) || true
@echo Очистка dangling образов
docker rmi -f $$(docker images -f "dangling=true" -q) || true
@echo Очистка $${SERVICE_NAME} образов
docker rmi -f $$(docker images --filter=reference='$${SERVICE_NAME}*' -q) || true
@echo Очистка $${.ServiceName} образов
docker rmi -f $$(docker images --filter=reference='$${.ServiceName}*' -q) || true
#@echo Очистка itest образов
#docker rmi -f $$(docker images --filter=reference='itest*' -q) || true
#@echo Очистка pg-migrations образов
Expand Down
1 change: 1 addition & 0 deletions template/{{.ServiceName}}/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bin/{{.ServiceName}}
12 changes: 6 additions & 6 deletions README.md → template/{{.ServiceName}}/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/and07/boilerplate-go)](https://goreportcard.com/report/github.com/and07/boilerplate-go)
[![codecov](https://codecov.io/gh/and07/boilerplate-go/branch/master/graph/badge.svg)](https://codecov.io/gh/and07/boilerplate-go)
[![Actions Status](https://github.com/and07/boilerplate-go/workflows/Build%20and%20Test/badge.svg)](https://github.com/and07/boilerplate-go/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/{{.User}}/{{.ServiceName}})](https://goreportcard.com/report/github.com/{{.User}}/{{.ServiceName}})
[![codecov](https://codecov.io/gh/{{.User}}/{{.ServiceName}}/branch/master/graph/badge.svg)](https://codecov.io/gh/{{.User}}/{{.ServiceName}})
[![Actions Status](https://github.com/{{.User}}/{{.ServiceName}}/workflows/Build%20and%20Test/badge.svg)](https://github.com/{{.User}}/{{.ServiceName}}/actions)
[![MIT License](http://img.shields.io/:license-mit-blue.svg)](LICENSE)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fand07%2Fboilerplate-go.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fand07%2Fboilerplate-go?ref=badge_shield)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2F{{.User}}%2F{{.ServiceName}}.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2F{{.User}}%2F{{.ServiceName}}?ref=badge_shield)

# Standard Go Project Layout (Boilerplate-GO)

Expand Down Expand Up @@ -30,13 +30,13 @@ $ echo "$(minikube ip) private-boi.minikube" | sudo tee -a /etc/hosts

```sh
helm package jaeger --debug
helm package boilerplate-go-chart --debug
helm package {{.ServiceName}}-chart --debug
```

```sh
$ helm install --name jaeger jaeger-0.1.0.tgz

$ helm install --name boi boilerplate-go-chart-0.1.0.tgz
$ helm install --name boi {{.ServiceName}}-chart-0.1.0.tgz

$ helm install --name prometheus --namespace monitoring -f prometheus-values.yaml stable/prometheus

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package api;

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
info: {
title: "My boilerplate-go"
title: "My {{.ServiceName}}"
version: "1.0"
contact: {
name: "and07"
url: "https://github.com/and07"
name: "{{.User}}"
url: "https://github.com/{{.User}}"
email: ""
};
};
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"swagger": "2.0",
"info": {
"title": "My boilerplate-go",
"title": "My {{.ServiceName}}",
"version": "1.0",
"contact": {
"name": "and07",
"url": "https://github.com/and07"
"name": "{{.User}}",
"url": "https://github.com/{{.User}}"
}
},
"host": "localhost:8843",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions template/{{.ServiceName}}/build/package/project.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine

COPY bin/{{.ServiceName}} .
COPY tpl tpl
CMD ["/{{.ServiceName}}"]
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions template/{{.ServiceName}}/cmd/{{.ServiceName}}/handle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"context"
"net/http"

"github.com/{{.User}}/{{.ServiceName}}/internal/pkg/template"
)

func hiHandler(ctx context.Context, tpl *template.Template, tmplData interface{}) func(w http.ResponseWriter, r *http.Request) {

return func(w http.ResponseWriter, r *http.Request) {
//span, _ := opentracing.StartSpanFromContext(ctx, "Scratch.hiHandler")
//defer span.Finish()
counter.Inc()

tpl.RenderTemplate(w, "main.html", tmplData)
}
}

func publicHandle(ctx context.Context, tpl *template.Template, tmplData interface{}) *http.ServeMux {
rPublic := http.NewServeMux()
rPublic.HandleFunc("/", hiHandler(ctx, tpl, tmplData))
return rPublic
}
Loading