feat: xsrf_token set
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m9s
Build and Deploy Go App / deploy (push) Successful in 34s

This commit is contained in:
nihonium 2025-12-04 06:29:20 +03:00
parent 31e55c0539
commit b79a6b9117
Signed by: nihonium
GPG key ID: 0251623741027CFC
5 changed files with 117 additions and 20 deletions

33
modules/auth/helpers.go Normal file
View file

@ -0,0 +1,33 @@
package main
import (
"fmt"
"reflect"
)
func setField(obj interface{}, name string, value interface{}) error {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct {
return fmt.Errorf("expected pointer to a struct")
}
v = v.Elem()
field := v.FieldByName(name)
if !field.IsValid() {
return fmt.Errorf("no such field: %s", name)
}
if !field.CanSet() {
return fmt.Errorf("cannot set field: %s", name)
}
val := reflect.ValueOf(value)
if field.Type() != val.Type() {
return fmt.Errorf("provided value type (%s) doesn't match field type (%s)", val.Type(), field.Type())
}
field.Set(val)
return nil
}