Add create function template and fix some minor template bugs (#23)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-05-04 22:59:45 -04:00
1 parent 4afb4f6be5
commit e31e91a5ad
12 files changed
+204 -24

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
// Code generated by go generate; DO NOT EDIT.
// Code generated by "make api"; DO NOT EDIT.
package hosts
import (
+63
View File
@@ -0,0 +1,63 @@
// Code generated by "make api"; DO NOT EDIT.
package hosts
import (
"context"
"fmt"
"github.com/hashicorp/watchtower/api"
)
func (s HostCatalog) CreateHost(ctx context.Context, host *Host) (*Host, *api.Error, error) {
if s.Client == nil {
return nil, nil, fmt.Errorf("nil client in CreateHost request")
}
if s.Id == nil || *s.Id == "" {
return nil, nil, fmt.Errorf("missing catalog ID in CreateHost request")
}
req, err := s.Client.NewRequest(ctx, "PUT", fmt.Sprintf("host-catalogs/%s/hosts", *s.Id), host)
if err != nil {
return nil, nil, fmt.Errorf("error creating CreateHost request: %w", err)
}
resp, err := s.Client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during CreateHost call: %w", err)
}
target := new(Host)
apiErr, err := resp.Decode(target)
if err != nil {
return nil, nil, fmt.Errorf("error decoding CreateHost repsonse: %w", err)
}
return target, apiErr, nil
}
func (s HostCatalog) CreateHostSet(ctx context.Context, hostset *HostSet) (*HostSet, *api.Error, error) {
if s.Client == nil {
return nil, nil, fmt.Errorf("nil client in CreateHostSet request")
}
if s.Id == nil || *s.Id == "" {
return nil, nil, fmt.Errorf("missing catalog ID in CreateHostSet request")
}
req, err := s.Client.NewRequest(ctx, "PUT", fmt.Sprintf("host-catalogs/%s/host-sets", *s.Id), hostset)
if err != nil {
return nil, nil, fmt.Errorf("error creating CreateHostSet request: %w", err)
}
resp, err := s.Client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during CreateHostSet call: %w", err)
}
target := new(HostSet)
apiErr, err := resp.Decode(target)
if err != nil {
return nil, nil, fmt.Errorf("error decoding CreateHostSet repsonse: %w", err)
}
return target, apiErr, nil
}
+7 -3
View File
@@ -1,4 +1,4 @@
// Code generated by go generate; DO NOT EDIT.
// Code generated by "make api"; DO NOT EDIT.
package hosts
import (
@@ -6,15 +6,19 @@ import (
"time"
"github.com/fatih/structs"
"github.com/hashicorp/watchtower/api"
"github.com/hashicorp/watchtower/api/internal/strutil"
)
type Host struct {
Client *api.Client `json:"-"`
defaultFields []string
// Canonical path of the resource from the API's base URI
// The ID of the host
// Output only.
Path *string `json:"path,omitempty"`
Id *string `json:"id,omitempty"`
// The type of the resource, to help differentiate schemas
Type *string `json:"type,omitempty"`
// Friendly name, if set
+7 -3
View File
@@ -1,4 +1,4 @@
// Code generated by go generate; DO NOT EDIT.
// Code generated by "make api"; DO NOT EDIT.
package hosts
import (
@@ -6,15 +6,19 @@ import (
"time"
"github.com/fatih/structs"
"github.com/hashicorp/watchtower/api"
"github.com/hashicorp/watchtower/api/internal/strutil"
)
type HostCatalog struct {
Client *api.Client `json:"-"`
defaultFields []string
// Canonical path of the resource from the API's base URI
// The ID of the host
// Output only.
Path *string `json:"path,omitempty"`
Id *string `json:"id,omitempty"`
// The type of the resource, to help differentiate schemas
Type *string `json:"type,omitempty"`
// Friendly name, if set
+7 -3
View File
@@ -1,4 +1,4 @@
// Code generated by go generate; DO NOT EDIT.
// Code generated by "make api"; DO NOT EDIT.
package hosts
import (
@@ -6,15 +6,19 @@ import (
"time"
"github.com/fatih/structs"
"github.com/hashicorp/watchtower/api"
"github.com/hashicorp/watchtower/api/internal/strutil"
)
type HostSet struct {
Client *api.Client `json:"-"`
defaultFields []string
// Canonical path of the resource from the API's base URI
// The ID of the host
// Output only.
Path *string `json:"path,omitempty"`
Id *string `json:"id,omitempty"`
// The type of the resource, to help differentiate schemas
Type *string `json:"type,omitempty"`
// Friendly name, if set
+1 -1
View File
@@ -1,4 +1,4 @@
// Code generated by go generate; DO NOT EDIT.
// Code generated by "make api"; DO NOT EDIT.
package hosts
import (