Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeForm(dst interface{}, src map[string][]string) error
- func EditPeriodDetailsHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, ...) error
- func ExecSecure(f HandleFunc, ctx context.Context, requestContext *RequestContext, ...) (err error)
- func GetDefaultFuncMap() template.FuncMap
- func GetMongoURI(username, password, host string, port int) string
- func GetVotersFormFieldConverter(parser *gopolls.VotersParser) schema.Converter
- func HomeHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, ...) error
- func NewPeriodHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, ...) error
- func NewSchemaDecoder() *schema.Decoder
- func PeriodDetailsHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, ...) error
- func RunServerMongo(config *AppConfig, templateRoot, host string, port int, debug bool)
- func ShowPeriodSettingsListHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, ...) error
- type AppConfig
- type AppContext
- type CustomFormValidator
- type DateFormField
- type DateTimeFormField
- type Error
- type FormDecoder
- type FormValidationError
- type HandleFunc
- type Handler
- type HandlerError
- type HourMinuteFormField
- type LimitsConfig
- type LocalizationConfig
- type MongoConfig
- type PeriodForm
- type RequestContext
- func (requestContext *RequestContext) FormatDate(t time.Time) string
- func (requestContext *RequestContext) FormatDateTime(t time.Time) string
- func (requestContext *RequestContext) FormatMeetingTime(meetingTime *pollsdata.MeetingTimeTemplateModel) string
- func (requestContext *RequestContext) GetDateFormat() string
- func (requestContext *RequestContext) GetDateTimeFormat() string
- func (requestContext *RequestContext) GetMomentJSDateFormat() string
- func (requestContext *RequestContext) GetMomentJSDateTimeFormat() string
- func (requestContext *RequestContext) GetTimezoneName() string
- func (requestContext *RequestContext) PrepareTemplateRenderData() map[string]interface{}
- func (requestContext *RequestContext) URL(name string, pairs ...string) (*url.URL, error)
- func (requestContext *RequestContext) URLString(name string, pairs ...string) (string, error)
- type TemplateProvider
- type VotersFormField
- type VotersLimitsConfig
- type WeekdayFormField
Constants ¶
View Source
const InternalDateFormat = "2006/01/02"
View Source
const InternalDateTimeFormat = "2006/01/02 15:04"
Variables ¶
View Source
var DefaultFormDecoder = NewFormDecoder()
View Source
var DefaultSchemaDecoder = NewSchemaDecoder()
TODO is it a good idea to re-use encoders? or should a new one always be created? not clear from doc...
View Source
var InternalDateFormatMomentJS = pollsweb.MomentJSDateFormatter.ConvertFormat(InternalDateFormat)
View Source
var InternalDateTimeFormatMomentJS = pollsweb.MomentJSDateFormatter.ConvertFormat(InternalDateTimeFormat)
Functions ¶
func DecodeForm ¶
func EditPeriodDetailsHandleFunc ¶
func EditPeriodDetailsHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) error
func ExecSecure ¶
func ExecSecure(f HandleFunc, ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) (err error)
func GetDefaultFuncMap ¶
func GetMongoURI ¶
func GetVotersFormFieldConverter ¶
func GetVotersFormFieldConverter(parser *gopolls.VotersParser) schema.Converter
func HomeHandleFunc ¶
func HomeHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) error
func NewPeriodHandleFunc ¶
func NewPeriodHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) error
func NewSchemaDecoder ¶
func PeriodDetailsHandleFunc ¶
func PeriodDetailsHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) error
func RunServerMongo ¶
func ShowPeriodSettingsListHandleFunc ¶
func ShowPeriodSettingsListHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) error
Types ¶
type AppConfig ¶
type AppConfig struct { Mongodb *MongoConfig Localization *LocalizationConfig Limits *LimitsConfig }
func NewAppConfig ¶
func NewAppConfig() *AppConfig
type AppContext ¶
type AppContext struct { *AppConfig Logger *zap.SugaredLogger DataHandler pollsdata.DataHandler Templates *TemplateProvider LogRemoteAddr bool HandlerTimeout time.Duration // used to generate URLs // must be set by hand, the NewAppContext... methods don't do this Router *mux.Router // date / datetime formats: converted automatically from the options, maybe we can do better by allowing an // overwrite // they must be set by hand, the NewAppContext... methods don't do this. You can use SetTimeFormats. DefaultMomentJSDateFormat string DefaultMomentJSDateTimeFormat string // used to parse voters in all kinds of contexts VotersParser *gopolls.VotersParser }
func NewAppContext ¶
func NewAppContext(config *AppConfig, logger *zap.SugaredLogger, dataHandler pollsdata.DataHandler, templateRoot string) *AppContext
func NewAppContextMongo ¶
func NewAppContextMongo(ctx context.Context, config *AppConfig, logger *zap.SugaredLogger, templateRoot string) (*AppContext, error)
func (*AppContext) Close ¶
func (appContext *AppContext) Close(ctx context.Context) error
TODO defer call to close, defer call to logger.sync
func (*AppContext) RegisterFormDecoders ¶
func (appContext *AppContext) RegisterFormDecoders()
func (*AppContext) SetTimeFormats ¶
func (appContext *AppContext) SetTimeFormats()
type CustomFormValidator ¶
type CustomFormValidator interface {
ValidateForm() error
}
type DateFormField ¶
func NewDateFormField ¶
func NewDateFormField(year int, month time.Month, day int) DateFormField
func ParseDateFormField ¶
func ParseDateFormField(s string) (DateFormField, error)
func (DateFormField) Equals ¶
func (d DateFormField) Equals(other DateFormField) bool
func (DateFormField) String ¶
func (d DateFormField) String() string
type DateTimeFormField ¶
func NewDateTimeFormField ¶
func NewDateTimeFormField(year int, month time.Month, day, hour, min int) DateTimeFormField
func ParseDateTimeFormField ¶
func ParseDateTimeFormField(s string) (DateTimeFormField, error)
func (DateTimeFormField) Equals ¶
func (dt DateTimeFormField) Equals(other DateTimeFormField) bool
func (DateTimeFormField) String ¶
func (dt DateTimeFormField) String() string
type FormDecoder ¶
func NewFormDecoder ¶
func NewFormDecoder() *FormDecoder
func (*FormDecoder) DecodeForm ¶
func (decoder *FormDecoder) DecodeForm(dst interface{}, src map[string][]string) error
func (*FormDecoder) NormalizeAndDecodeForm ¶
func (decoder *FormDecoder) NormalizeAndDecodeForm(dst interface{}, src map[string][]string) error
func (*FormDecoder) ValidateAndNormalizeFormStrings ¶
type FormValidationError ¶
type FormValidationError struct { pollsweb.PollWebError FieldName string Message string Wrapped error }
func NewFormValidationError ¶
func NewFormValidationError(message string) *FormValidationError
func (*FormValidationError) Error ¶
func (e *FormValidationError) Error() string
func (*FormValidationError) SetFieldName ¶
func (e *FormValidationError) SetFieldName(fieldName string) *FormValidationError
func (*FormValidationError) SetWrapped ¶
func (e *FormValidationError) SetWrapped(wrapped error) *FormValidationError
func (*FormValidationError) Unwrap ¶
func (e *FormValidationError) Unwrap() error
type HandleFunc ¶
type HandleFunc func(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) error
type Handler ¶
type Handler struct { *AppContext HandleFunc HandleFunc }
type HandlerError ¶
type HourMinuteFormField ¶
type HourMinuteFormField struct {
Hour, Minute uint8
}
func ParseHoursAndMinutes ¶
func ParseHoursAndMinutes(s string) (field HourMinuteFormField, err error)
func (HourMinuteFormField) Equals ¶
func (f HourMinuteFormField) Equals(other HourMinuteFormField) bool
func (HourMinuteFormField) String ¶
func (f HourMinuteFormField) String() string
type LimitsConfig ¶
type LimitsConfig struct {
Voters *VotersLimitsConfig
}
func NewLimitsConfig ¶
func NewLimitsConfig() *LimitsConfig
type LocalizationConfig ¶
type LocalizationConfig struct { DefaultTimezoneName string `mapstructure:"time_zone"` DefaultDateFormat string `mapstructure:"date_format"` DefaultTimeFormat string `mapstructure:"time_format"` DefaultLanguage string `mapstructure:"language"` }
func NewLocalizationConfig ¶
func NewLocalizationConfig() *LocalizationConfig
type MongoConfig ¶
type MongoConfig struct { UserName string `mapstructure:"username"` Password string Host string Port int ConnectTimeout time.Duration `mapstructure:"connect_timeout"` Database string }
func NewMongoConfig ¶
func NewMongoConfig() *MongoConfig
type PeriodForm ¶
type PeriodForm struct { Name string `schema:"period_name" valid:"runelength(5|250)"` Start DateTimeFormField `schema:"period_start" valid:"-"` End DateTimeFormField `schema:"period_end" valid:"-"` Weekday WeekdayFormField `schema:"weekday" valid:"-"` MeetingTime HourMinuteFormField `schema:"time" valid:"-"` Voters VotersFormField `schema:"voters" valid:"-"` }
func DecodePeriodForm ¶
func DecodePeriodForm(src map[string][]string) (*PeriodForm, error)
func (PeriodForm) ValidateForm ¶
func (form PeriodForm) ValidateForm() error
type RequestContext ¶
type RequestContext struct {
*AppContext
}
func NewRequestContext ¶
func NewRequestContext(appContext *AppContext) *RequestContext
func (*RequestContext) FormatDate ¶
func (requestContext *RequestContext) FormatDate(t time.Time) string
func (*RequestContext) FormatDateTime ¶
func (requestContext *RequestContext) FormatDateTime(t time.Time) string
func (*RequestContext) FormatMeetingTime ¶
func (requestContext *RequestContext) FormatMeetingTime(meetingTime *pollsdata.MeetingTimeTemplateModel) string
func (*RequestContext) GetDateFormat ¶
func (requestContext *RequestContext) GetDateFormat() string
func (*RequestContext) GetDateTimeFormat ¶
func (requestContext *RequestContext) GetDateTimeFormat() string
func (*RequestContext) GetMomentJSDateFormat ¶
func (requestContext *RequestContext) GetMomentJSDateFormat() string
func (*RequestContext) GetMomentJSDateTimeFormat ¶
func (requestContext *RequestContext) GetMomentJSDateTimeFormat() string
func (*RequestContext) GetTimezoneName ¶
func (requestContext *RequestContext) GetTimezoneName() string
func (*RequestContext) PrepareTemplateRenderData ¶
func (requestContext *RequestContext) PrepareTemplateRenderData() map[string]interface{}
type TemplateProvider ¶
type TemplateProvider struct { RootPath string BaseTemplate *template.Template FuncMap template.FuncMap TemplateMap map[string]*template.Template }
func NewTemplateProvider ¶
func NewTemplateProvider(root string) *TemplateProvider
func (*TemplateProvider) InitBase ¶
func (provider *TemplateProvider) InitBase() error
func (*TemplateProvider) RegisterDefaults ¶
func (provider *TemplateProvider) RegisterDefaults() (int, error)
func (*TemplateProvider) RegisterTemplate ¶
type VotersFormField ¶
func NewVotersFormField ¶
func NewVotersFormField(voters []*gopolls.Voter) VotersFormField
type VotersLimitsConfig ¶
type VotersLimitsConfig struct { MaxNumVoters int `mapstructure:"max_num_voters"` MaxVotersNameLength int `mapstructure:"max_voters_name_length" valid:"range(5|250)"` MaxVotersWeight gopolls.Weight `mapstructure:"max_voters_weight"` }
func NewVotersLimitsConfig ¶
func NewVotersLimitsConfig() *VotersLimitsConfig
type WeekdayFormField ¶
func ParseWeekdayFormField ¶
func ParseWeekdayFormField(s string) (WeekdayFormField, error)
func (WeekdayFormField) String ¶
func (w WeekdayFormField) String() string
Click to show internal directories.
Click to hide internal directories.