package handlers const ( // archiveExpiryNever is the archive expiry that keeps archived // events forever. A stored empty expiry means the same. archiveExpiryNever = "never" // tmplKeyArchiveExpiryChoices is the template data key for the // entries of a page's archive expiry select. tmplKeyArchiveExpiryChoices = "ArchiveExpiryChoices" ) // archiveChoice is one entry of a database target's archive expiry // or archive rotation select: the value stored, the label shown, and // whether the select starts on it. type archiveChoice struct { Value string Label string Selected bool } // archiveExpiryChoices lists the archive expiries offered by the new // webhook page, the add target form and the target edit form. func archiveExpiryChoices() []archiveChoice { return []archiveChoice{ {Value: archiveExpiryNever, Label: archiveExpiryNever}, {Value: "1h", Label: "1h"}, {Value: "12h", Label: "12h"}, {Value: "24h", Label: "24h"}, {Value: "720h", Label: "30d"}, {Value: "2160h", Label: "90d"}, {Value: "8760h", Label: "365d"}, } } // archiveExpiryOptions returns the choices with expiry selected; an // empty expiry selects never. An expiry that is not one of the // choices comes first as its own selected entry, so saving the form // unchanged keeps it. func archiveExpiryOptions(expiry string) []archiveChoice { if expiry == "" { expiry = archiveExpiryNever } options := archiveExpiryChoices() for i := range options { if options[i].Value == expiry { options[i].Selected = true return options } } own := archiveChoice{Value: expiry, Label: expiry, Selected: true} return append([]archiveChoice{own}, options...) }