Ini adalah repositori pembuatan web chat sederhana dengan golang Rest & Websocket
Menggunakan Golang dan json file sebagai penyimpanan pesan - pesan lama
Menggunakan REST third party pada golang bila belum terinstall silahkan gunakan
$ go get github.com/gorilla/mux
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
Rest handler get
r := mux.NewRouter()
r.HandleFunc("/message", allMessage).Methods("GET")
Semua chat yang lama akan di ambil dari allMessage.json
Menggunakan Websocket third party pada golang bila belum terinstall silahkan gunakan
$ $ go get github.com/gorilla/websocket
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()
$ go run main.go
var path = "./Allmessage.json" -- path untuk penyimpanan db
Florentinus Oktavian : [email protected].