server

package
v0.0.0-...-5881286 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

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 DecodeForm(dst interface{}, src map[string][]string) error

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 GetDefaultFuncMap() template.FuncMap

func GetMongoURI

func GetMongoURI(username, password, host string, port int) string

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 NewSchemaDecoder() *schema.Decoder

func PeriodDetailsHandleFunc

func PeriodDetailsHandleFunc(ctx context.Context, requestContext *RequestContext, w http.ResponseWriter, r *http.Request) error

func RunServerMongo

func RunServerMongo(config *AppConfig, templateRoot, host string, port int, debug bool)

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

type DateFormField time.Time

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

type DateTimeFormField time.Time

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 Error

type Error struct {
	Err  error
	Code int
}

func NewError

func NewError(err error, code int) Error

func (Error) Error

func (e Error) Error() string

func (Error) HttpCode

func (e Error) HttpCode() int

func (Error) Unwrap

func (e Error) Unwrap() error

type FormDecoder

type FormDecoder struct {
	UTF8Form      norm.Form
	SchemaDecoder *schema.Decoder
}

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

func (decoder *FormDecoder) ValidateAndNormalizeFormStrings(src map[string][]string) (map[string][]string, error)

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
}

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandlerError

type HandlerError interface {
	error
	HttpCode() int
}

type HourMinuteFormField

type HourMinuteFormField struct {
	Hour, Minute uint8
}

func ParseHoursAndMinutes

func ParseHoursAndMinutes(s string) (field HourMinuteFormField, err error)

func (HourMinuteFormField) Equals

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{}

func (*RequestContext) URL

func (requestContext *RequestContext) URL(name string, pairs ...string) (*url.URL, error)

func (*RequestContext) URLString

func (requestContext *RequestContext) URLString(name string, pairs ...string) (string, error)

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

func (provider *TemplateProvider) RegisterTemplate(name string, paths ...string) (*template.Template, error)

type VotersFormField

type VotersFormField struct {
	Voters []*gopolls.Voter
}

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

type WeekdayFormField time.Weekday

func ParseWeekdayFormField

func ParseWeekdayFormField(s string) (WeekdayFormField, error)

func (WeekdayFormField) String

func (w WeekdayFormField) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL