Files
micromdm/pkg/frontend/context.go
Victor Vrantchan ec514fd70e add form data to context
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.
2021-02-20 19:02:45 -05:00

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
}