tsk-13: Retrieve scheduled message endpoint (#36)
Closes #13 Reviewed-on: phoenix/textsender-api#36 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package handler
|
||||
|
||||
import "encoding/json"
|
||||
import "log"
|
||||
import "net/http"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ExtractFromRequest(r *http.Request, reqItem interface{}) error {
|
||||
err := json.NewDecoder(r.Body).Decode(&reqItem)
|
||||
@@ -21,3 +24,18 @@ func RespondWithJSON(w http.ResponseWriter, statusCode int, data interface{}) {
|
||||
log.Printf("Error encoding JSON: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the query parameter from the URL
|
||||
func ParseQueryParams(r *http.Request, query string) (*string, error) {
|
||||
queryParams := r.URL.Query()
|
||||
if _, exists := queryParams[query]; exists {
|
||||
value := queryParams.Get(query)
|
||||
if len(value) == 0 {
|
||||
return nil, fmt.Errorf("Value of query parameter is empty")
|
||||
} else {
|
||||
return &value, nil
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("Could not find query %s", query)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user