Skip to content
FreeSWITCH socket client written in go (http://golang.org)
Branch: master
Clone or download
CodeLingoBot and danbogos Fix function comments based on best practices from Effective Go
Signed-off-by: CodeLingo Bot <bot@codelingo.io>
Latest commit 880b6b2 Mar 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml Added support for bgapi Jan 29, 2019
LICENSE Update LICENSE Sep 4, 2016
README.md README updated Jul 4, 2017
fsock.go Fix function comments based on best practices from Effective Go Mar 15, 2019
fsock_it_test.go
fsock_test.go Added integration tests Jan 29, 2019
test_data.txt
utils.go Added more tests Jan 29, 2019
utils_test.go Added integration tests Jan 29, 2019

README.md

FreeSWITCH socket client written in Go

Installation

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\n",eventMap, connId)
}

// Formats the event as map and prints it out
func printChannelAnswer( eventStr, connId string) {
    // Format the event from string into Go's map type
    eventMap := fsock.FSEventStrToMap(eventStr, []string{})
    fmt.Printf("%v, connId: %s\n",eventMap, connId)
}

// Formats the event as map and prints it out
func printChannelHangup( eventStr, connId string) {
    // Format the event from string into Go's map type
    eventMap := fsock.FSEventStrToMap(eventStr, []string{})
    fmt.Printf("%v, connId: %s\n",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
    }

    // Filters
    evFilters := make(map[string][]string)
    evFilters["Event-Name"] = append(evFilters["Event-Name"], "CHANNEL_ANSWER")
    evFilters["Event-Name"] = append(evFilters["Event-Name"], "CHANNEL_HANGUP_COMPLETE")

    // We are interested in heartbeats, channel_answer, channel_hangup define handler for them
    evHandlers := map[string][]func(string, string){
	    "HEARTBEAT":               {printHeartbeat},
	    "CHANNEL_ANSWER":          {printChannelAnswer},
	    "CHANNEL_HANGUP_COMPLETE": {printChannelHangup},
    }

    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()
}

Build Status

You can’t perform that action at this time.