Giter Club home page Giter Club logo

sockets-with-go's Introduction

Project

Routes

  1. /publish only supports POST method
{
    "message": "hello buddies",
    "client_id": "surajsarkar",
    "topic": "info"
}
  1. /ws some of examples you can use to test is ⬇️

some of the template actions in websocket

  • For registring client
{
    "message": "",
    "topic": "",
    "client_id": "surajsarkar",
    "action": "register"
}
  • For disconnecting client
{
    "message": "",
    "topic": "",
    "client_id": "surajsarkar",
    "action": "disconnect"
}
  • subscribing to a topic eg: info
{
    "message": "",
    "topic": "info",
    "client_id": "surajsarkar",
    "action": "subscribe"
}
  • unsubscribing from a topic eg: info
{
    "message": "",
    "topic": "info",
    "client_id": "surajsarkar",
    "action": "unsubscribe"
}
  • publishing to a channel
{
    "message": "Hi how are you.",
    "topic": "info",
    "client_id": "surajsarkar",
    "action": "publish"
}
  • Define a interface
type y interface {}; // where y in interface name
  • Define struct
type a struct {} // a is struct name
  • Adding methods to struct
func (x structname) funcname (<input> <inputtype>) <output_type> {
    // code to execute
}
  • condition
if (condition) {
    // code to execute if condition is true
} else if (another_condition){
    // execute if another_condition true
}else {
    // default case
}
  • creating map
map_name := map[<key_dtype>]<val_dtype>{values...}
//eg
score := map[string]int{"Suraj": 100, "Opponent": 1}

Channels

Things to remember

  • Sending on a closed channel will cause a panic

when we use channel what ever comes in channel will not be sequential.

Mutex

  • helps in locking machanism so if you are accessing a value across a routines, to remove conflict we use mutex so a single routine can use the channel at a time.
  • to lock use : sync.Mutex.Lock()
  • to lock use : sync.Mutex.Unlock()

Contex

  • Context type, which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes
  • when we create a context it returns a context object and cancel func, which when called sends a message to context.Done() channel. which tells if the channel was closed.

Things to cover with projects

  • context

some important points

//assigning pointer of a var to another var
i := 5
p := &i

// here p gets the value of i's memory address

To create a slice dinamically sized array

slice := make([]int, 7) // dtype, length, capacity (optional)
//append to slice 
append(slice, element_to_append)

Then we will start building project

sockets-with-go's People

Contributors

surajsarkar avatar

Watchers

 avatar

Forkers

surajl2w

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.