Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Now-a-days, Go language is the good choice for web programming, web APIs, micro-services, and other distributed services because of its performance and reliability.

In this Article, you will learn how to integrate sms functionality with go programming language or how to send sms using golang from spring edge sms gateway APIs.

Requirements:

  • Basic knowledge of Go language.
  • Account/Auth-key from Spring Edge SMS Gateway.
  • Sender Name provided by sms provider.
  • A Working envournment to run Go Language.

To start with golang sms integration, we will create a package. In Go programming language every thing is divided into packages only. Go has only structs instead of classes.

package main

Now import http, url and other required packages.

import (
"net/http"
"net/url"
"fmt"
"strings"
)

Once imported packages we will write function to integrate sms functionality and define related variables like sms gateway url, auth key and sender name for our message.

func main() {
gatewayURL := "http://trans.springedge.com"
apikey := "AUTH_API_KEY"
sender := "SEDEMO"
urlStr := gatewayURL + "/api/web/send/"
}

Add params to sms api request like recipent’s mobile number on which you want to deliver sms, sender name which will apear as sender of sms, auth key and sms body.

v := url.Values{}
v.Set("to","919035xxxxxx")
v.Set("apikey",apikey)
v.Set("sender",sender)
v.Set("message","Hello, this is a test sms")
rb := *strings.NewReader(v.Encode())

Generate HTTP api request and send payload along with API request.

client := &http.Client{}
req, _ := http.NewRequest("POST", urlStr, &rb)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, _ := client.Do(req)

Print response which received from SMS API trigger for referance.

fmt.Println(resp)

Go Lang Package to send sms :
An executable Go Language package to send text sms, merge of all above explained code

package main

import (
  "net/http"
  "net/url"
  "fmt"
  "strings"
)

func main() {

  // Set variable values
  gatewayURL := "http://trans.springedge.com"
  apikey := "AUTH_API_KEY"
  sender := "SEDEMO"
  urlStr := gatewayURL + "/api/web/send/"

  // Params
  v := url.Values{}
  v.Set("to","919035xxxxxx")
  v.Set("apikey",apikey)
  v.Set("sender",sender)
  v.Set("message","Hello, this is a test sms")
  rb := *strings.NewReader(v.Encode())

  client := &http.Client{}
  req, _ := http.NewRequest("POST", urlStr, &rb)
  req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

  // Make request
  resp, _ := client.Do(req)

  //print response
  fmt.Println(resp.Status)
}

Conclusion:
To integrate sms functionality with golang, we have create a package which take mobile number, text message body, predefined auth key and sender name. We have used HTTP based API from spring edge sms gateway, used params to call API and send sms.

In above article we got knowledge about how to send sms using golang with sms gateway RestAPI.

Marketing or Promotion is important for business Start-Ups to build a brand image. Marketing will
As business practices adapt, change, and develop over time, new terminology tends to get added