Compare commits

..

1 Commits
main ... 7/jwt

Author SHA1 Message Date
ajikamaludin 47c924e0bb
update readme 2 years ago

@ -1,43 +1,25 @@
# GO GRPC BASIC
## Requirements
### `Check other branch to step by step create project from 1/dev, 2/grpc-gateway, etc`
check other branch to step by step create project
### Validate Go Installation
```bash
$ go version
go version go1.18.3 linux/amd64
```
### Add GOPATH
add/edit to your ~/.bashrc or ~/.zshrc file
```bash
export GOPATH=/home/{your-user?}/go
```
dont forget to execute,
to reload bash
```bash
source ~/.bashrc
```
to reload zsh
```bash
source ~/.zshrc
```
### Validate GOPATH
```bash
$ echo $GOPATH
/home/aji/go
echo $GOPATH
```
### Start Project in Go
```bash
$ cd $GOPATH/src
$ mkdir -p github.com/ajikamaludin/go-grpc_basic
$ cd github.com/ajikamaludin/go-grpc_basic
$ go mod init github.com/ajikamaludin/go-grpc_basic
$ go mod tidy
cd $GOPATH/src
mkdir -p github.com/ajikamaludin/go-grpc_basic
cd github.com/ajikamaludin/go-grpc_basic
go mod init github.com/ajikamaludin/go-grpc_basic
go mod tidy
```
### Install Protoc
@ -66,14 +48,14 @@ go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@latest
```
### Add PATH
add/edit to your ~/.bashrc or ~/.zshrc file
add to your ~/.bashrc or ~/.zshrc file
```bash
export PATH="$PATH:$GOPATH/bin"
```
### Validate Protoc Dependency Golang Installation
```bash
~ ls $GOPATH/bin
dlv gopls protoc-gen-go protoc-gen-grpc-gateway
dlv gopls protoc-gen-go protoc-gen-grpc-gateway revel
go-outline grpcurl protoc-gen-go-grpc protoc-gen-swagger
```
@ -225,28 +207,11 @@ runtime.HTTPError = errors.CustomHTTPError
### Jwt ( Json Web Tokens ) Auth
- add jwt configs to `config.yaml`, jwt: issuer: ajikamaludin, key: P@ssw0rd, type: Bearer
- changes `pkg/v1/config/config.go` add new config struct and validate config, **[UPDATE]** change New to GetInstance for singleton config
```go
var lock = &sync.Mutex{}
var config *Config
func GetInstance() (*Config, error) {
if config == nil {
lock.Lock()
defer lock.Unlock()
config, err := New()
if err != nil {
return nil, err
}
return config, nil
}
return config, nil
}
```
- changes `pkg/v1/config/config.go` add new config struct and validate config, [UPDATE] change New to GetInstance for singleton config
- changes `pkg/v1/utils/constants/constants.go` to add new const for jwt token expired and refresh token expired
- `go get github.com/dgrijalva/jwt-go`, lib to handle jwt token in go
- create new pkg `pkg/v1/jwt/jwt.go`, implement Generate token and Claim token
- create new proto `proto/v1/auth/auth.proto` auth for login and register service, recompile `sh compile-proto.sh` **[UPDATE]**
- create new proto `proto/v1/auth/auth.proto` auth for login and register service, recompile `sh compile-proto.sh` [UPDATE]
- implement `api/v1/auth/auth.go`, `api/v1/auth/login.go` and `api/v1/auth/register.go`
- register new grpc service to grpc server
```go

@ -46,7 +46,7 @@ func GetInstance() (*Config, error) {
if config == nil {
lock.Lock()
defer lock.Unlock()
config, err := New()
config, err := new()
if err != nil {
return nil, err
}
@ -55,7 +55,7 @@ func GetInstance() (*Config, error) {
return config, nil
}
func New() (*Config, error) {
func new() (*Config, error) {
cfgPath, err := parseFlag()
if err != nil {
log.Fatal(err)

Loading…
Cancel
Save