MCPcopy Create free account
hub / github.com/gogs/gogs / Assign

Function Assign

internal/form/form.go:40–62  ·  view source on GitHub ↗

Assign assign form values back to the template data.

(form any, data map[string]any)

Source from the content-addressed store, hash-verified

38
39// Assign assign form values back to the template data.
40func Assign(form any, data map[string]any) {
41 typ := reflect.TypeOf(form)
42 val := reflect.ValueOf(form)
43
44 if typ.Kind() == reflect.Pointer {
45 typ = typ.Elem()
46 val = val.Elem()
47 }
48
49 for i := 0; i < typ.NumField(); i++ {
50 field := typ.Field(i)
51
52 fieldName := field.Tag.Get("form")
53 // Allow ignored fields in the struct
54 if fieldName == "-" {
55 continue
56 } else if fieldName == "" {
57 fieldName = com.ToSnakeCase(field.Name)
58 }
59
60 data[fieldName] = val.Field(i).Interface()
61 }
62}
63
64func getRuleBody(field reflect.StructField, prefix string) string {
65 for _, rule := range strings.Split(field.Tag.Get("binding"), ";") {

Callers 4

RenderWithErrMethod · 0.92
InstallFunction · 0.92
validateFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected