|
|
@ -1,6 +1,7 @@
|
|
|
|
# GO GRPC BASIC
|
|
|
|
# GO GRPC BASIC
|
|
|
|
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
check other branch to step by step create project
|
|
|
|
### Validate Go Installation
|
|
|
|
### Validate Go Installation
|
|
|
|
```bash
|
|
|
|
```bash
|
|
|
|
$ go version
|
|
|
|
$ go version
|
|
|
@ -62,6 +63,7 @@ go-outline grpcurl protoc-gen-go-grpc protoc-gen-swagger
|
|
|
|
### Setup Project
|
|
|
|
### Setup Project
|
|
|
|
- create `proto` dir
|
|
|
|
- create `proto` dir
|
|
|
|
- create versioning dir and service dir `health`
|
|
|
|
- create versioning dir and service dir `health`
|
|
|
|
|
|
|
|
- exec `get-lib.sh` in `proto` dir to download / get important library to use by `health.proto` usage is in compile proto file
|
|
|
|
- create proto file `health.proto`
|
|
|
|
- create proto file `health.proto`
|
|
|
|
- compile / generate proto with `compile-proto.sh` in proto dir
|
|
|
|
- compile / generate proto with `compile-proto.sh` in proto dir
|
|
|
|
|
|
|
|
|
|
|
@ -114,7 +116,7 @@ service HealthService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
- re - compile / re - generate proto with `compile-proto.sh` in proto dir
|
|
|
|
- re - compile / re - generate proto with execute `compile-proto.sh` in proto dir
|
|
|
|
- `go mod tidy`
|
|
|
|
- `go mod tidy`
|
|
|
|
- `go get "github.com/gorilla/handlers"` TODO: what is for ?
|
|
|
|
- `go get "github.com/gorilla/handlers"` TODO: what is for ?
|
|
|
|
- create `http.go` in router dir and implement NewHTTPServer and register health api service
|
|
|
|
- create `http.go` in router dir and implement NewHTTPServer and register health api service
|
|
|
@ -175,7 +177,7 @@ import (
|
|
|
|
- create `pkg/v1/utils/converter` dir, create `converter.go` file in there, to convert camelcase to snake_case
|
|
|
|
- create `pkg/v1/utils/converter` dir, create `converter.go` file in there, to convert camelcase to snake_case
|
|
|
|
- create `pkg/v1/postgres/custom.main.go` to implement all query to database table custom
|
|
|
|
- create `pkg/v1/postgres/custom.main.go` to implement all query to database table custom
|
|
|
|
- changes `configs/configs.go` to bundle pg connection
|
|
|
|
- changes `configs/configs.go` to bundle pg connection
|
|
|
|
- how to use custom.main.go call function from custom main in api status, check `api/v1/health/status.go`
|
|
|
|
- how to use custom.main.go call function from api calldb, check `api/v1/health/calldb.go`
|
|
|
|
|
|
|
|
|
|
|
|
### Example of call Other Rest API
|
|
|
|
### Example of call Other Rest API
|
|
|
|
- add new environtment to `config.yaml` add cert path
|
|
|
|
- add new environtment to `config.yaml` add cert path
|
|
|
@ -184,4 +186,11 @@ import (
|
|
|
|
- create `pkg/v1/cert` dir, create `cert.go`, this file is for handle Insecure ssl connection (self gen cert)
|
|
|
|
- create `pkg/v1/cert` dir, create `cert.go`, this file is for handle Insecure ssl connection (self gen cert)
|
|
|
|
- create `pkg/v1/requestapi` dir, create `requestapi.go`, implement http call
|
|
|
|
- create `pkg/v1/requestapi` dir, create `requestapi.go`, implement http call
|
|
|
|
- create `services/v1/jsonplaceholder` dir, create service name `jsonplaceholder.go`, implement any of endpoint http call from requestapi.go
|
|
|
|
- create `services/v1/jsonplaceholder` dir, create service name `jsonplaceholder.go`, implement any of endpoint http call from requestapi.go
|
|
|
|
- create new method from service health and implement call jsonplaceholder service from there ex: `api/v1/health/callapi.go`
|
|
|
|
- create new method from service health and implement call jsonplaceholder service from there, check `api/v1/health/callapi.go`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### HTTP Custom Error Reponse
|
|
|
|
|
|
|
|
- create `pgk/v1/utils/errors/errors.go`, implement error handler for custom http
|
|
|
|
|
|
|
|
- register runtime Http error in `http.go`
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
|
|
|
runtime.HTTPError = errors.CustomHTTPError
|
|
|
|
|
|
|
|
```
|
|
|
|