fix bug
This commit is contained in:
parent
d24f7efb0b
commit
2c5c83578c
|
@ -60,7 +60,7 @@ __end:
|
|||
break
|
||||
}
|
||||
}
|
||||
return ipaddr
|
||||
return strings.TrimSpace(ipaddr)
|
||||
}
|
||||
|
||||
func (ctx *Context) Request() *http.Request {
|
||||
|
@ -120,7 +120,7 @@ func (ctx *Context) Error(code int, reason string) (err error) {
|
|||
|
||||
func (ctx *Context) Redirect(url string, code int) {
|
||||
if code != http.StatusFound && code != http.StatusMovedPermanently {
|
||||
code = http.StatusMovedPermanently
|
||||
code = http.StatusFound
|
||||
}
|
||||
http.Redirect(ctx.Response(), ctx.Request(), url, code)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package reflection
|
|||
|
||||
import "git.nspix.com/golang/kos/util/reflect"
|
||||
|
||||
func Setter(hacky any, variables map[string]any) (err error) {
|
||||
func Setter[T string | int | int64 | float64 | any](hacky any, variables map[string]T) (err error) {
|
||||
for k, v := range variables {
|
||||
if err = Set(hacky, k, v); err != nil {
|
||||
return err
|
||||
|
@ -11,6 +11,6 @@ func Setter(hacky any, variables map[string]any) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func Set(hacky any, field string, value interface{}) (err error) {
|
||||
func Set(hacky any, field string, value any) (err error) {
|
||||
return reflect.Set(hacky, field, value)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package reflection
|
||||
|
||||
import "testing"
|
||||
|
||||
type fake struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
|
||||
func TestSetter(t *testing.T) {
|
||||
dst := &fake{}
|
||||
ms := map[string]string{"name": "aa", "age": "5"}
|
||||
Setter(dst, ms)
|
||||
if dst.Age != 5 {
|
||||
t.Errorf("setter failed")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue