go-user-store-redis

command module
v0.0.0-...-c298ccb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2018 License: MIT Imports: 9 Imported by: 0

README

Go User Store

This is a user store keeping the application users acting as a gRPC server.

It listens to the port 5300.

alt text

Before all
  • Have Go
  • Have gRPC
  • Have Docker
  • Set Environment variables:
    • USER_STORE_REDIS_URL (used in ./dal/client.go)

installed.

gRPC settings

Everything starts with designing the protobuf file (./proto/user.proto for this project) and once the messages and services are designed (or changed later) the following command should be run:

cd $GOPATH/src/github.com/vahdet/go-user-store
protoc -I proto proto/user.proto --go_out=plugins=grpc:proto

This command will generate (or recreate if it exists) a .pb.go file just beside itself. It is ./proto/user.pb.go here and it allows implementing Go services, repositories, in short any Go code behind the services defined in the .proto file.

For this case, the server implementation is performed in ./grpcserver/server.go file.

Datastore
Redis in a container

A Redis instance should be up at the port defined in the config file ./resources/app.yaml. Unless the port is changed, the default one is 6379 on localhost

A sample Docker command to install an official Redis image (with data persistence to disk) is as follows:

docker container run -d --name redisTest \
-v /opt/docker/data/redis:/data \
-p 6379:6379
redis:latest
  • See all running containers
docker ps
  • See all containers (running or not)
docker ps -a
  • Remove Docker image (although it is a bad practice, add -f force remove) with a few characters of the CONTAINER_ID which you can find the one assigned to your container with the ps commands above.
docker rm 
  • Bonus: Delete stopped containers
docker rm -v $(docker ps -a -q -f status=exited)
Security

Set a user/pass for the redis container.

Testing

In this app, data store testing is adopts the approach that a separate redis docker container is created for test usage. However, there are other ways worth trying:

or, if you dare to code through another API anyway:

Docker
Build

See the ./Dockerfile

Run the following command in the root directory in order to build as specified in the Dockerfile

docker image build -t go-user-store .

This will create an image named go-user-store locally.

You can check the docker images by the command and check go-user-store is listed:

docker image ls
Run

To run a container out of the image, run the following command

docker container run --publish 5300:5300 --name my-goddamn-user-store --rm outyet

It binds the internal port 5300 to external port 5300. Change the one before colon if you want to expose the container through a different port.

Push to Docker Hub

See Pushing and Pulling to and from Docker Hub

Data Persistence

A volume is assigned to redis container by -v flag (see previous sections).

There is currently no need for a volume or bind mount for the go code.

Git Tips for humble beings

The StackOverflow answer resembles three lines of general purpose git commands that can be used anytime a change is made and should be committed to master branch:

git add .
git commit -a -m "My classical message to be replaced"
git push

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
app
dal
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL