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 # GO GRPC BASIC
## Requirements ## 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 ### Validate Go Installation
```bash ```bash
$ go version $ go version
go version go1.18.3 linux/amd64 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 ### Validate GOPATH
```bash ```bash
$ echo $GOPATH echo $GOPATH
/home/aji/go
``` ```
### Start Project in Go ### Start Project in Go
```bash ```bash
$ cd $GOPATH/src cd $GOPATH/src
$ mkdir -p github.com/ajikamaludin/go-grpc_basic mkdir -p github.com/ajikamaludin/go-grpc_basic
$ cd github.com/ajikamaludin/go-grpc_basic cd github.com/ajikamaludin/go-grpc_basic
$ go mod init github.com/ajikamaludin/go-grpc_basic go mod init github.com/ajikamaludin/go-grpc_basic
$ go mod tidy go mod tidy
``` ```
### Install Protoc ### Install Protoc
@ -66,14 +48,14 @@ go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@latest
``` ```
### Add PATH ### Add PATH
add/edit to your ~/.bashrc or ~/.zshrc file add to your ~/.bashrc or ~/.zshrc file
```bash ```bash
export PATH="$PATH:$GOPATH/bin" export PATH="$PATH:$GOPATH/bin"
``` ```
### Validate Protoc Dependency Golang Installation ### Validate Protoc Dependency Golang Installation
```bash ```bash
~ ls $GOPATH/bin ~ 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 go-outline grpcurl protoc-gen-go-grpc protoc-gen-swagger
``` ```
@ -225,28 +207,11 @@ runtime.HTTPError = errors.CustomHTTPError
### Jwt ( Json Web Tokens ) Auth ### Jwt ( Json Web Tokens ) Auth
- add jwt configs to `config.yaml`, jwt: issuer: ajikamaludin, key: P@ssw0rd, type: Bearer - 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 - 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/utils/constants/constants.go` to add new const for jwt token expired and refresh token expired - 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 - `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 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` - implement `api/v1/auth/auth.go`, `api/v1/auth/login.go` and `api/v1/auth/register.go`
- register new grpc service to grpc server - register new grpc service to grpc server
```go ```go

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

Loading…
Cancel
Save