/publish
only supportsPOST
method
{
"message": "hello buddies",
"client_id": "surajsarkar",
"topic": "info"
}
/ws
some of examples you can use to test is ⬇️
- 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}
- Sending on a closed channel will cause a panic
when we use channel what ever comes in channel will not be sequential.
- 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()
- 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 tocontext.Done()
channel. which tells if the channel was closed.
- 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