~mendelmaleh/dummy

b7992e7049cbea825edd717ffdc3e89122e1a0d4 — Mendel E 1 year, 1 month ago 55d7475
Normalize in server package
2 files changed, 33 insertions(+), 8 deletions(-)

M cmd/dummyserver/options.go
M options.go
M cmd/dummyserver/options.go => cmd/dummyserver/options.go +33 -0
@@ 89,3 89,36 @@ func (opt *Options) FromForm(form url.Values) error {

	return nil
}

// Normalize our Options, implement limits and workarounds.
func (opt *Options) Normalize() {
	limit := &dummy.Options{
		Width:  4096,
		Height: 4096,

		Size: 240,
		DPI:  2880,
	}

	opt.Width = min(opt.Width, limit.Width)
	opt.Height = min(opt.Height, limit.Height)

	opt.Size = minFloat64(opt.Size, limit.Size)
	opt.DPI = minFloat64(opt.DPI, limit.DPI)
}

func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}

func minFloat64(a, b float64) float64 {
	if a < b {
		return a
	}

	return b
}

M options.go => options.go +0 -8
@@ 51,11 51,3 @@ func (opt Options) Copy() (copt Options) {

	return copt
}

// Normalize our Options, implement limits and workarounds.
func (opt *Options) Normalize() {
	// limit width to 600 for now
	if opt.Width > 600 {
		opt.Width = 600
	}
}