Skip to content

Commit

Permalink
Merge pull request #1 from go-feature-flag/init-repo
Browse files Browse the repository at this point in the history
Init repo
  • Loading branch information
thomaspoignant authored Oct 2, 2024
2 parents d4297c6 + 75381e7 commit 9e2a73d
Show file tree
Hide file tree
Showing 20 changed files with 1,518 additions and 2 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: "Build"
on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened ]

jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- run: make vendor
- run: make build
Lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- run: make lint

Test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- run: make test

Coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- run: make coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# swagger-change:
# name: Swagger Change
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# fetch-depth: 1
# - name: Setup go
# uses: actions/setup-go@v5
# with:
# go-version-file: go.mod
# check-latest: true
# - run: make swagger
# - run: git diff --exit-code --quiet
54 changes: 54 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
out/

.DS_Store
.vscode
.idea
*.iml
.run

# reporting stuff
*-report.xml
*.cov
coverage.xml
bin/


# CI deployment folder
.deployment

# goreleaser
dist/
release/

vendor/

# venv created for the documentation script
.venv

# binaries
release/
cmd/migrationcli/migrationcli
cmd/relayproxy/relayproxy
tmp/

# Local dev files
goff-proxy.yaml
flags.yaml

go-feature-flag-relay-proxy/

# AWS SAM build folder
.aws-sam

node_modules/
oryxBuildBinary

./.sonarlint
sonarlint.xml
vcs.xml
workspace.xml
codeStyles/
inspectionProfiles/
misc.xml
modules.xml
shelf/
81 changes: 81 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
linters:
enable:
- asciicheck
- bodyclose
- dogsled
- dupl
- funlen
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- revive
- gosec
- lll
- misspell
- nakedret
- noctx
- prealloc
- rowserrcheck
- copyloopvar
- stylecheck
- unconvert
- unparam
- whitespace
- gofmt
- gci
# - gofumpt
linters-settings:
funlen:
lines: 90
statements: 50
gocritic:
disabled-checks:
- singleCaseSwitch
golint:
min-confidence: 0.6
gosimple:
checks: ["all","-S1023"]
gofumpt:
module-path: github.com/thomaspoignant/go-feature-flag
gci:
skip-generated: true
no-lex-order: true
issues:
exclude-dirs:
- (^|/)bin($|/)
- (^|/)examples($|/)
exclude-rules:
- path: _test.go
linters:
- funlen
- maligned
- noctx
- scopelint
- bodyclose
- lll
- goconst
- gocognit
- gocyclo
- gochecknoinits
- dupl
- staticcheck
- revive
- gosec
- copyloopvar
- path: _mock.go
linters:
- funlen
- maligned
- noctx
- scopelint
- bodyclose
- lll
- goconst
- gocognit
- gocyclo
- gochecknoinits
- dupl
- staticcheck
- revive
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/Bahjat/pre-commit-golang
rev: v1.0.3
hooks:
- id: gofumpt

- repo: https://github.com/golangci/golangci-lint
rev: v1.59.0
hooks:
- id: golangci-lint
entry: golangci-lint run --enable-only=gci --fix

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black
language_version: python3.12
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet

GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)

.PHONY: all test build vendor



all: help
## Build:
build: build-api ## Build all the binaries and put the output in out/bin/

create-out-dir:
mkdir -p out/bin

build-api: create-out-dir ## Build the migration cli in out/bin/
CGO_ENABLED=0 GO111MODULE=on $(GOCMD) build -mod vendor -o out/bin/goff-api .

clean: ## Remove build related file
-rm -fr ./bin ./out ./release
-rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml

vendor: ## Copy of all packages needed to support builds and tests in the vendor directory
$(GOCMD) mod tidy
$(GOCMD) mod vendor

## Dev:
swagger: ## Build swagger documentation
$(GOCMD) install github.com/swaggo/swag/cmd/swag@latest
cd cmd/relayproxy && swag init --parseDependency --parseDepth=1 --parseInternal --markdownFiles docs

setup-env:
docker stop goff || true
docker rm goff || true
docker run --name goff -e POSTGRES_DB=gofeatureflag -e POSTGRES_PASSWORD=my-secret-pw -p 5432:5432 -e POSTGRES_USER=goff-user -d postgres
sleep 2
migrate -source "file://database_migration" -database "postgres://goff-user:my-secret-pw@localhost:5432/gofeatureflag?sslmode=disable" up

## Test:
test: ## Run the tests of the project
$(GOTEST) -v -race ./...

coverage: ## Run the tests of the project and export the coverage
$(GOTEST) -cover -covermode=count -tags=docker -coverprofile=coverage.cov.tmp ./... \
&& cat coverage.cov.tmp | grep -v "/examples/" > coverage.cov


## Lint:
lint: ## Use golintci-lint on your project
mkdir -p ./bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest # Install linters
./bin/golangci-lint run --timeout=5m --timeout=5m ./... --enable-only=gci --fix # Run linters

## Help:
help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# app-api
API for https://app.gofeatureflag.org to manage your feature flags.
# GO Feature Flag API - API to configure your feature flag
![WIP](https://img.shields.io/badge/status-%E2%9A%A0%EF%B8%8FWIP-red)

This repository is a work in progress initiative to create an API to manage your feature flags.

## Goals
- Create an API to manage your feature flags
- API should allow to add, modify and delete feature flags.
- Use a database to store the feature flags.
- This API is created to integrate a front end application to manage the feature flags.
- We should manage authentication and authorization to access the API.
- Authentication should be generic enough to be integrated with any authentication provider.
- We should be able to provide history of a flag to see when it was created, modified and deleted.

## Tech stack
- GO API using echo
- Postgres database using `sqlx` and `pq` as driver.



## Contributing
⚠️ Since this it is a work in progress initiative please come to the [Slack channel](https://gofeatureflag.org/slack) first before contributing.

### How to start the project.
After cloning the project you can start the database _(using docker)_:
```shell
make setup-env
```
It will start an instance of postgres with the following credentials:
- user: `goff-user`
- password: `my-secret-pw`

And it will apply the database migrations to your environment.

To start the API:
```shell
make build
./out/bin/goff-api
```
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ignore:
- "examples"
- "testdata"
- "testutils"
- "**/_test.go"
- "**/_mock.go"
- "**/testdata/"
- "**/testutils/"
Loading

0 comments on commit 9e2a73d

Please sign in to comment.