Skip to content

Commit a1f7c6b

Browse files
Merge pull request #2 from jeferagudeloc/develop
Develop
2 parents fd377bc + df1ea88 commit a1f7c6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1985
-2
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# grpc-http-gateway
2-
project to test grpc, clean architecture and gorm
1+
# todo

docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
services:
3+
server:
4+
build:
5+
context: './src/server'
6+
dockerfile: 'Dockerfile'
7+
container_name: server
8+
volumes:
9+
- ./src/server:/usr/src/app/
10+
networks:
11+
- bridge
12+
gateway:
13+
build:
14+
context: './src/gateway'
15+
dockerfile: 'Dockerfile'
16+
container_name: gateway
17+
ports:
18+
- 9091:8080
19+
depends_on:
20+
- server
21+
restart: on-failure
22+
volumes:
23+
- ./src/client:/usr/src/app/
24+
networks:
25+
- bridge
26+
networks:
27+
bridge:
28+
driver: bridge

src/gateway/.DS_Store

6 KB
Binary file not shown.

src/gateway/.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${workspaceFolder}/main.go",
13+
"args": [],
14+
}
15+
]
16+
}

src/gateway/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:alpine3.14 AS build
2+
WORKDIR /build
3+
COPY . .
4+
RUN apk add git
5+
RUN go build -buildvcs=false -o app .
6+
7+
FROM golang:alpine3.14 AS run
8+
RUN addgroup -g 1000 golang && adduser -u 1000 -S -G golang -D golang
9+
USER golang
10+
11+
WORKDIR /app
12+
COPY --from=build /build/app .
13+
ENTRYPOINT ["./app"]

src/gateway/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# todo
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package action
2+
3+
import "net/http"
4+
5+
func HealthCheck(w http.ResponseWriter, _ *http.Request) {
6+
w.WriteHeader(http.StatusOK)
7+
}
8+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package logger
2+
3+
type Logger interface {
4+
Infof(format string, args ...interface{})
5+
Warnf(format string, args ...interface{})
6+
Errorf(format string, args ...interface{})
7+
Fatalln(args ...interface{})
8+
WithFields(keyValues Fields) Logger
9+
WithError(err error) Logger
10+
}
11+
12+
type Fields map[string]interface{}
13+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package logging
2+
3+
import "github.com/jeferagudeloc/grpc-http-gateway/src/gateway/application/adapter/logger"
4+
5+
type Error struct {
6+
log logger.Logger
7+
err error
8+
key string
9+
httpStatus int
10+
}
11+
12+
func NewError(log logger.Logger, err error, key string, httpStatus int) Error {
13+
return Error{
14+
log: log,
15+
err: err,
16+
key: key,
17+
httpStatus: httpStatus,
18+
}
19+
}
20+
21+
func (e Error) Log(msg string) {
22+
e.log.WithFields(logger.Fields{
23+
"key": e.key,
24+
"error": e.err.Error(),
25+
"http_status": e.httpStatus,
26+
}).Errorf(msg)
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package logging
2+
3+
import "github.com/jeferagudeloc/grpc-http-gateway/src/gateway/application/adapter/logger"
4+
5+
type Info struct {
6+
log logger.Logger
7+
key string
8+
httpStatus int
9+
}
10+
11+
func NewInfo(log logger.Logger, key string, httpStatus int) Info {
12+
return Info{
13+
log: log,
14+
key: key,
15+
httpStatus: httpStatus,
16+
}
17+
}
18+
19+
func (i Info) Log(msg string) {
20+
i.log.WithFields(logger.Fields{
21+
"key": i.key,
22+
"http_status": i.httpStatus,
23+
}).Infof(msg)
24+
}

0 commit comments

Comments
 (0)