commit dd1562c064ef82c610805dfd8cdaca5af54f6d22 from: Oliver Lowe date: Tue Jan 18 13:37:18 2022 UTC Always format generated code While here document what is needed to actually run go generate. commit - f5fde32e94d77a44e85a28f9263531b34fdf7c8b commit + dd1562c064ef82c610805dfd8cdaca5af54f6d22 blob - 08c3bb298903b6e7ed660a9dd370003d345bbc95 blob + aee29003cd9406fed861d0fc0ecdff2202a5763d --- README.md +++ README.md @@ -56,6 +56,12 @@ Source code for the basic lookup, create and delete op Icinga2 object types, such as Host and Service, are generated automatically. +To generate the code, ensure the following tools are available: + +* POSIX shell (/bin/sh) +* awk +* gofmt + The shell script crud.sh writes Go source code by reading a template file and doing some text substitution. It loops through object types, piping the template file crud.skel into the awk script crud.awk for blob - ef0c13cb27a60a4050375907a86d2a293651657c blob + 80a024bcecbca0755bbb780f1fc35472380a6206 --- crud.go +++ crud.go @@ -55,7 +55,6 @@ func (c *Client) DeleteHost(name string, cascade bool) } return nil } - // Services returns a slice of Service matching the filter expression filter. // If no services match, error wraps ErrNoMatch. // To fetch all service, set filter to the empty string (""). @@ -107,7 +106,6 @@ func (c *Client) DeleteService(name string, cascade bo } return nil } - // Users returns a slice of User matching the filter expression filter. // If no users match, error wraps ErrNoMatch. // To fetch all user, set filter to the empty string (""). @@ -159,7 +157,6 @@ func (c *Client) DeleteUser(name string, cascade bool) } return nil } - // HostGroups returns a slice of HostGroup matching the filter expression filter. // If no hostgroups match, error wraps ErrNoMatch. // To fetch all hostgroup, set filter to the empty string (""). blob - 6b8ffbf9297141704fd930b6cd2de2db41d14782 blob + 2bfde846644d3988f576e0136e9afe7d219c9d62 --- crud.sh +++ crud.sh @@ -27,7 +27,6 @@ do esac done - if test -n "$file" then echo "$head" > "$file" @@ -39,8 +38,8 @@ for t in $types do if test -n "$file" then - awk -v "type=$t" -f crud.awk crud.skel >> "$file" + awk -v "type=$t" -f crud.awk crud.skel | gofmt >> "$file" else - awk -v "type=$t" -f crud.awk crud.skel + awk -v "type=$t" -f crud.awk crud.skel | gofmt fi done blob - ae632700bfed2ae9da2abec5f19be31065e895b8 blob + 0aed23206f89c7a23d04fe9bc52bdfa190ae4b18 --- crud.skel +++ crud.skel @@ -44,7 +44,7 @@ func (c *Client) CreateTYPE(LOWER TYPE) error { // depending on the TYPE are also deleted. If no TYPE is found, error wraps // ErrNotExist. func (c *Client) DeleteTYPE(name string, cascade bool) error { - if err := c.deleteObject("/objects/PLURAL/" + name, cascade); err != nil { + if err := c.deleteObject("/objects/PLURAL/"+name, cascade); err != nil { return fmt.Errorf("delete LOWER %s: %w", name, err) } return nil