Giter Site home page Giter Site logo

webchat's Introduction

Webchat

Ini adalah repositori pembuatan web chat sederhana dengan golang Rest & Websocket

Tabel Konten

Tech

Menggunakan Golang dan json file sebagai penyimpanan pesan - pesan lama

API

PULL API

Menggunakan REST third party pada golang bila belum terinstall silahkan gunakan

$ go get github.com/gorilla/mux

1. API to send message

post-api

Rest handler post

r := mux.NewRouter()
r.HandleFunc("/message", allMessage).Methods("POST")

Param akan di validasi dulu dan bila berhasil akan di masukkan ke dalam json file dan bila sukses akan seperti ini

post-api

2. API to retrieve messages

get-api

Rest handler get

r := mux.NewRouter()
r.HandleFunc("/message", allMessage).Methods("GET")

Semua chat yang lama akan di ambil dari allMessage.json
post-api

PUSH API

Menggunakan Websocket third party pada golang bila belum terinstall silahkan gunakan

$ $ go get github.com/gorilla/websocket

3. API to retrieve message at realtime

get-api

akses home akan masuk ke dalam template dengan tampilan chat sederhana

fs := http.FileServer(http.Dir("./public"))
	r.Handle("/", fs)

lalu pesan akan dikirim ke websocket /ws oleh javascript dan di proses oleh handleConnection function

r.HandleFunc("/ws", handleConnections)

dan terakhir buat goroutine untuk memproses pesan chat yang masuk

go handleMessages()

get-api

TroubleShoot

Menjalankan Golang Listener

$ go run main.go

Setting Path Untuk JSON FILE DB

var path = "./Allmessage.json" -- path untuk penyimpanan db

Author

Florentinus Oktavian : [email protected].

License

webchat's People

Stargazers

Florentinus Oktavian avatar

Watchers

James Cloos avatar Florentinus Oktavian 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.