while trying to send sms code it is not working but when i put the url in browser the status is success. while i m integrating it with my app it is not working and i am using postgresql to access the details.
package controllers
import (
"io/ioutil"
"log"
"net/http"
"github.com/go-gorp/gorp"
_ "github.com/go-sql-driver/mysql"
//"github.com/streetcom/app/log"
)
var (
Dbm *gorp.DbMap
)
func Sendsms(msg string) {
rows, err := Dbm.Query("Select mobile_number from alert WHERE name=$1 AND email=$2 AND mobile_number=$3")
defer rows.Close()
if err != nil {
log.Println(err.Error())
} else {
for rows.Next() {
var mobile_number string
err = rows.Scan(&mobile_number)
if err != nil {
log.Println(err.Error())
} else {
response, err := http.Get("https://api.textlocal.in/send/?apikey=redacted&sender=TXTLCL&numbers=" + mobile_number + "&message=" + msg)
if err != nil {
log.Println(err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Println(err)
} else {
log.Printf("%s
", string(contents))
}
}
}
}
}
}
This is a very vague question, and in computing precision matters. WHAT doesn't work? Did you try debugging your code in any way? You will need to learn how to test and debug code or programming will be very frustrating for you.
In this case, if that is the code you are actually running then the problem looks to be with your query. I know nothing of gorp
but you have a query with three parameters there and aren't providing any of them. I don't see how you can get any rows returned from that. It may be you need a separate "Execute" call or some such - check the documentation. If you don't get any rows then the message sending loop will never do anything.