我制作了Restful api,我想要显示结果,但是golang说关于函数的错误,错误说“ undefined:returnAllSMSBlasts”为什么,您可以检查我的代码错误吗?
这是我的代码
data.go
package main
import (
"encoding/json"
"log"
"net/http"
)
func returnAllSMSBlasts(w http.ResponseWriter, r *http.Request) {
var smsblasts SMSBlasts
var arr_smsblast []SMSBlasts
var response Response
db := connect()
defer db.Close()
rows, err := db.Query("Select SequenceID,MobilePhone,Output,WillBeSentDate,SentDate,Status,DtmUpd")
if err != nil{
log.Print(err)
}
for rows.Next(){
if err := rows.Scan(&smsblasts.SequenceID, &smsblasts.MobilePhone,
&smsblasts.Output, &smsblasts.WillBeSentDate,
&smsblasts.SentDate, &smsblasts.Status,
&smsblasts.DtmUpd); err != nil{
log.Fatal(err.Error())
}else{
arr_smsblast = append(arr_smsblast , smsblasts)
}
}
response.Status = 1
response.Message = "success"
response.Data = arr_smsblast
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}
这是我的代码
main.go
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
_ "github.com/denisenkom/go-mssqldb"
)
func main() {
router := mux.NewRouter()
router.HandleFunc("/postsmsblasts", returnAllSMSBlasts).Methods("POST")
http.Handle("/", router)
fmt.Println("Connected to port 1234")
log.Fatal(http.ListenAndServe(":1234", router))
}