Skip to content
Snippets Groups Projects
Commit 2d4392b8 authored by sivan's avatar sivan
Browse files

added service template

parent 4af778bb
No related branches found
No related tags found
No related merge requests found
image: golang:1.16
stages:
- test
lint:
stage: test
script:
- make lint
unit_tests:
stage: test
script:
- make dep
- make test
- gocover-cobertura < coverage/coverage.txt > coverage/coverage.xml
artifacts:
reports:
cobertura: coverage/coverage.xml
race:
stage: test
script:
- make race
coverage:
stage: test
script:
- make coverage
artifacts:
untracked: false
expire_in: 30 days
paths:
- "coverage/cover.html"
Makefile 0 → 100644
lint: dep ## Lint the files
@golint -set_exit_status ./...
test: ## Run unittests
@go test -cover -coverprofile=coverage/coverage.txt -covermode count ./...
race: dep ## Run data race detector
@go test -race -short ./...
dep: ## Get the dependencies
@go get -v -d ./...
@go get -u golang.org/x/lint/golint
@go get -u github.com/boumenot/gocover-cobertura
coverage: dep
@go test -v -coverpkg=./... -coverprofile=coverage/cover.out ./...
@go tool cover -func coverage/cover.out | grep total
@go tool cover -html=coverage/cover.out -o coverage/cover.html
windows:
$(eval GOOS := windows)
@go build -o main ./cmd/service-template/
@mv main builds
macos: dep
$(eval GOOS := darwin)
@go build -o main ./cmd/service-template/
@mv main builds
linux: # Build for linux
$(eval GOOS := linux)
@go build -o main ./cmd/service-template/
@mv main builds
run:
./builds/main
\ No newline at end of file
# Service Template
Keep in mind that not all folders are required, only the `/builds`, `/cmd/app-name` and `/coverage` folders are required.
\ No newline at end of file
# Ignore everything in this directory
*
# Except this file
!.gitignore
!README.md
\ No newline at end of file
# `/builds`
Where the built binaries are placed. Everything in this folder should be ignored by a .gitignore file.
\ No newline at end of file
# `/cmd`
Main applications for this project.
The directory name for each application should match the name of the executable you want to have (e.g., /cmd/myapp).
Don't put a lot of code in the application directory. If you think the code can be imported and used in other projects, then it should live in the /pkg directory. If the code is not reusable or if you don't want others to reuse it, put that code in the /internal directory. You'll be surprised what others will do, so be explicit about your intentions!
It's common to have a small main function that imports and invokes the code from the /internal and /pkg directories and nothing else.
\ No newline at end of file
package main
func main() {
}
# Ignore everything in this directory
*
# Except this file
!.gitignore
!README.md
\ No newline at end of file
# `/coverage`
Where code coverage statistics go when running command like `make coverage`.
\ No newline at end of file
# `/deployments`
Docker and Kubernetes yaml files.
\ No newline at end of file
module query-service
module service-template
go 1.15
# `/internal`
Private application and library code. This is the code you don't want others importing in their applications or libraries. Note that this layout pattern is enforced by the Go compiler itself. See the Go 1.4 [`release notes`](https://golang.org/doc/go1.4#internalpackages) for more details. Note that you are not limited to the top level `internal` directory. You can have more than one `internal` directory at any level of your project tree.
# `/pkg`
Library code that's ok to use by external applications (e.g., /pkg/mypubliclib). Other projects will import these libraries expecting them to work, so think twice before you put something here :-) Note that the internal directory is a better way to ensure your private packages are not importable because it's enforced by Go. The /pkg directory is still a good way to explicitly communicate that the code in that directory is safe for use by others. The I'll take pkg over internal blog post by Travis Jeffery provides a good overview of the pkg and internal directories and when it might make sense to use them.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment