mirror of
https://github.com/micromdm/micromdm/
synced 2026-06-25 15:35:46 +08:00
When calling frontend.Fail pass the form data in the context. In case of an error, returns the values back so they're not reset on the page.
20 lines
315 B
Go
20 lines
315 B
Go
package frontend
|
|
|
|
import "context"
|
|
|
|
type key int
|
|
|
|
const dataKey key = 0
|
|
|
|
func AddFormData(ctx context.Context, data Data) context.Context {
|
|
return context.WithValue(ctx, dataKey, data)
|
|
}
|
|
|
|
func dataFromContext(ctx context.Context) Data {
|
|
v, ok := ctx.Value(dataKey).(Data)
|
|
if !ok {
|
|
return Data{}
|
|
}
|
|
return v
|
|
}
|