Instructions
-
Prepare environment
cd $GOPATH/src/github.com git clone git@github.com:bygui86/go-cassandra.git cd bygui86/go-cassandra go get ./...
-
Run cassandra
docker run -d --name cassandra -p 7199:7199 -p 7000:7000 -p 7001:7001 -p 9160:9160 -p 9042:9042 cassandra
-
Create Cassandra keyspace and table
- Open CQL connection
docker exec -it cassandra cqlsh $(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cassandra)
- Create Cassandra keyspace
CREATE KEYSPACE golang WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};
- Create Cassandra table
USE golang; CREATE TABLE users ( id UUID, firstname text, lastname text, age int, email text, city text, PRIMARY KEY (id) );
- Open CQL connection
-
Run application
cd $GOPATH/src/github.com/bygui86/go-cassandra go run main.go
-
Test some REST calls (see endpoints list below)
REST endpoints
GET http://localhost:8080/
heart beatPOST http://localhost:8080/users/new
insert new userGET http://localhost:8080/users
get all usersGET http://localhost:8080/users/{uuid}
get user by uuid
PLEASE NOTE
: See the postman collection for samples of the user JSON structure