Skip to content

Commit

Permalink
init target datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyblasczyk committed Oct 30, 2024
1 parent c9d8b10 commit 892a32d
Show file tree
Hide file tree
Showing 23 changed files with 674 additions and 250 deletions.
36 changes: 36 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package client

import (
"encoding/json"
"fmt"
"net/http"
)

//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config openapi.client.yaml openapi.v1.yaml

type Target struct {
ID string
Name string
Type string
}

func (c *Client) GetTarget(id string) (*Target, error) {
url := fmt.Sprintf("%s/v1/targets/%s", c.Server, id)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}

resp, err := c.Client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var target Target
err = json.NewDecoder(resp.Body).Decode(&target)
if err != nil {
return nil, err
}

return &target, nil
}
3 changes: 3 additions & 0 deletions client/openapi.client.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

# yaml-language-server: $schema=https://raw.githubusercontent.com/oapi-codegen/oapi-codegen/HEAD/configuration-schema.json
package: client
output: client.gen.go
Expand Down
Loading

0 comments on commit 892a32d

Please sign in to comment.