This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdevurl.go
More file actions
63 lines (53 loc) · 2.13 KB
/
devurl.go
File metadata and controls
63 lines (53 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package coder
import (
"context"
"fmt"
"net/http"
)
// DevURL is the parsed json response record for a devURL from cemanager.
type DevURL struct {
ID string `json:"id" table:"-"`
URL string `json:"url" table:"URL"`
Port int `json:"port" table:"Port"`
Access string `json:"access" table:"Access"`
Name string `json:"name" table:"Name"`
Scheme string `json:"scheme" table:"Scheme"`
}
type delDevURLRequest struct {
WorkspaceID string `json:"workspace_id"`
DevURLID string `json:"url_id"`
}
// DeleteDevURL deletes the specified devurl.
func (c *DefaultClient) DeleteDevURL(ctx context.Context, workspaceID, urlID string) error {
reqURL := fmt.Sprintf("/api/v0/workspaces/%s/devurls/%s", workspaceID, urlID)
return c.requestBody(ctx, http.MethodDelete, reqURL, delDevURLRequest{
WorkspaceID: workspaceID,
DevURLID: urlID,
}, nil)
}
// CreateDevURLReq defines the request parameters for creating a new DevURL.
type CreateDevURLReq struct {
WorkspaceID string `json:"workspace_id"`
Port int `json:"port"`
Access string `json:"access"`
Name string `json:"name"`
Scheme string `json:"scheme"`
}
// CreateDevURL inserts a new dev URL for the authenticated user.
func (c *DefaultClient) CreateDevURL(ctx context.Context, workspaceID string, req CreateDevURLReq) error {
return c.requestBody(ctx, http.MethodPost, "/api/v0/workspaces/"+workspaceID+"/devurls", req, nil)
}
// DevURLs fetches the Dev URLs for a given workspace.
func (c *DefaultClient) DevURLs(ctx context.Context, workspaceID string) ([]DevURL, error) {
var devurls []DevURL
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/workspaces/"+workspaceID+"/devurls", nil, &devurls); err != nil {
return nil, err
}
return devurls, nil
}
// PutDevURLReq defines the request parameters for overwriting a DevURL.
type PutDevURLReq CreateDevURLReq
// PutDevURL updates an existing devurl for the authenticated user.
func (c *DefaultClient) PutDevURL(ctx context.Context, workspaceID, urlID string, req PutDevURLReq) error {
return c.requestBody(ctx, http.MethodPut, "/api/v0/workspaces/"+workspaceID+"/devurls/"+urlID, req, nil)
}