package render import "gitoa.ru/go-4devs/mime" type Option func(*Reference) func WithParam(name string, val interface{}) Option { return func(r *Reference) { r.Params[name] = val } } func WithEngine(name string) Option { return func(r *Reference) { r.Engine = name } } func WithFormat(ext mime.Ext) Option { return func(r *Reference) { r.Format = ext } } func NewReference(name string, opts ...Option) Reference { ref := Reference{ name: name, } for _, opt := range opts { opt(&ref) } return ref } type Reference struct { name string Engine string Format mime.Ext Params Params } func (r Reference) Name() string { if !r.Format.Is(mime.ExtUnrecognized) { return r.name + "." + r.Format.String() } return r.name } func (r Reference) String() string { if r.Engine != "" { return r.name + "." + r.Format.String() + "." + r.Engine } return r.name + "." + r.Format.String() } func (r Reference) IsEngine(engines ...string) bool { for _, engine := range engines { if engine == r.Engine { return true } } return false } func (r Reference) IsFromat(formats ...mime.Ext) bool { return r.Format.Is(formats...) } type Params map[string]interface{} func (p Params) Get(name string) interface{} { return p[name] }