27 lines
623 B
Go
27 lines
623 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"dim/types"
|
||
|
)
|
||
|
|
||
|
// Creates a new DNS zone.
|
||
|
func zoneCreate(c *Context, req Request, res *Response) error {
|
||
|
zoneName := new(types.ZoneName)
|
||
|
if err := req.Parse(&zoneName); err != nil {
|
||
|
res.AddMessage(LevelError, "expected zone name, but got error: %s", err)
|
||
|
return nil
|
||
|
}
|
||
|
id := 0
|
||
|
err := c.tx.
|
||
|
QueryRow(`insert into zones(name, created_by, modified_by)
|
||
|
values ($1, $2, $2) returning id`, zoneName, c.username).
|
||
|
Scan(&id)
|
||
|
if err != nil {
|
||
|
res.AddMessage(LevelError, "could not create zone")
|
||
|
return fmt.Errorf("could not create zone '%s': %s", zoneName, err)
|
||
|
}
|
||
|
return nil
|
||
|
}
|