Giter VIP home page Giter VIP logo

golang_chat_example's Introduction

golang_chat_example

This is an example of a realtime chat application using Go and websockets.

Configuration Files

The Godeps folder contains dependency management files for deploying to Heroku.

Procfile is a configuration file for deploying to Herkou.

If you deploy to Google App Engine you'll have to add an app.yaml file and delete the aforementioned config files.

The .project file enables you to open this project in Eclipse ( make sure you have the Goclipse plugin ). Otherwise, it's yet another config file. You can delete it if you'd like.

Run Locally - Terminal

  1. Have Go installed: https://golang.org

  2. Set the GOPATH environment variable to the root directory of this project. Of course if you have other GOPATH routes just add

;C:\Users\YourName\Desktop\golang_chat_example

to the end of the value. Of course this is if you clone this repository to your Desktop :)

  1. Open git bash terminal and change directory to be root of the project
cd Desktop/golang_chat_example
  1. In the same terminal enter the command:
go run src/server/server.go

The application should be running and listening to port 8081

If you are deploying the application, change the websocket address/port in the html/client.html file.

Deploy - Heroku

  1. Have a heroku account (don't worry, it's free for your first few applications): https://heroku.com/

  2. If this is your firt time using Heroku, get the toolbelt: https://toolbelt.heroku.com/ and after installation, open the git bash terminal and enter the following commands:

heroku login

Enter your information and continue to the next step.

  1. Enter the following commands while in the root directory of the project:
git init
git add -A .
git commit -m "initial commit"
heroku create -b https://github.com/kr/heroku-buildpack-go.git

After the last line completes, an application name should be provided. It may look like something funky.. As you can see from the html/client.html file, the pubAddr variable is set to application_name.herokuapp.com where application_name was tranquil-gorge-4724 in my case.

  1. Take the application name given to you and change the pubAddr variable in html/client.html and comment out and replace the addr variable.
// var addr = "localhost:8081"
var pubAddr = "application_name.herokuapp.com"

var conn = new Websocket("wss://" +  pubAddr + "/ws");
  1. In the html/client.html file there is a section of code that's commented out.. Go ahead and uncomment that.

  2. Finally deploy!! In the git bash terminal enter the following commands:

git add -A .
git commit -m "changed websocket address"
git push heroku master

To open, just go to the URL provided -or- enter the command:

heroku open

Enjoy!

golang_chat_example's People

Contributors

piusnyakoojo avatar

Stargazers

双子三生 avatar

Watchers

James Cloos avatar 双子三生 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.