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

feat: initiate repo #1

Merged
merged 2 commits into from
Feb 9, 2022
Merged
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
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Summary

Please fill in a short summary for your PR here.

---

Please make sure the PR commits

- follow the [7 rules of commit messages](https://chris.beams.io/posts/git-commit/)
- follow the [conventional commits guidelines](https://www.conventionalcommits.org/)
- are rearrange to squash trivial commits together (use [git rebase](http://gitready.com/advanced/2009/03/20/reorder-commits-with-rebase.html)
2 changes: 2 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Always validate the PR title AND all the commits
titleAndCommits: true
102 changes: 102 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# From https://github.com/github/gitignore

#### Visual Studio Code
.vscode
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

#### Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Sphinx documentation
docs/_build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Cython debug symbols
cython_debug/

# Auto-gen files
autogen

# mysql persistent data
mysql-persistence/

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

/openapi

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

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

# Dependency directories (remove the comment below to include it)
# vendor/
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/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: git://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: golangci-lint
- id: go-mod-tidy
- repo: https://github.com/pinglin/conventional-pre-commit
rev: v1.1.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@bochengyang @pinglin @Phelan164 @xiaofei-du
* @bochengyang @pinglin @Phelan164 @xiaofei-du
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.17.2 AS build

WORKDIR /go/src
COPY . /go/src

RUN go get -d -v ./...

RUN --mount=type=cache,target=/root/.cache/go-build go build -o /pipeline-backend ./cmd/
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /pipeline-backend-migrate ./internal/db/migrations

FROM gcr.io/distroless/base AS runtime

ENV GIN_MODE=release
WORKDIR /pipeline-backend

COPY --from=build /pipeline-backend ./
COPY --from=build /pipeline-backend-migrate ./
COPY --from=build /go/src/configs ./configs
COPY --from=build /go/src/internal/db/migrations ./internal/db/migrations

EXPOSE 8080/tcp
ENTRYPOINT ["./pipeline-backend"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Pipeline-backend
15 changes: 15 additions & 0 deletions cmd/custom_middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"net/http"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
)

func appendCustomHeaderMiddleware(next runtime.HandlerFunc) runtime.HandlerFunc {
return runtime.HandlerFunc(func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
r.Header.Add("Username", "local-user")

next(w, r, pathParams)
})
}
53 changes: 53 additions & 0 deletions cmd/interceptors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"context"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)

// RecoveryInterceptor - panic handler
func recoveryInterceptorOpt() grpc_recovery.Option {
return grpc_recovery.WithRecoveryHandler(func(p interface{}) (err error) {
return status.Errorf(codes.Unknown, "panic triggered: %v", p)
})
}

// CustomInterceptor - append metadatas for unary
func unaryAppendMetadataInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, status.Error(codes.Internal, "can not extract metadata")
}

md.Append("Username", "local-user")

newCtx := metadata.NewIncomingContext(ctx, md)

h, err := handler(newCtx, req)

return h, err
}

// CustomInterceptor - append metadatas for stream
func streamAppendMetadataInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
md, ok := metadata.FromIncomingContext(stream.Context())
if !ok {
return status.Error(codes.Internal, "can not extract metadata")
}

md.Append("Username", "local-user")

newCtx := metadata.NewIncomingContext(stream.Context(), md)
wrapped := grpc_middleware.WrapServerStream(stream)
wrapped.WrappedContext = newCtx

err := handler(srv, wrapped)

return err
}
Loading