Skip to content

Commit

Permalink
Schema validation: update HTTP sample 2
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyaksenov committed Aug 28, 2024
1 parent bd71b4f commit d6d0b63
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ local listen_address_schema = schema.new('listen_address', schema.record({
host = schema.scalar({
type = 'string',
validate = validate_host,
default = '127.0.0.1',
}),
port = schema.scalar({
type = 'integer',
validate = validate_port,
default = 8080,
}),
}))

local function validate(cfg)
if cfg.host and cfg.port then
listen_address_schema:validate(cfg)
else
error("You need to set both host and port values")
end
listen_address_schema:validate(cfg)
end

local function apply(cfg)
Expand Down

0 comments on commit d6d0b63

Please sign in to comment.