21 lines
377 B
Go
21 lines
377 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
)
|
|
|
|
func (app *application) readIDParam(r *http.Request) (int64, error) {
|
|
params := httprouter.ParamsFromContext(r.Context())
|
|
|
|
id, err := strconv.ParseInt(params.ByName("id"), 10, 64)
|
|
if err != nil || id < 1 {
|
|
return 0, errors.New("invalid id parameter")
|
|
}
|
|
|
|
return id, nil
|
|
}
|