12345678910111213141516171819202122232425262728293031323334353637 |
- package main
-
- import (
- "fmt"
- "io"
- "log"
- "net/http"
- )
-
- const _addr string = ":8081"
-
- func smsHandler(w http.ResponseWriter, r *http.Request) {
- if err := authHeader(r); err != nil {
- http.Error(w, err.Error()+"\n访问 /help 查看使用帮助", http.StatusInternalServerError)
- return
- }
-
- defer r.Body.Close()
- body, err := io.ReadAll(r.Body)
- if err != nil {
- http.Error(w, err.Error()+"\n访问 /help 查看使用帮助", http.StatusInternalServerError)
- return
- }
-
- if err := SendSMS(&body); err != nil {
- http.Error(w, err.Error()+"\n访问 /help 查看使用帮助", http.StatusInternalServerError)
- return
- }
-
- fmt.Fprintf(w, "success")
- }
-
- func main() {
- http.HandleFunc("/sms", smsHandler)
- http.HandleFunc("/help", helpHandler)
- log.Fatal(http.ListenAndServe(_addr, nil))
- }
|