Go#
FreeSWITCH socket client written inInstallation
go get github.com/cgrates/fsock
Support
Join CGRateS on Google Groups here.
License
fsock.go is released under the MIT License. Copyright (C) ITsysCOM GmbH. All Rights Reserved.
Sample usage code
package main
import (
"github.com/cgrates/fsock"
"log/syslog"
"fmt"
)
// Formats the event as map and prints it out
func printHeartbeat( eventStr, connId string ) {
// Format the event from string into Go's map type
eventMap := fsock.FSEventStrToMap(eventStr, []string{})
fmt.Printf("%v, connId: %s",eventMap, connId)
}
func main() {
// Init a syslog writter for our test
l,errLog := syslog.New(syslog.LOG_INFO, "TestFSock")
if errLog!=nil {
l.Crit(fmt.Sprintf("Cannot connect to syslog:", errLog))
return
}
// No filters
evFilters := map[string]string{}
// We are interested in heartbeats, define handler for them
evHandlers := map[string][]func(string, string){"HEARTBEAT": []func(string, string){printHeartbeat}}
fs, err := fsock.NewFSock("127.0.0.1:8021", "ClueCon", 10, evHandlers, evFilters, l, "wetsfnmretiewrtpj")
if err != nil {
l.Crit(fmt.Sprintf("FreeSWITCH error:", err))
return
}
fs.ReadEvents()
}