Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

6/24/2020

Reading time:N/A min

bygui86/go-cassandra

by John Doe

InstructionsPrepare environmentcd $GOPATH/src/github.comgit clone git@github.com:bygui86/go-cassandra.gitcd bygui86/go-cassandrago get ./...Run cassandradocker run -d --name cassandra -p 7199:7199 -p 7000:7000 -p 7001:7001 -p 9160:9160 -p 9042:9042 cassandraCreate Cassandra keyspace and tableOpen 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) );Run applicationcd $GOPATH/src/github.com/bygui86/go-cassandrago run main.goTest some REST calls (see endpoints list below)REST endpointsGET 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 uuidPLEASE NOTE: See the postman collection for samples of the user JSON structureLinksTutorial

Illustration Image

Instructions

  1. Prepare environment

    cd $GOPATH/src/github.com
    git clone git@github.com:bygui86/go-cassandra.git
    cd bygui86/go-cassandra
    go get ./...
    
  2. Run cassandra

    docker run -d --name cassandra -p 7199:7199 -p 7000:7000 -p 7001:7001 -p 9160:9160 -p 9042:9042 cassandra
    
  3. Create Cassandra keyspace and table

    1. Open CQL connection
       docker exec -it cassandra cqlsh $(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cassandra)
      
    2. Create Cassandra keyspace
       CREATE KEYSPACE golang WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};
      
    3. Create Cassandra table
       USE golang;
       CREATE TABLE users ( id UUID, firstname text, lastname text, age int, email text, city text, PRIMARY KEY (id) );
      
  4. Run application

    cd $GOPATH/src/github.com/bygui86/go-cassandra
    go run main.go
    
  5. Test some REST calls (see endpoints list below)


REST endpoints

  • GET http://localhost:8080/ heart beat
  • POST http://localhost:8080/users/new insert new user
  • GET http://localhost:8080/users get all users
  • GET http://localhost:8080/users/{uuid} get user by uuid

PLEASE NOTE: See the postman collection for samples of the user JSON structure


Links

Related Articles

spring
angular
rest

GitHub - jhipster/jhipster-sample-app-cassandra: This is a sample application created with JHipster, with the Cassandra option

jhipster

3/7/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

go