mirror of
https://github.com/Bornholm/formidable.git
synced 2024-12-23 07:19:33 +01:00
57 lines
977 B
Go
57 lines
977 B
Go
package server
|
|
|
|
import (
|
|
"forge.cadoles.com/wpetit/formidable/internal/def"
|
|
"github.com/santhosh-tekuri/jsonschema/v5"
|
|
)
|
|
|
|
type Option struct {
|
|
Host string
|
|
Port uint
|
|
Schema *jsonschema.Schema
|
|
Values interface{}
|
|
Defaults interface{}
|
|
OnUpdate OnUpdateFunc
|
|
}
|
|
|
|
type OptionFunc func(*Option)
|
|
|
|
func defaultOption() *Option {
|
|
return &Option{
|
|
Host: "",
|
|
Port: 0,
|
|
Schema: def.Schema,
|
|
}
|
|
}
|
|
|
|
func WithAddress(host string, port uint) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.Host = host
|
|
opt.Port = port
|
|
}
|
|
}
|
|
|
|
func WithSchema(schema *jsonschema.Schema) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.Schema = schema
|
|
}
|
|
}
|
|
|
|
func WithValues(values interface{}) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.Values = values
|
|
}
|
|
}
|
|
|
|
func WithDefaults(defaults interface{}) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.Defaults = defaults
|
|
}
|
|
}
|
|
|
|
func WithOnUpdate(onUpdate OnUpdateFunc) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.OnUpdate = onUpdate
|
|
}
|
|
}
|