1
0

fmt + lint + docs

This commit is contained in:
konrad
2018-07-21 15:28:09 +02:00
committed by kolaente
parent 9979b7e321
commit 0487889963
5 changed files with 21 additions and 9 deletions

View File

@ -10,6 +10,18 @@ import (
const paramTagName = "param"
/////////////////////////
// HOW THIS BINDER WORKS
/////////////////////////
// This binder binds all values inside the url to their respective fields in a struct. Those fields need to have a tag
// "param" with the name of the url placeholder which must be the same as in routes.
//
// Whenever one of the standard CRUD methods is invoked, this binder is called, which enables one handler method
// to handle all kinds of different urls with different parameters.
/////////////////////////
// ParamBinder binds parameters to a struct.
// Currently a working implementation, waiting to implement this officially into echo.
func ParamBinder(i interface{}, c echo.Context) (err error) {
// Default binder
@ -77,9 +89,7 @@ func ParamBinder(i interface{}, c echo.Context) (err error) {
return
}
// This is kind of ugly, more a "feature proof", copied from the echo source code.
// Workaround until the pr to implement this nativly in echo is merged.
// Binder represents a binder
type Binder struct{}
func (b *Binder) bindData(ptr interface{}, data map[string][]string, tag string) error {
@ -227,6 +237,7 @@ func setFloatField(value string, bitSize int, field reflect.Value) error {
return err
}
// BindUnmarshaler type
type BindUnmarshaler interface {
// UnmarshalParam decodes and assigns a value from an form or query param.
UnmarshalParam(param string) error

View File

@ -1,10 +1,10 @@
package crud
import (
"fmt"
"git.kolaente.de/konrad/list/models"
"github.com/labstack/echo"
"net/http"
"fmt"
)
// ReadOneWeb is the webhandler to get one object